Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

dart - after changing my flutter channel from beta to stable , error started coming up

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(
question from:https://stackoverflow.com/questions/65858785/after-changing-my-flutter-channel-from-beta-to-stable-error-started-coming-up

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...