Android Studio 错误:未在Flutter中为类定义方法,并且模块是使用不兼容的版本编译的

mpbci0fu  于 2023-01-21  发布在  Android
关注(0)|答案(2)|浏览(182)

我只是尝试了一个源代码,我已经看到网上,我想测试它,但是,它是给我多个错误,因为新的更新小部件。

我尝试运行和执行的源代码是:https://github.com/themaaz32/phone_verification
运行应用程序时显示的错误如下:

lib/screens/login_screen.dart:52:12: Error: The method 'showSnackBar' isn't defined for the class 'ScaffoldState'.
 - 'ScaffoldState' is from 'package:flutter/src/material/scaffold.dart' ('/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart').
Try correcting the name to the name of an existing method, or defining a method named 'showSnackBar'.
          .showSnackBar(SnackBar(content: Text(e.message)));
           ^^^^^^^^^^^^
lib/screens/login_screen.dart:69:9: Error: The method 'FlatButton' isn't defined for the class '_LoginScreenState'.
 - '_LoginScreenState' is from 'package:phone_verification/screens/login_screen.dart' ('lib/screens/login_screen.dart').
Try correcting the name to the name of an existing method, or defining a method named 'FlatButton'.
        FlatButton(
        ^^^^^^^^^^
lib/screens/login_screen.dart:87:43: Error: The method 'showSnackBar' isn't defined for the class 'ScaffoldState'.
 - 'ScaffoldState' is from 'package:flutter/src/material/scaffold.dart' ('/C:/src/flutter/packages/flutter/lib/src/material/scaffold.dart').
Try correcting the name to the name of an existing method, or defining a method named 'showSnackBar'.
                _scaffoldKey.currentState.showSnackBar(
                                          ^^^^^^^^^^^^
lib/screens/login_screen.dart:122:9: Error: The method 'FlatButton' isn't defined for the class '_LoginScreenState'.
 - '_LoginScreenState' is from 'package:phone_verification/screens/login_screen.dart' ('lib/screens/login_screen.dart').
Try correcting the name to the name of an existing method, or defining a method named 'FlatButton'.
        FlatButton(
        ^^^^^^^^^

新错误

a8jjtwal

a8jjtwal1#

这是因为您的Flutter版本比库的版本新。库仍然使用FlatButton,例如,它作为一个破坏性的更改被删除
将每个FlatButton替换为TextButton,并显示您可以使用的SnackBar:

ScaffoldMessenger.of(context).showSnackBar(snackBar);
qltillow

qltillow2#

我忘了输入材料。

import 'package:flutter/material.dart';

相关问题