Sam*_*m A 7 dart flutter flutter-layout
我正在尝试使用颤振(使用 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(),
);
}
Run Code Online (Sandbox Code Playgroud)
zip*_*zit 10
I had a terrible time with this error (apparently different root cause as that corrected via comments above.) . Info offered here in case anybody else finds this posting based on the error code.
In my case I had a poorly formed constructor...
in main.dart...
@override
void initState() {
tapScreen = PageTapScreen(
key : keyOne,
profileList : demoProfiles,
tapScreenContext : tapScreenContext,
); . . .
Run Code Online (Sandbox Code Playgroud)
Elsewhere in my code base:
class PageTapScreen extends StatefulWidget {
final Key key;
final List<Profile> profileList;
final BuildContext tapScreenContext;
PageTapScreen(
this.key,
this.profileList,
this.tapScreenContext) : super(key: key) . . .
Run Code Online (Sandbox Code Playgroud)
Error generated from the tapScreen = ... call in main.dart:
3 required argument(s) expected, but 0 found.
The named parameter 'key' isn't defined.
The named parameter 'profileList' isn't defined.
The named parameter 'tapScreenContext' isn't defined.
Run Code Online (Sandbox Code Playgroud)
The fix was to add curly brackets to the Class constructor to clearly specify named parameters, per this reference.
PageTapScreen({
this.key,
this.profileList,
this.tapScreenContext}) : super(key: key)
Run Code Online (Sandbox Code Playgroud)
Again, the only reason I'm posting here is to highlight a potential fix to the error code noted in the original write up. Thia fix may not be intuitive based on the error message.
| 归档时间: |
|
| 查看次数: |
8346 次 |
| 最近记录: |