I have a Parent StatefulWidget and Child StatefulWidget. I want to call a function of parent widget i.e. goToPreviousItem from the child widget.
Parent Class
class Parent extends StatefulWidget {
@override
_ParentState createState() => _ParentState();
}
class _ParentState extends State<Parent> {
String item = 0;
@override
Widget build(BuildContext context) {
return ChildClass();
}
goToPreviousItem(value){
setState(() {item = value});
}
}
Child Class
class Child extends StatefulWidget {
@override
_ChildState createState() => _ChildState();
}
class _ChildState extends State<Child> {
@override
Widget build(BuildContext context) {
return Container(
child: FlatButton(
color: Color(0XFFEFEFEF),
textColor: primaryColor,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
padding: EdgeInsets.symmetric(
vertical: 15.0, horizontal: 10.0),
onPressed: () => goToPreviousItem(2),
child: Text(
"Update",
),
),
);
}
}
How can I do that?