Flutter => showDialog / AlertDialog => No MaterialLocalizations found

前端 未结 3 946
情歌与酒
情歌与酒 2021-02-20 11:47

just new to Flutter but very impressed. I want to show a Dialog if a PushNotification arrives via Firebase \"onMessage\".

But every Time I get a Exception \"No MaterialL

3条回答
  •  悲&欢浪女
    2021-02-20 12:39

    check your MaterialApp() widget, if you set localizationsDelegates ,may be you well get this problem. it works when i delete those code.

                  localizationsDelegates: [
                      DefaultCupertinoLocalizations.delegate,
                  ],
    
    

    my codes.

    MaterialApp(
                  navigatorKey: navigatorKey,
                  title: 'test',
                  theme: ThemeData(
                      platform: TargetPlatform.iOS,
                      backgroundColor: Color(0xfff1f1f1),
                      accentColor: AppStyle.colorPrimary,
                      primaryColor: AppStyle.colorPrimary,
                      buttonColor: AppStyle.colorPrimary,
                      iconTheme: IconThemeData(color: Colors.white),
                      textTheme: TextTheme(
                          title: TextStyle(color: Colors.white),
                      ),
                      primaryTextTheme: TextTheme(title: TextStyle(color: Colors.white)),
                      primaryIconTheme: const IconThemeData.fallback().copyWith(
                          color: Colors.white,
                      ),
                      appBarTheme: AppBarTheme().copyWith(brightness: Brightness.dark),
                  ),
                  home: LoginPage(),
                  debugShowCheckedModeBanner: false,
                  onGenerateRoute: AppRouter.router.generator,
              )
    
    

提交回复
热议问题