我有一个全局变量,如果使用Android,则为true。下面的代码不起作用。如何确定要根据平台显示的窗口小部件:
rmoMenu是一个自定义窗口小部件,它返回一个Drawer小部件
rmoBottomNavigationBar是一个自定义窗口小部件,它返回BottomNavigationBar小窗口
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
appBar: rmoAppBar(subText: 'My Shifts'),
if (globals.gblIsAndroid == true) then {
drawer: rmoMenu()
} else {
bottomNavigationBar: rmoBottomNavigationBar(),
},
body: ...
答案 0 :(得分:1)
您可以使用三元运算符:
Scaffold(
appBar: rmoAppBar(subText: 'My Shifts'),
drawer: globals.gblIsAndroid ? rmoMenu() : null,
bottomNavigationBar: !globals.gblIsAndroid ? rmoBottomNavigationBar() : null,