I'm trying to get my app bar to change dynamically, example if on page 1 I press add condition it will add data to my database and it will rotate to a new screen and show the title of data that I add in screen 2,

I already try this https://flutter.dev/docs/cookbook/navigation/passing-data#1-define-a-todo-class and still got so much error

this is my add data code

Future<bool> addDialog(BuildContext context) async {
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('Add Table', style: TextStyle(fontSize: 15.0)),
            content: Column(
              children: <Widget>[
                TextField(
                  textInputAction: TextInputAction.next,
                  decoration: InputDecoration(hintText: 'Enter Table Name'),
                  onChanged: (value) {
                    this.tableName = value;
                  },
                ),
                SizedBox(height: 5.0),
                TextField(
                  keyboardType: TextInputType.number,
                  decoration: InputDecoration(hintText: 'Enter Guest Pax'),
                  onChanged: (value) {
                    this.guestPax = value;
                  },
                ),
                SizedBox(height: 5.0),
                Row(
                  children: <Widget>[
                    FlatButton(
                      child: Text('Add'),
                      textColor: Colors.blue,
                      onPressed: () {
                        if (!UtilsImporter()
                            .commanUtils
                            .validateTName(tableName)) {
                          UtilsImporter().commanUtils.showToast(
                              UtilsImporter().stringUtils.retrunTName, context);
                        } else if (!UtilsImporter()
                            .commanUtils
                            .validateGuestPax(guestPax)) {
                          UtilsImporter().commanUtils.showToast(
                              UtilsImporter().stringUtils.returnGuestPax,
                              context);
                        } else {
                          crudObj.addData({
                            'tableName': this.tableName,
                            'guestPax': this.guestPax
                          }).then((result) {
                            // dialogTrigger(context);
                          }).catchError((e) {
                            print(e);
                          });

                          Navigator.of(context)
                              .pushReplacementNamed('/Dashboard'); << this here i want after press it will navigate to the 2nd screen and show this 'tableName' to my title
                        }
                      },
                    ),
                    FlatButton(
                      child: Text('Return'),
                      textColor: Colors.blue,
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    )
                  ],
                ),
              ],
            ),
          );
        });
  }


Solution 1: Kailash Chouhan

try using below

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => YourPage('Your Text to send'),
  ),
);

and on the next page

class YourPage extends StatefulWidget {
  YourPage(this.text);

  final String text;

  @override
  State<StatefulWidget> createState() => new YourPageState();
}

then set on app bar header like below

Test(widget.text)