0
点赞
收藏
分享

微信扫一扫

error: The argument type ‘MaterialApp Function()‘ can‘t be assigned to the parameter type ‘Widget Fu

年夜雪 2022-04-18 阅读 138

在这里插入图片描述
控制台报这个错误
error: The argument type ‘MaterialApp Function()’ can’t be assigned to the parameter type 'Widget Fu。。。
一查才知道是因为是flutter Screen的写法改变了
上了pub。com里面去查变成了这个样

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
    return ScreenUtilInit(
      designSize: Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (_) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          // Use this line to prevent extra rebuilds
          useInheritedMediaQuery: true,
          title: 'First Method',
          // You can use the library anywhere in the app even in theme
          theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: TextTheme(bodyText2: TextStyle(fontSize: 30.sp)),
          ),
          home: HomePage(title: 'First Method'),
        );
      },
    );
  }
}

于是将自己的改成这样

    return ScreenUtilInit(
      designSize: Size(375, 812),
      builder:  (_) {
        return MaterialApp(
        navigatorKey: navigatorKey,
        //关闭右上角的debug调试
        debugShowCheckedModeBanner: false,
        routes: routes,
        home: BottomNavigatorBarDemo(),
        // home: TransiPage(),
        // home: ApplyCourse(),
        // initialRoute: "BottomNavigatorBarDemo",
        // initialRoute: "ApplyCourse",
        theme: getTheme(false),
        darkTheme: getTheme(true),
        localizationsDelegates: const [
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        navigatorObservers: [RouteObserverProvider.of(context)],
        supportedLocales: [Locale.fromSubtags(languageCode: 'zh')],
        // builder: (context, widget) {
        //   return MediaQuery(
        //       data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
        //       child: widget);
        // },
        builder: EasyLoading.init(),
        // home: BottomNavigatorBarDemo(),
      );},
    );
举报

相关推荐

0 条评论