-1

i have form with three dropdown buttons and these were declared at top of the class,

String _currentItemSelected1 = 'low';
String _currentItemSelected2 = 'low';
String _currentItemSelected3 = 'low';

then I have RisedButton with onPressed property with this body:

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => SuggestionResult(
      _currentItemSelected1,
      _currentItemSelected2,
      _currentItemSelected3,
    ),
  ),
);

in SuggestionResult class I was override the constructor as following:

final String temp;
final String hum;
final String light;
SuggestionResult({this.temp, this.hum, this.light});

Now, the PROBLEM is when I calling SuggestionResult class it says: "Too many positional arguments: 0 expected, but 3 found. Try removing the extra positional arguments, or specifying the name for named arguments."

Lucas Macêdo
  • 23
  • 1
  • 7
  • You need to understand the difference between positional and named arguments in dart. Have a look at [this question](https://stackoverflow.com/questions/13264230/what-is-the-difference-between-named-and-positional-parameters-in-dart). – Vineet Feb 06 '21 at 06:52

3 Answers3

0

try this;

onPressed: () {
             Navigator.push(
            context,
           MaterialPageRoute(
          builder: (context) => new SuggestionResult(temp:_currentItemSelected1, hum: _currentItemSelected2, light: _currentItemSelected3  
         ),
       ),
     );
  },

In Dart we define named parameters by surrounding them with curly ({}) braces: Like following;

SuggestionResult({this.temp, this.hum, this.light});

This means that we can create the widget above like this:

new SuggestionResult(temp: _currentItemSelected1, hum: _currentItemSelected2, light: _currentItemSelected3);
prahack
  • 1,267
  • 1
  • 15
  • 19
0

Try this:

new SuggestionResult(temp: _currentItemSelected1, hum: _currentItemSelected2, light: _currentItemSelected3);
Dan Gerchcovich
  • 168
  • 5
  • 12
0

When you call your SuggestionResult page you should specify the name of the parameters.

...
builder: (context) => new SuggestionResult(
    temp: _currentItemSelected1,
    hum: _currentItemSelected2,
    light: _currentItemSelected3,
);
...