I have CupertinoTabScaffold
with 4 tabs, and I have a variable that is responsible for authorization, I need to update the tabs when this variable changes
My CupertinoTabScaffold
:
CupertinoTabScaffold(
controller: _controller,
key: myKey,
backgroundColor: Colors.black87,
tabBar: CupertinoTabBar(
inactiveColor: const Color.fromRGBO(43, 46, 74, 1),
activeColor: const Color.fromRGBO(232, 69, 69, 1),
iconSize: 27,
currentIndex: currentIndex,
onTap: onItemTapped,
items: const [
BottomNavigationBarItem(icon: Icon(CupertinoIcons.house), activeIcon: Icon(CupertinoIcons.house_fill)),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.square_list), activeIcon: Icon(CupertinoIcons.square_list_fill)),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.cart), activeIcon: Icon(CupertinoIcons.cart_fill)),
BottomNavigationBarItem(icon: Icon(CupertinoIcons.person), activeIcon: Icon(CupertinoIcons.person_fill)),
],
),
tabBuilder: (BuildContext context, int index) {
switch (index) {
case 0:
return CupertinoTabView(
navigatorKey: tabNavKeys[index],
builder: (BuildContext context) => const HomePage(),
);
case 1:
return CupertinoTabView(
navigatorKey: tabNavKeys[1],
builder: (BuildContext context) {
return const CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
child: CatalogPage(),
);
},
);
case 2:
return currentIndex == 2 ? CupertinoTabView(
navigatorKey: tabNavKeys[2],
builder: (BuildContext context) {
return const CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
child: ShoppingBag(),
);
},
) : Container();
case 3:
return CupertinoTabView(
navigatorKey: tabNavKeys[3],
builder: (BuildContext context) {
return const CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
child: UserProfileScaffold(),
);
},
);
default:
return Container();
}
}),
CodePudding user response:
You can do this using stream and state management. The StreamBuilder
widget rebuilds is children when a new message appears in the stream.