I was just trying out a source code that I have seen online, and I wanted to test it, however, it is giving me multiple errors because of the new update on widgets.
The source code that I am trying to run and execute is: https://github.com/themaaz32/phone_verification
The errors being displayed when I run the application are the following:
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(
^^^^^^^^^
2
Answers
This is because your version of Flutter is newer than that of the library. The library still uses
FlatButton
for example which was removed as a breaking changeReplace every
FlatButton
withTextButton
and for showing a SnackBar you can use:I forgot to import material.dart