未找到 MaterialLocalizations
No MaterialLocalizations found
我试图在点击 BottomNavigationBarItem 按钮时显示警告对话框,
在 CupertinoTabBar 内,但它说找不到 MaterialLocalizations。
调试控制台
这个小部件的祖先是:
CupertinoApp
state: _CupertinoAppState#730fe
MyApp
state: MyAppState#064cb
代码
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
label: "",
icon: Padding(
padding: const EdgeInsets.only(left: 10, top: 10),
child: Align(
alignment: Alignment.bottomLeft,
child: Icon(Icons.create_new_folder),
),
),
),
BottomNavigationBarItem(
label: "",
icon: Padding(
padding: const EdgeInsets.only(right: 10, top: 10),
child: Align(
alignment: Alignment.bottomRight,
child: Icon(Icons.folder_open),
),
),
)
],
currentIndex: state,
onTap: (int index) {
setState(() {
state = index;
});
if (index == 0) {
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
actions: [
Text("Bye"),
],
title: Text("New Folder"),
content: Text("Folder name"),
),
);
}
},
),
您可以尝试在主页上用 MaterialApp
包装您的整个项目。
您是否将委托直接传递给了 CupertinoApp 的 localizationsDelegates?请试试这个:
CupertinoApp(
....
....
localizationsDelegates: [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
....
....
),
我试图在点击 BottomNavigationBarItem 按钮时显示警告对话框, 在 CupertinoTabBar 内,但它说找不到 MaterialLocalizations。
调试控制台
这个小部件的祖先是:
CupertinoApp
state: _CupertinoAppState#730fe
MyApp
state: MyAppState#064cb
代码
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
items: [
BottomNavigationBarItem(
label: "",
icon: Padding(
padding: const EdgeInsets.only(left: 10, top: 10),
child: Align(
alignment: Alignment.bottomLeft,
child: Icon(Icons.create_new_folder),
),
),
),
BottomNavigationBarItem(
label: "",
icon: Padding(
padding: const EdgeInsets.only(right: 10, top: 10),
child: Align(
alignment: Alignment.bottomRight,
child: Icon(Icons.folder_open),
),
),
)
],
currentIndex: state,
onTap: (int index) {
setState(() {
state = index;
});
if (index == 0) {
showDialog(
context: context,
builder: (BuildContext context) => CupertinoAlertDialog(
actions: [
Text("Bye"),
],
title: Text("New Folder"),
content: Text("Folder name"),
),
);
}
},
),
您可以尝试在主页上用 MaterialApp
包装您的整个项目。
您是否将委托直接传递给了 CupertinoApp 的 localizationsDelegates?请试试这个:
CupertinoApp(
....
....
localizationsDelegates: [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
....
....
),