英文:
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(),
);
},
);
}
}
答案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(),
),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论