0

I'm tring to change labels color depends on if it selected or not, but flutter sets 1 color for all

NavigationBarTheme(
            data: NavigationBarThemeData(
                backgroundColor: Theme.of(context)
                    .extension<MyExtension>()!
                    .white,
                labelTextStyle: MaterialStateProperty.resolveWith(
                    (state) {
                      return state == MaterialState.selected
                        ? Theme.of(context).textTheme.caption!.copyWith(
                        color: Theme.of(context)
                            .extension<MyExtension>()!
                            .black,
                      )
                        : Theme.of(context).textTheme.caption!.copyWith(
                              color: Theme.of(context)
                                  .extension<MyExtension>()!
                                  .grey3,
                            );
                    }),
                indicatorColor: Theme.of(context)
                    .extension<MyExtension>()!
                    .grey2),

This is how it looks now

I tried to print the state of every item and it always MaterialState.pressed for each

  • for changing the theme of `bottomNavigationBar` you can use `bottonNavigationBarThemeData` instead. ```ThemeData(bottomNavigationBarTheme: BottomNavigationBarThemeData(selectedLabelStyle:TextStyle(color: Colors.blue))),``` – Saad Mar 22 '23 at 06:27
  • @Saad, yes, but with bottomNavigationBarThemeData i can't change indicator color – Morgan Windy Mar 22 '23 at 06:33
  • so you can use both : ```ThemeData(navigationBarTheme: NavigationBarThemeData(indicatorColor: Colors.black),bottomNavigationBarTheme:BottomNavigationBarThemeData(selectedLabelStyle:) ),``` – Saad Mar 22 '23 at 06:44
  • @Saad. But it still wont have any effect cause NavigationBar doesn't take BottomNavigationBarThemeData's styles. Even if i will wrap NavigationBar in it. – Morgan Windy Mar 22 '23 at 06:58

0 Answers0