No MaterialLocalizations found

598 views Asked by At

I am trying to show alert dialog on click of BottomNavigationBarItem button, inside CupertinoTabBar but it says No MaterialLocalizations found.

Debug Console

The ancestors of this widget were:

CupertinoApp
    state: _CupertinoAppState#730fe
MyApp
    state: MyAppState#064cb

Code

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"),
          ),
        );
      }
    },
  ),
2

There are 2 answers

0
bluenile On BEST ANSWER

Did you pass your delegates directly to localizationsDelegates of CupertinoApp? Please try this :

CupertinoApp(
....
....
  localizationsDelegates: [
    DefaultMaterialLocalizations.delegate,
    DefaultCupertinoLocalizations.delegate,
    DefaultWidgetsLocalizations.delegate,
  ],
....
....
),
0
Akif On

You can try to wrap your whole project with MaterialApp on your home page.