2
votes

I moved to stable flutter channel from beta, after upgrading flutter,

I am getting error for ListTile() attributes and ScaffoldMassanger,

 child: ListTile(
        horizontalTitleGap: 10, // error
        minVerticalPadding: 10, // error
        ),


  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
    content: Text('success'),
    duration: Duration(seconds: 2),
  ));

I tried below solutions:

 flutter upgrade
 flutter clean
 flutter pub get
 reinstalled dart and flutter plugin in VSCode
 flutter run
 updated vscode

no success

error log after removing depreciated attributes,

lib/widgets/list_expense.dart:32:9: Error: The getter 'ScaffoldMessenger' isn't defined for the class '_ListExpenseState'.

  • '_ListExpenseState' is from 'package:XpenseTracker/widgets/list_expense.dart' ('lib/widgets/list_expense.dart'). Try correcting the name to the name of an existing getter, or defining a getter or field named 'ScaffoldMessenger'. ScaffoldMessenger.of(context).showSnackBar(SnackBar(
1
Do flutter clean, and then runShubham Narkhede
Can you also share the errors you are getting?gkpln3
@ShubhamNarkhede, I tried flutter clean and run , getting sameMrudul Addipalli
These properties will have been deprecated and then removed. You should try to use an alternative. Also yes, please copy the error in this post or we can't be sure.James
I have replaced the attributes, but I am getting error for Scaffold Massanger, and added error by editing , please have a look for Scaffold massangerMrudul Addipalli

1 Answers

1
votes

These properties have been removed, as can be seen in the class (ListTile) documentation: https://api.flutter.dev/flutter/material/ListTile/ListTile.html

Please take a look at this package here, in order to use these properties: https://pub.dev/packages/list_tile_more_customizable

[EDIT] For your Scaffold issue please try to use a static helper function like so, then pass the string to render, along with the BuildContext:

 static Future showSimpleSnackBar(
      String message, GlobalKey<ScaffoldState> contextState) async {
      final snackBar = SnackBar(
        content: Text(message),
        duration: Duration(seconds: 3),
        action: SnackBarAction(
          label: "Got it",
          onPressed: () {
            //invoke an action here...
          },
        ),
      );

  contextState.currentState.removeCurrentSnackBar(); 
  contextState.currentState.showSnackBar(snackBar);
  }

Make sure as well that the BuildContext is coming from a Global ScaffoldKey, and that the scaffold will be responsible with rendering the snackbar.