0

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

annyeongk
  • 19
  • 1
  • 7

2 Answers2

0

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);
TripleNine
  • 1,457
  • 1
  • 4
  • 15
  • which part should I change in the SnackBar? – annyeongk Sep 19 '22 at 18:11
  • AFAIK you don't need to change `SnackBar`. If you still get an error, please share the error message. – TripleNine Sep 19 '22 at 18:17
  • snackbar is okay already, but it says Error: No named parameter with the name 'color'. for TextButton – annyeongk Sep 19 '22 at 18:22
  • The widgets are already resolved, however I am still getting errors whihc I will attach above. pls help – annyeongk Sep 19 '22 at 18:32
  • Try [this](https://stackoverflow.com/a/67801441/16463801). – TripleNine Sep 19 '22 at 18:37
  • New error occured: * What went wrong: A problem occurred evaluating project ':app'. > org/gradle/api/services/BuildService – annyeongk Sep 19 '22 at 18:42
  • That is shown after I tried changing the kotlin version – annyeongk Sep 19 '22 at 18:42
  • ERROR: Failed to apply plugin [id 'kotlin-android'] > The current Gradle version 5.6.2 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin. – annyeongk Sep 19 '22 at 18:48
  • Yes you also have to update the gradle version if you update the kotlin version. I usually init a new empty project or have a look at the latest flutter examples in github to see the versions i need. You can try kotlin: 1.6.10 and gradle:7.1.2. – TripleNine Sep 19 '22 at 18:53
  • I have eliminated the above errors in whichI hae upgraded kotlin and gradle but I still get an error.. Dependency 'androidx.window:window-java:1.0.0-beta04' requires 'compileSdkVersion' to be set to 31 or higher. Compilation target for module ':app' is 'android-29' – annyeongk Sep 19 '22 at 18:55
  • I just want to execute and try the source code :( – annyeongk Sep 19 '22 at 18:57
  • Go to android/app/build.gradle and change the `minSdkVersion` and `targetSdkVersion` to 31 or something above. – TripleNine Sep 19 '22 at 19:00
  • New error.. * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed : android:exported needs to be explicitly specified for element . Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. – annyeongk Sep 19 '22 at 19:01
  • Go to `android/app/src/main/AndroidManifest.xml` and add `android:exported` inside the `` tag beneath `android:icon` for example. If this doesn't help (what I assume) then your library didn't set the `android:exported` flag. Try [this](https://stackoverflow.com/a/68648841/16463801) then. – TripleNine Sep 19 '22 at 19:12
  • It has successfully run, however, the OTP is not being sent to the emulator, is there anything I should do with firebase or something? or it should work? After putting my number, it loads like forever – annyeongk Sep 19 '22 at 19:20
  • I can't help you there without any code. But this is off-topic, so please open another question. If this answer helped you, then please accept and upvote it. – TripleNine Sep 19 '22 at 19:24
  • the code is in te github repo. – annyeongk Sep 19 '22 at 19:24
0

I forgot to import material.dart

import 'package:flutter/material.dart';
Dr Strange
  • 87
  • 1
  • 5