Tuesday, 25 June 2024

tabs in body flutter

import 'package:flutter/material.dart';
import 'package:multistoreapp/widgets/fake_search.dart';

class CategoryScreen extends StatefulWidget {
  const CategoryScreen({super.key});

  @override
  State<CategoryScreen> createState() => _CategoryScreenState();
}

class _CategoryScreenState extends State<CategoryScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        backgroundColor: Colors.white,
        title: const FakeSearch(),
      ),
      body: Stack(
        children: [
          Positioned(

            bottom: 0,
            left: 0,
            child: Container(height: 800, width: 100, color: Colors.red),
          ),
          Positioned(
            bottom: 0,
            right: 0,
            child: Container(height: 800, width: 300, color: Colors.blue),
          )
        ],
      ),
    );
  }
}



flutter tabbar

 import 'package:flutter/material.dart';

import 'package:flutter/cupertino.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 9,
      child: Scaffold(
          appBar: AppBar(
            elevation: 0,
            backgroundColor: Colors.white,
            title: const CupertinoSearchTextField(),

            bottom: const TabBar(
              isScrollable: true,
              indicatorColor: Colors.yellow,
              indicatorWeight: 7,
              tabs: [
                RepeatedTab(label:'Men'),
                RepeatedTab(label:'WoMen'),
                RepeatedTab(label:'shoe'),
                RepeatedTab(label:'Bags'),
                RepeatedTab(label:'Electronics'),
                RepeatedTab(label:'Accessories'),
                RepeatedTab(label:'Kids'),
                RepeatedTab(label:'Beauty'),

              ],
            ),
          ),
          body: const TabBarView(
            children: [
              Center(
                child: Text('men screen'),
              ),
              Center(
                child: Text('women screen'),
              ),
              Center(
                child: Text('shoes screen'),
              ),
              Center(
                child: Text('Elec screen'),
              ),
              Center(
                child: Text('Bags screen'),
              ),
              Center(
                child: Text('Access screen'),
              ),
              Center(
                child: Text('kids screen'),
              ),
              Center(
                child: Text('Beauty screen'),
              )
            ],
          )),
    );
  }
}

class RepeatedTab extends StatelessWidget {
  final String label;

  const RepeatedTab({
    super.key, required this.label,
  });

  @override
  Widget build(BuildContext context) {
    return Tab(
      child: Text(
        label,
        style: TextStyle(color: Colors.grey.shade600),
      ),
    );
  }
}

flutter

 flutter run

https://blog.logrocket.com/flutter-tabbar-a-complete-tutorial-with-examples/


Monday, 24 June 2024

flutter bottom navigation

import 'package:flutter/material.dart';

class CustomerHomeScreen extends StatefulWidget {
  const CustomerHomeScreen({super.key});

  @override
  State<CustomerHomeScreen> createState() => _CustomerHomeScreenState();
}

class _CustomerHomeScreenState extends State<CustomerHomeScreen> {
  int _selectIndex=0;
  final List<Widget> _tabs=const[
    Center(child: Text('home screen')),
    Center(child: Text('category screen')),
    Center(child: Text('stores screen')),
    Center(child: Text('cart screen')),
    Center(child: Text('profile screen')),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:_tabs[_selectIndex] ,
      bottomNavigationBar: BottomNavigationBar(
        elevation: 0,
        selectedLabelStyle: const TextStyle(fontWeight: FontWeight.w600),
        selectedItemColor: Colors.black,
        // unselectedItemColor:Colors.red,
        type: BottomNavigationBarType.fixed,//check different values
        // currentIndex: 1,
        currentIndex: _selectIndex,
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
          BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Category'),
          BottomNavigationBarItem(icon: Icon(Icons.shop), label: 'Stores'),
          BottomNavigationBarItem(
              icon: Icon(Icons.shopping_cart), label: 'Cart'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
        ],
        onTap: (index){
          setState(() {
             _selectIndex=index;
          });
        },
      ),
    );
  }
}

flutter old project upgrade

 o update the project to null safety follow these steps:

Side note: change the flutter version in pubsec.yaml, make new project and copy the following line:

sdk: ">=2.19.6 <3.0.0"

Then follow the steps:

  1. Run flutter upgrade in the terminal to upgrade Flutter
  2. Run dart migrate to run the dart migration tool.
  3. Solve all errors which the migration tool shows.
  4. Run flutter pub outdated --mode=null-safety to print all outdated packages.
  5. Run flutter pub upgrade --null-safety to upgrade all packages automatically.
  6. Check the code for errors and solve them (Very important).
  7. Run dart migrate again and it should now be successful. Follow the link to checkout the proposed changes.
  8. Press the "Apply Migration" button.
  9. Check the code for errors again and fix them.
  10. your project should be updated now. Referenced from this website.

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...