How can I solve this issue, The argument type 'MaterialApp Function()' can't be assigned error

huangapple go评论62阅读模式
英文:

How can I solve this issue, The argument type 'MaterialApp Function()' can't be assigned error

问题

以下是代码的翻译部分:

我正在使用ScreenUtilInit,出现了这个错误,

参数类型“MaterialApp Function()”无法分配给参数类型“Widget Function(BuildContext, Widget?)”,

这是Flutter代码段,我该如何解决这个问题

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // 这个小部件是您应用程序的根部件。
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      builder: () {
        return MaterialApp(
          title: 'Flutter电子商务',
          theme: ThemeData(  
            primarySwatch: Colors.blue,
          ),
          home: SplashScreen(),
        );
      },
    );
  }
}

希望这可以帮助您解决问题。如果您需要进一步的帮助,请随时提问。

英文:

I am using ScreenUtilInit and this error is occurred,

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

This is the flutter code segment, and how can I solve this issue

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      builder: (){
        return MaterialApp(
          title: 'Flutter E-Commerce',
          theme: ThemeData(  
          primarySwatch: Colors.blue,
          ),
          home: SplashScreen(),
        );
      },
    );
  }
}

How can I solve this issue, The argument type 'MaterialApp Function()' can't be assigned error

答案1

得分: 0

The builder of ScreenUtilInit requires Build context and an optional Widget parameter. 

class MyApp extends StatelessWidget {
    static const double _designWidth = 375;
    static const double _designHeight = 812;
    const MyApp({Key? key}) : super(key: key);
    @override
    Widget build(BuildContext context) {
        return ScreenUtilInit(
            designSize: const Size(_designWidth, _designHeight),
            builder: (context, widget) => MaterialApp(
                theme: ThemeData(useMaterial3: true),
                title:"Flutter E-Commerce",
                home: const SplashScreen(),
            ),
        );
    }
}
英文:

The builder of ScreenUtilInit requires Build context and an optional Widget parameter.

   class MyApp extends StatelessWidget {
    
      static const double _designWidth = 375;
      static const double _designHeight = 812;
      const MyApp(Key? key}) : super(key: key);
      @override
      Widget build(BuildContext context) {
        return ScreenUtilInit(
          designSize: const Size(_designWidth, _designHeight),
          builder: (context, widget) => MaterialApp(
            theme: ThemeData(useMaterial3: true),
            title:"Flutter E-Commerce",
            home: const SplashScreen(),
          ),
        );
      }
    }

huangapple
  • 本文由 发表于 2023年3月4日 03:58:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定