Home > database >  The argument type 'MaterialApp Function()' can't be assigned to the parameter type &#
The argument type 'MaterialApp Function()' can't be assigned to the parameter type &#

Time:12-13

recently i am trying to run from github but in pub get i am getting this kind of error like this

The argument type 'MaterialApp Function()' can't be assigned to the parameter type 'Widget Function(BuildContext, Widget?)'

the main code that effected are this

 return ScreenUtilInit(
        designSize: Size(428.0, 926.0),
        builder: () => MaterialApp(
          title: 'MMAS',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            textTheme: TextTheme(
              headline3: TextStyle(
                fontFamily: 'OpenSans',
                fontSize: 45.0,
                color: Colors.deepOrangeAccent,
              ),
              button: TextStyle(
                fontFamily: 'OpenSans',
              ),
              subtitle1: TextStyle(fontFamily: 'NotoSans'),
              bodyText2: TextStyle(fontFamily: 'NotoSans'),
            ),
            colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.indigo)
                .copyWith(secondary: Colors.orange),
            textSelectionTheme:
                TextSelectionThemeData(cursorColor: Colors.amberAccent),
          ),
          builder: (context, widget) => MediaQuery(
            data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
            child: widget!,
          ),
          home: SignIn(),
          // Home(),
          locale: _locale,
          localizationsDelegates: [
            AppLocalization.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          localeResolutionCallback: (locale, supportedLocales) {
            for (var supportedLocale in supportedLocales) {
              if (supportedLocale.languageCode == locale!.languageCode &&
                  supportedLocale.countryCode == locale.countryCode) {
                return supportedLocale;
              }
            }
            return supportedLocales.first;
          },
          supportedLocales: [
            Locale("en", "US"),
            Locale("de", "DE"),
            Locale("es", "ES"),
            Locale("fr", "FR"),
            Locale("hi", "IN"),
            Locale("ja", "JP"),
            Locale("ko", "KR"),
            Locale("pt", "PT"),
            Locale("ru", "RU"),
            Locale("tr", "TR"),
            Locale("vi", "VN"),
            Locale("zh", "CN"),
          ],
        ),
      );

How to resolve this?

CodePudding user response:

Hi it is a common issue while using ScreenUtilInit widget, you need to add BuildContext in the builder method of the ScreenUtilInit to make it work such as:

return ScreenUtilInit(
    designSize: Size(428.0, 926.0),
    builder: (BuildContext context,child) => MaterialApp(

It should fix your issue

CodePudding user response:

Please use this library. It might help you. [1]: https://pub.dev/packages/sizer

  • Related