【发布时间】:2020-04-20 20:33:54
【问题描述】:
我正在尝试在我的 Flutter 应用程序上创建一个带有浮动操作按钮的列表视图小部件,但它不起作用,因为 Android Studio 不断告诉我:
- “未定义命名参数children”
- 我基本上不能把children放在body里:Center widget,但我不知道为什么
我基本上是 Flutter 的初学者,我仍然对基本语法以及哪些小部件可以容纳哪些小部件感到有些困惑,因此非常感谢任何帮助!谢谢!
这是由于第一个错误而无法运行的整体代码(在上面的引号中):
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: Home(),
));
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.green[300],
title: Text(
'Welcome',
style: TextStyle(
fontSize: 25.0,
fontFamily: 'Raleway',
letterSpacing: 1.0,
),
),
centerTitle: true,
),
body: Center(
children: <Widget> [
ListView(
children: <Widget>[
Container(
height: 50,
color: Colors.green[100],
child: Text(
'Body Text',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 45.0,
letterSpacing: 1.0,
color: Colors.green[300],
),
),
),
Container(
height: 50,
color: Colors.green[100],
child: Text(
'Text'
),
),
],
),
FloatingActionButton(
onPressed: () {},
child: Text(
'+',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 35.0,
),
),
backgroundColor: Colors.green[300],
),
]
),
);
}
}
【问题讨论】: