Reputation: 624
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'.
Upvotes: 2
Views: 937
Reputation: 525
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.
Upvotes: 1