how to pass a class function to a widget in another class in flutter

Viewed 129

i have 3 pages 1,2,3 i want to reach the 3rd page by clicking on a button in the 2nd page that implement a function from the 1st page

so how can i pass the function to the second page

so this is the class that has the function


class SharedPage extends StatefulWidget {
  _SharedPageState createState() => _SharedPageState();
}

class _SharedPageState extends State<SharedPage> {
  String _information = '';
   void updateInformation(String information) {
    setState(() => _information = information);
  }

  void moveToSecondPage() async {
    final information = await Navigator.push(
      context,
      MaterialPageRoute(builder: (context) {
        return AddShared(); /// this is the page that i want to reach 
      }),
    );
    updateInformation(information);
  }

and this is the class that i want to pass the function to

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {


  @override
  Widget build(BuildContext context) {
   
    var add = [
      
      FlatButton(
        shape: CircleBorder(),
        child: Icon(
          Icons.add,
          color: Colors.red,
          size: 30,
        ),
        onPressed: () {
          /// i want to implement the MoveToSecondScreen here 
        },
      ),
    
    ];

0 Answers
Related