我正在使用底部导航栏。在某个事件触发时,我需要在当前屏幕上显示一些警报。
这是我实现底部导航栏的方式。我有四个选项卡。
在这里,当_isHomeDetected
为真并且用户点击图标(即索引3)时,我需要更改第4个选项卡的图标,无论用户在哪个选项卡中,都要显示警报消息。 我该怎么做?
class LandingScreen extends StatefulWidget {
static Widget bottomNavigationBar;
..
}
class _LandingScreenState extends State<LandingScreen> {
...
StreamSubscription<String> _subscription;
bool _isHomeDetected = false;
@override
void initState() {
...
_subscription = server.messages.listen(onData, onError: onError);
}
onData(message) {
setState(() {
_isHomeDetected = json.decode(message)["isHomeBeacon"];
});
}
...
@override
Widget build(BuildContext context) {
LandingScreen.bottomNavigationBar = new BottomNavigationBar(
....
);
return new Scaffold(
body: _currentPage,
bottomNavigationBar: LandingScreen.bottomNavigationBar,
);
}
_navigateToScreens(int currentIndex) {
List screens = [
..
];
setState((){
if (!_isHomeDetected || currentIndex != 3){
_currentPage = screens[currentIndex];
} else {
Utils.showCupertinoAlert(
context: context, content: "You wanna log out???");
}
});
}
}