Flutter 中过多的位置参数意味着什么?
What does too many positional argument mean in Flutter?
Dart Analysis Toolbar
当我在 Android Studio 中编写此代码时,这就是我的 dart 分析工具栏中出现的内容:
The code I wrote
我该如何防止这种情况?
您缺少 )
括号,请在分号前添加它。
This link 解释了位置参数和命名参数。而且您正在尝试的过程不是一个好习惯。您需要分解小部件,以便更容易维护。
尝试如下:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: const Text('I am rich'),
backgroundColor: Colors.blueGrey[900],
),
body: Center(
child: Image.asset('images/diamond.png'),
),
),
);
}
}
分号前加括号
将您的 MaterialApp
替换为:
MaterialApp(
title: 'SaHomeDecor',
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: Text('I am rich'),
backgroundColor: Colors.blueGrey[900],
),
body: Center(
child: Image.asset('images/diamond.png'),
),
),
);
如果您使用 AppBar
,则必须像 Scaffold(appBar:AppBar())
一样提供 Scaffold.appBar
属性。
对于图像,您必须使用 Scaffold.body
属性。
Dart Analysis Toolbar
当我在 Android Studio 中编写此代码时,这就是我的 dart 分析工具栏中出现的内容: The code I wrote 我该如何防止这种情况?
您缺少 )
括号,请在分号前添加它。
This link 解释了位置参数和命名参数。而且您正在尝试的过程不是一个好习惯。您需要分解小部件,以便更容易维护。
尝试如下:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: const Text('I am rich'),
backgroundColor: Colors.blueGrey[900],
),
body: Center(
child: Image.asset('images/diamond.png'),
),
),
);
}
}
分号前加括号
将您的 MaterialApp
替换为:
MaterialApp(
title: 'SaHomeDecor',
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
title: Text('I am rich'),
backgroundColor: Colors.blueGrey[900],
),
body: Center(
child: Image.asset('images/diamond.png'),
),
),
);
如果您使用 AppBar
,则必须像 Scaffold(appBar:AppBar())
一样提供 Scaffold.appBar
属性。
对于图像,您必须使用 Scaffold.body
属性。