Experience

The Getter modalBarrierDismissLabel was called on null

1.9kviews

Is this annoying error bugging your development in Flutter, with particular datetime or date picker, alert plugins? Are you using CupertinoApp instead of MaterialApp in your project? Luckily the solution is simple.

The error basically means that it is assuming you are under the parent Widget of type MaterialApp at root level, however this isn’t the case especially in my particular project where I had a conditional clause to separate out iOS or Android apps due to some slight design differentiations and handling of certain specific functionality.

The key to resolving this issue is to add the following code into the CupertinoApp( widget as an attribute. Example below.

class YourApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    if (isIos) {
      return CupertinoApp(

        // Resolve problems of widgets not in MaterialApp for them to actually work...
        localizationsDelegates: [ DefaultMaterialLocalizations.delegate, DefaultCupertinoLocalizations.delegate, DefaultWidgetsLocalizations.delegate, ],

        theme: CupertinoThemeData(
        home: MainHomePage(
          // etc...
        ),
      );
    } else {
      return MaterialApp(
        home: MainHomePage(
          // etc...
        ),
      );
    }
  }
}

As usual, happy fluttering! Hope the above saves you hours of headache!

Leave a Response