【发布时间】:2021-06-06 23:22:59
【问题描述】:
我有使用 CupertinoTabScaffold 显示底部导航的代码,我想在其中一个菜单上显示底部对话框,但出现错误
在构建 Builder 时抛出了以下断言(脏,依赖项:[_InheritedTheme,_LocalizationsScope-[GlobalKey #a6d51]]): 构建期间调用的 setState() 或 markNeedsBuild()。
这是我的代码
class AppTab extends StatefulWidget {
final dataUser;
AppTab(this.dataUser);
@override
_AppTabState createState() => _AppTabState(dataUser);
}
class _AppTabState extends State<AppTab> {
final user;
_AppTabState(this.user);
@override
Widget build(BuildContext context) {
return BlocListener<AuthenticationBloc, AuthenticationState>(
listener: (context, state) {
if (state == AuthenticationState.unauthenticated()) {
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false, arguments: state.loginPageState);
}
},
child: CupertinoTabScaffold(
controller: tabController,
tabBar: CupertinoTabBar(
activeColor: HexColor("#26ADE4"),
inactiveColor: HexColor("#707070"),
items: [
BottomNavigationBarItem(
label: "Menu 1",
icon: Image.asset("assets/icon_tab_home.png", height: 25, width: 22),
activeIcon: Image.asset("assets/icon_tab_home_active.png", height: 25, width: 22),
),
BottomNavigationBarItem(
label: "Menu 2",
icon: Image.asset("assets/icon_tab_buat_bill.png", height: 25, width: 22),
activeIcon: Image.asset("assets/icon_tab_buat_bill_active.png", height: 25, width: 22),
),
BottomNavigationBarItem(
label: "Menu 3",
icon: Image.asset("assets/icon_tab_account.png", height: 25, width: 22),
activeIcon: Image.asset("assets/icon_tab_account_active.png", height: 25, width: 22),
),
],
),
tabBuilder: (context, index) {
if (index == 0) {
return HomePage(user);
} else if (index == 1) {
return _bottomSheetMore(context);
}
return AccountPage(user);
}),
);
}
_bottomSheetMore(context) {
showModalBottomSheet(
context: context,
builder: (builder) {
return new Container(
padding: EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 5.0,
bottom: 5.0,
),
decoration: new BoxDecoration(
color: Colors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child: new Wrap(
children: <Widget>[
new ListTile(
title: const Text(
'Menu Akun',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w700,
),
),
subtitle: Text("Pilih salah satu"),
),
new Divider(
height: 10.0,
),
new ListTile(
title: const Text(
'Menu Home',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w700,
),
),
),
new Divider(
height: 10.0,
),
new ListTile(
title: const Text(
'Logout',
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w700,
),
),
onTap: () async {
// Add Here
},
),
],
),
);
},
);
}
}
【问题讨论】: