Как обновить цвет sh иконок на CurvedNavigationBar - PullRequest
2 голосов
/ 28 мая 2020

Я пытаюсь использовать пакет curvedNavigationBar. Вот мой код:

 Widget build(BuildContext context) {
     int currentTab = 2;
    return Scaffold(
      key: _scaffoldKey,
      bottomNavigationBar: CurvedNavigationBar(
        key: _bottomNavigationKey,
        index: currentTab,
        height: 50.0,
        items: <Widget>[
          Icon(Icons.home, color:currentTab==0?Colors.yellow:Colors.black, size: 30),
          Icon(Icons.wifi_tethering, color:currentTab==1?Colors.yellow:Colors.black, size: 30),
          Icon(Icons.flag, color:currentTab==2?Colors.yellow:Colors.black, size: 65),
          Icon(Icons.mail, color:currentTab==3?Colors.yellow:Colors.black, size: 30),
          Icon(Icons.account_circle, color: currentTab==4?Colors.yellow:Colors.black, size: 30),
        ],
        color: Colors.yellow,
        buttonBackgroundColor: Colors.black,
        backgroundColor: Colors.black,
        animationCurve: Curves.bounceInOut,
        animationDuration: Duration(milliseconds: 200),
        onTap: (index) {
          setState(() {
            currentTab = index;
          });
        },
      ),
      body: Container(
        color: Colors.black,
        child: Center(
          child: Column(
            children: <Widget>[
              Text(_page.toString(), textScaleFactor: 10.0),
              RaisedButton(
                child: Text('Go To Page of index 1'),
                onPressed: () {
                  final CurvedNavigationBarState navBarState =
                      _bottomNavigationKey.currentState;
                  navBarState.setPage(1);
                },
              ),
            ],
          ),
        ),
      ),
      appBar: AppBar(
        backgroundColor: Colors.yellow,
        leading: Padding(
          child: GestureDetector(
            onTap: () {
              _scaffoldKey.currentState.openDrawer();
            },
            child: CircleAvatar(
              backgroundImage: ExactAssetImage('images/profile.jpg'),
              radius: 30,
            ),
          ),
          padding: const EdgeInsets.all(8.0),
        ),
        title: Text("Title"),
      ),
      drawer: DrawerCustom("Vogan", "@jbbo"),
      drawerEdgeDragWidth: 0,
    );

в методе setState, я даю currentTab значение индекса. Но иконки не обновляются sh, цвет остается прежним. Я наблюдал за fixedColor, но пакет не обрабатывает такие свойства. То же самое для activeIcons внутри navigationbarItem, потому что свойство items для curvednavigationBar представляет собой список виджетов. Поэтому я не могу использовать элемент навигации.

Как решить эту проблему?

edit

Думал, что это может быть потому, что я не инициализировал состояние, поэтому я добавил это:

 @override
  void initState(){
    super.initState();
  }

Он все еще не работает , Я не понимаю. onPressed работает хорошо, когда я нажимаю на значок, I go внутри метода, значение currentTab обновляется, но цвета значка остаются неизменными.

1 Ответ

0 голосов
/ 28 мая 2020

Основал! Это произошло потому, что моя переменная currentTab не была глобальной переменной класса, я объявляю ее внутри метода сборки, это была ошибка

...