我在底部应用程序栏的主页中有 BottomAppBar,单击该按钮时我有浮动操作按钮,我想在底部应用程序栏的默认页面中显示一些更改。 问题是 - 当我单击该更改时,刷新页面时不会反映更改,然后会显示更改。 我想要 - 更改会立即反映出来
这是我的底部应用栏屏幕
late Widget currentScreen;
int currentTab = 0;
void initState() {
super.initState();
currentScreen = const NewHomeScreen();
}
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
BottomAppBar(
color: Colors.transparent,
elevation: 0,
shape: const CircularNotchedRectangle(),
notchMargin: 10,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = const NewHomeScreen();
currentTab = 0;
});
},
child: Icon(
Icons.home_filled,
color: currentTab == 0
? const Color(0xffF8D62B)
: const Color(0xff7C878C),
),
),
const SizedBox(
width: 20,
),
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = const CalenderUi();
currentTab = 1;
});
},
child: Icon(
Icons.calendar_month_rounded,
color: currentTab == 1
? const Color(0xffF8D62B)
: const Color(0xff7C878C),
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
MaterialButton(
minWidth: 40,
onPressed: () {
setState(() {
currentScreen = const ProfileUiScreen();
currentTab = 3;
});
},
child: Icon(
Icons.person_outline_rounded,
color: currentTab == 3
? const Color(0xffF8D62B)
: const Color(0xff7C878C),
),
),
const SizedBox(
width: 20,
),
MaterialButton(
minWidth: 40,
onPressed: () {
_drawerKey.currentState?.toggle();
draweropen = !draweropen;
},
child:Icon(
draweropen ?
Icons.clear
: Icons.menu,
color: currentTab == 4
? const Color(0xffF8D62B)
: const Color(0xff7C878C),
),
),
],
),
],
),
),
我尝试了很多事情,例如:
Shared Preference
和
eventBus
可能由于默认屏幕更改未反映出来 帮我解决这个问题,提前谢谢
您可以使用底部导航栏替换底部应用程序栏,同时您必须创建一个自定义屏幕,其中只有底部导航栏在那里,您必须在索引上放置一个类。
如果您想要实时数据,请使用 SqfLite。