Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

update cart count in bottom navigation bar flutter

I need to create a bottom navigation bar with cart value updated

here is my app main

@override
  Widget build(BuildContext context) {   
        return Scaffold(
          appBar: CommonAppBar(
              title:'title',
          iconUrl: '',
          automaticallyImplyLeading: true),
      body: ......
      ),
      bottomNavigationBar:
          CommonBottomNavigationBar(context: context, index: 2),
     
    );
  }

here is my bottom navigationbar.dart

Widget CommonBottomNavigationBar({BuildContext context, int index}) {
  int _currentIndex = index;
 
  List<BottomNavigationBarItem> items = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: 'Home',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.search),
      label: 'Search',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.shopping_cart),
      label: 'Cart',
    ), // BottomNavigationBarItem(

    BottomNavigationBarItem(
      icon: Icon(Icons.account_circle),
      label: 'Account',
    )
  ];

  return Theme(
      
      data: Theme.of(context).copyWith(
        canvasColor: PRIMARY_COLOR,
        primaryColor: ACTIVE_COLOR,
        textTheme: Theme.of(context)
            .textTheme
            .copyWith(caption: new TextStyle(color: Colors.white)),
      ),
      child: new BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (value) {
          
          }
        },
        items: items,
       
      ));
}

here is my function to get cart count

Future<dynamic> getCartcount() async {
  ApiProvider _apiProvider = ApiProvider();
  var data = await _apiProvider.getCartcount();

  return data;
}

i have multiple pages and each page having same bottom navigation so how to pass the cart value to bottom navigation bar in each page i have added a code as but it was not loading on load so what should i have to do to pass the cart value ..

getCartcount().then((value) => {});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...