我对 flutter 完全陌生,事实上这是我第一次使用它,我真的不明白为什么 dart 在使用 flutter_screenutil 包中的
ScreenUtilInit
时对我大喊大叫,并且 invalid constant value
错误来自 builder: (context, child)
。我在网上到处搜索并阅读了 pub 文档,但仍然找不到调整如何安抚这些令人窒息的错误。
这是代码片段
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const ScreenUtilInit(
useInheritedMediaQuery: true,
designSize: Size(375, 812),
minTextAdapt: true,
splitScreenMode: true,
// The Invalid constant value is coming from the next line
builder: (context, child){
return const GetMaterialApp(
debugShowCheckedModeBanner: false,
title: "JobMon",
theme: ThemeData(
scaffoldBackgroundColor: kLight,
iconTheme: IconThemeData(color: kDark),
primaryColor: Colors.grey,
),
home: defaultHome,
);
},
);
}
}
我真的很感激这里的一些帮助,因为我真的不知道这里做错了什么。
从
const
小部件中删除 GetMaterialApp
关键字。
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const ScreenUtilInit(
useInheritedMediaQuery: true,
designSize: Size(375, 812),
minTextAdapt: true,
splitScreenMode: true,
//Remove the const keyword
builder: (context, child){
return const GetMaterialApp(
debugShowCheckedModeBanner: false,
title: "JobMon",
theme: ThemeData(
scaffoldBackgroundColor: kLight,
iconTheme: IconThemeData(color: kDark),
primaryColor: Colors.grey,
),
home: defaultHome,
);
},
);
}
}