Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'1 required argument(s) expected but 0 found' error

I'm trying my hand at building an app with flutter (which uses Dart 2). I'm getting an error which I cant figure out:

The error is at the 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(),
    );
  } 
like image 973
Sam A Avatar asked Aug 03 '18 07:08

Sam A


1 Answers

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,
    ); . . . 

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)  . . . 

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.

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)  

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.

like image 192
zipzit Avatar answered Oct 13 '22 01:10

zipzit