flutter - 当我使用 flutter_screenutil 或 sizer 包时,我无法声明“家”。我收到错误参数“home”未定义
问题描述
这是我的主要飞镖文件的代码:
void main() {
runApp(new MaterialApp());
}
class MaterialApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints){
return OrientationBuilder(
builder: (context, orientation){
SizerUtil().init(constraints, orientation);
return new MaterialApp(
home: OpeningScreen()
);
},
);
},
);
}
}
这是我得到的错误:
The named parameter 'home' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'home'.
我有一个呈现应用程序登录页面 UI 的 OpeningScreen() 类。当我也在 flutter_screenutil 中使用“home”时,同样的错误出现了。
解决方案
ScreenUtil() 没有任何问题。问题就在这里
class MaterialApp extends StatelessWidget
您不能使用MaterialApp作为类名,因为它是在颤振库中预定义的。尝试使用其他名称,例如 class MyApp extends StatelessWidget
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: Size(360, 690),
allowFontScaling: false,
builder: () => MaterialApp(
home: Testing(),
),
);
}
}
推荐阅读
- firebase - Firestore 对集合组数据的分页查询
- php - 如何关闭angularjs中的弹出框
- reactjs - gatsby中的graphql elemMatch查询不返回数据
- wildfly - JBoss WildFly 15.0.1 Final 未在具有 2 GB 的 ubuntu 14.04 vServer 上启动:JRE 内存不足
- laravel - 开发 laravel 和 vue 项目的最佳解决方案是什么?
- javascript - 如何在点击时更改服务器字段的值
- python - 类型错误:assertListEqual() 缺少 1 个必需的位置参数:'list2'
- javascript - 翻译字符串提取
- bash - 如何在 Ansible playbook 中为每个客户端设置不同的环境变量
- javascript - 将 OnClick 事件从组件传递到其他组件