【发布时间】:2019-01-11 01:15:57
【问题描述】:
我正在尝试使用 Flutter(使用 Dart 2)构建一个应用程序。我遇到了一个我无法弄清楚的错误:
错误在child: new Center(
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Begin with a search...'),
actions: <Widget> [
new FlatButton(
child: new Text('Logout', style: new TextStyle(fontSize: 17.0, color: Colors.white)),
onPressed: _signOut,
)
]
),
body: new Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
child: new Center(
child: new Row(
children: <Widget>[
new TextField(
controller: _controller,
autofocus: true,
textAlign: TextAlign.start,
decoration: new InputDecoration(
prefixIcon: new Padding(
padding: const EdgeInsetsDirectional.only(end: 10.0),
child: new Icon(Icons.search),
),
border: new OutlineInputBorder(borderRadius: new BorderRadius.all(Radius.circular(20.0))),
hintText: 'Search for a recipient',
),
onChanged: null,
),
new FlatButton(
onPressed: () {_controller.clear();},
child: new Icon(Icons.clear)
),
],
),
),
),
bottomNavigationBar: NavBar(),
);
}
【问题讨论】:
-
你用的是什么 Flutter 版本?在项目目录中运行
flutter analyze时是否遇到同样的错误?能否请您添加完整的错误输出? -
Flutter 版本 v0.5.1(测试版)。运行
flutter analyze不会返回相同的错误。唯一的错误是{ "resource": "/Users/Samuel/Documents/GitHub/MyApp/lib/root_page.dart", "owner": "dart", "code": "missing_return", "severity": 4, "message": "This function declares a return type of 'Widget', but doesn't end with a return statement.", "source": "dart", "startLineNumber": 47, "startColumn": 5, "endLineNumber": 47, "endColumn": 11, "tags": [] } -
那么重启 IDE 应该已经解决了。您使用的是什么 IDE?
-
使用 VSCode。我刚刚重新启动,它工作!谢谢...这么简单的解决方案哈哈
-
很高兴听到:)
标签: dart flutter flutter-layout