AlertDialog error after upgrading flutter

355

Change

builder: AlertDialog

to

builder: (_) => AlertDialog()
Share:
355
Ajit Kumar Dutta
Author by

Ajit Kumar Dutta

Updated on December 28, 2022

Comments

  • Ajit Kumar Dutta
    Ajit Kumar Dutta over 1 year

    I used AlertDialog to notify user about the internet availability. It was working fine until I upgrade my flutter using command flutter upgrade. Snapshot of the program is as follows:

    connectivitySubscription = Connectivity()
            .onConnectivityChanged
            .listen((ConnectivityResult connresult) {
          if (connresult == ConnectivityResult.none) {
            dialogshown = true;
            showDialog(
              context: context,
              barrierDismissible: false,
              builder: AlertDialog(
                title: Text(
                  "Error",
                ),
                content: Text(
                  "No Data Connection Available.",
                ),
                actions: <Widget>[
                  FlatButton(
                    onPressed: () => {
                      SystemChannels.platform.invokeMethod('SystemNavigator.pop'),
                    },
                    child: Text("Exit."),
                  ),
                ],
              ),
            );
          } else if (_previousResult == ConnectivityResult.none) {
            checkinternet().then((result) {
              if (result == true) {
                if (dialogshown == true) {
                  dialogshown = false;
                  Navigator.pop(context);
                }
              }
            });
          }
    
          _previousResult = connresult;
        });
    

    The error is in the

    builder: AlertDialog
    

    of showDialog function. Before upgrading flutter it was child: AlertDialog and was working fine, and after upgrading it is showing error. The quick fix suggestion by flutter makes it "builder: AlertDialog" still it is showing error. The error is "The argument type 'AlertDialog' can't be assigned to the parameter type 'Widget Function(BuildContext)'.". There are also Strike through line on every FlatButton and RaisedButton in my complete project with warning message "'FlatButton' is deprecated and shouldn't be used. Use TextButton instead".

    Please help me solve this problem. If I need to change to my previous version of flutter, let me know how to do? Thanks

    • fartem
      fartem about 3 years
      Can you show where in the code you are getting error?
  • Jigar Patel
    Jigar Patel about 3 years
    @AjitKumarDutta Great that it worked for you. If the answer helped, consider accepting it as the answer.