I am fairly new in Flutter. I have an issue where I am stock. I am trying to parse data from one widget to another StatefulWidget.
I have this widget where I try to parse data from
class MaltInput extends StatefulWidget {
@override
_MaltInputState createState() => _MaltInputState();
}
class _MaltInputState extends State<MaltInput> {
List<String> malt = ['Malt 1', 'Malt 2', 'Malt 3'];
String maltpick = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Malt input'),
),
body: ListView.builder(
itemCount: malt.length,
itemBuilder: (context, index){
return Card(
child: ListTile(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Test(malt[index]),
));
},
title: Text(malt[index]),
),
);
},
),
);
}
}
Parse to this widget
class Test extends StatefulWidget {
String malt;
Test({this.malt});
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
String malt;
_TestState({this.malt});
List<String> items = [];
final TextEditingController ectrl = TextEditingController();
@override
Widget build(BuildContext context) {
String maltpick;
maltpick = (widget.malt);
//widget.malt = "";
return Scaffold(
appBar: AppBar(
title: Text('Dynamic content'),
),
body: Column(
children: <Widget>[
//
RaisedButton(
child: Text('Add malt'),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => MaltInput()));
}
),
Text('Header.....'),
Text(maltpick),
Expanded(
child: ListView.builder(
itemCount: items.length,
itemBuilder: (BuildContext ctxt, int Index){
return Text(items[Index]);
}
),),
],
),
);
}
}
The error is in this line : builder: (context) => Test(malt[index]), Error code: Error: Too many positional arguments: 0 allowed, but 1 found. Try removing the extra positional arguments. builder: (context) => Test(malt[index]),