skip to Main Content

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(
        ^^^^^^^^^

New Errors
Error for running the app

2

Answers


  1. 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 change

    Replace every FlatButton with TextButton and for showing a SnackBar you can use:

    ScaffoldMessenger.of(context).showSnackBar(snackBar);
    
    Login or Signup to reply.
  2. I forgot to import material.dart

    import 'package:flutter/material.dart';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search