I made a reusable widget in flutter. It is a list item but when I press on it, it should navigate to another screen in the app. The problem is, I want the title of the list item (widget.title) to be the same as the CupertinoNavigationBar. I tried to pass it like in the official documentation but I get errors like: Expected 2 arguments but instead got 1. Please help me...
Here's the code:
class Elem extends StatefulWidget {
final String imagine;
final String titlu;
final String subtitlu;
final String tip;
final String link;
const Elem(
{Key key, this.imagine, this.titlu, this.subtitlu, this.tip, this.link})
: super(key: key);
@override
_StatefulStateCupertinoTwo createState() => _StatefulStateCupertinoTwo();
}
class _StatefulStateCupertinoTwo extends State<Elem> {
@override
Widget build(BuildContext context) {
return ListTile(
leading: ClipRRect(
child: Image.network(
widget.imagine,
),
borderRadius: BorderRadius.circular(10.0),
),
title: Text(widget.titlu, style: TextStyle(color: Colors.white)),
subtitle: Text(widget.subtitlu, style: TextStyle(color: Colors.grey)),
trailing: Icon(
CupertinoIcons.add_circled_solid,
color: CupertinoColors.systemBlue,
size: 30,
),
onTap: () {
Navigator.push(context, CupertinoPageRoute(builder: (context) => Detaile(
widget.titlu,
)));
},
);
}
}
class Detaile extends StatelessWidget{
final String title;
// receive data from the FirstScreen as a parameter
Detaile(String titlu, {Key key, @required this.title}) : super(key: key);
@override
Widget build(BuildContext context) {
// TODO: implement build
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text(title),
),
child: Text('Hello'),
);
},
}
Also, here are some errors I get:
Too many positional arguments: 0 expected, but 1 found. Try removing the extra arguments.
Too many positional arguments: 2 expected, but 1 found. Try removing the extra arguments.
Undefined name 'titlu'. Try correcting the name to one that is defined, or defining the name.
Arguments of a constant creation must be constant expressions. Try making the argument a valid constant, or use 'new' to call the constructor.
Evaluation of this constant expression throws an exception.