Flutter : How to dismiss an AlertDialog on Button?

Problem

I’m showing an AlertDialog on my App, but when I click on no/cancel then AlertDialog doesn’t dismiss, it keep popping the route where I came from. I’ve used Navigator.of(context).pop(); and Navigator.pop(context, false); but both are not working.

Solution

To Dismiss an AlertDialog Navigator.of(context).pop(); works but in my case below code worked.

Navigator.of(context, rootNavigator: true).pop('dialog');

That’s All.

Thanks for reading.

Keep Coding.

Tagged : / / /

[SOLVED] Flutter : firebase_core_web not found. Please update settings.gradle.

Solution

In your android/app/build.gradle, update the following:

android {
    // ...
    defaultConfig {
        // ...
        minSdkVersion 16
    }
}

into:

android {
    // ...
    defaultConfig {
        // ...
        minSdkVersion 23
    }
}


Note: You need to use minSdkVersion 23 when using firebase in flutter.

That’s All.

Thanks for reading.

Keep Coding.

Tagged : / / / / /

[SOLVED] Flutter: Not showing “Open for editing in Android Studio”

The problem is caused by missing .iml project files. These files are added automatically to the .gitignore file but they should not. To fix it:

  1. Delete .idea folder.
  2. Create a new temporary Flutter project with the same name.
  3. Copy from the project to your existing project these 2 missing files:
  • [project_name].iml
  • android/[project_name]_android.iml
  1. Open Android Studio and the problem should be gone.

To avoid it in the future, make sure .iml files are not excluded in the gitignore. There is a Github issue on this topic.

Tagged : / / / / / /

How To Remove RECAPTCHA From Phone Auth In Flutter Firebase

Problem

I have implemented firebase phone Auth in my flutter app but whenever i fill phone no. and click on send otp then it opens a RECAPTCHA verification url in browser by default. I don’t want to show it.

See the below screenshot of popup.

enter image description here

Solution

Follow the below Steps :-

Step 1 :- Go to Google Cloud Console, enable the Android Device Check API for your project ( Select the same project which you have created in firebase for flutter App. ). The default Firebase API Key will be used, and needs to be allowed to access the DeviceCheck API.

Step 2 :- If you haven’t added SHA-256 fingerprint in firebase then add it too.

For more information, you can also check Google SafetyNet API for checking Google Play Services installation in device at the time of Phone Authentication.

That’s All

Thanks for Reading.

Keep Coding.

[SOLVED] FlutterFirebaseMessagingPlugin.java – Build fails with Exception “error: cannot find symbol”

Problem

After upgrading firebase_auth to latest version (i.e., ^1.2.0), it says update intl to ^0.17.0. When i updated intl, I’m getting errors when I try to run flutter pub get.

C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:20: error: cannot find symbol
    import com.google.firebase.iid.FirebaseInstanceId;
                                  ^
      symbol:   class FirebaseInstanceId
      location: package com.google.firebase.iid
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:21: error: cannot find symbol
    import com.google.firebase.iid.Metadata;
                                  ^
      symbol:   class Metadata
      location: package com.google.firebase.iid
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:152: error: cannot find symbol
                      : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                        ^
      symbol:   variable Metadata
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:153: error: cannot find symbol
              FirebaseInstanceId.getInstance().deleteToken(senderId, "*");
              ^
      symbol:   variable FirebaseInstanceId
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:165: error: cannot find symbol
                      : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                        ^
      symbol:   variable Metadata
      location: class FlutterFirebaseMessagingPlugin
    C:\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:166: error: cannot find symbol
              String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
                             ^
      symbol:   variable FirebaseInstanceId
      location: class FlutterFirebaseMessagingPlugin

Solution

Update firebase_messaging to latest one (Currently i.e., firebase_messaging: ^10.0.0), and call flutter pub get.

That’s it.

Thanks for Reading.

Keep Coding.

Tagged : / / / /

[SOLVED] Flutter Webview throws Compiling Error.

Problem

The android studio while running throws this error and stop the build

A:\flutter.pub-cache\hosted\pub.dartlang.org\webview_flutter-2.0.6\android\src\main\java\io\flutter\plugins\webviewflutter\InputAwareWebView.java:31: error: cannot find symbol private ThreadedInputConnectionProxyAdapterView proxyAdapterView; ^ symbol: class ThreadedInputConnectionProxyAdapterView location: class InputAwareWebView

A:\flutter.pub-cache\hosted\pub.dartlang.org\webview_flutter-2.0.6\android\src\main\java\io\flutter\plugins\webviewflutter\InputAwareWebView.java:112: error: cannot find symbol new ThreadedInputConnectionProxyAdapterView( ^ symbol: class ThreadedInputConnectionProxyAdapterView location: class InputAwareWebView Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 2 errors

FAILURE: Build failed with an exception.

Solution

ThreadedInputConnectionProxyAdapterView has wrong extension .jav just change it to .java until the flutter team release the fix.

Its Located to :- C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\webview_flutter-2.0.6\android\src\main\java\io\flutter\plugins\webviewflutter

That’s All.

Thanks for Reading.

Keep Coding.

Tagged : / / / /

[SOLVED] Flutter : Cannot run with sound null safety, because the following dependencies don’t support null safety

Problem

I’m using flutter_recaptcha_v2: ^0.1.0. Now, I am trying to run it using flutter run, however, it will not start because of the following error:

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

- package:flutter_recaptcha_v2
- package:webview_flutter
- package:http
- package:http_parser

For solutions, see https://dart.dev/go/unsound-null-safety
FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 21s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

Solution

If you want run your project with --no-sound-null-safety so now you add this line your main.dart file in top(first line) with comment..

// @dart=2.9

then run your project.

Thanks for reading.

Keep Coding.

Tagged : / / / / / / /

[SOLVED] Flutter : NoSuchMethodError: The getter ‘isEmpty’ was called on null.

Problem

I’m Calling An API and getting response in Variable Data ($data). When data is coming then there is no Error but when I’m getting null as response then getting this error Unhandled Exception: NoSuchMethodError: The getter ‘isEmpty’ was called on null.

When I am using the below code then it is throwing me an error:

Solution

That is because $data returns null, So I’ve Used

if(data?.isEmpty ?? true)

? prevents an error if the previous part of the expression results in null and ?? true results in true if the previous part of the expression is null and therefore treats == null and isEmpty the same for the if(...) check.

Now My Code is working Fine.

Thanks for reading.

Keep Coding.

Tagged : / / / / / /

[Solved] Flutter : [core/not-initialized] Firebase has not been correctly initialized. Have you added the “google-services.json” file to the project?

Problem

I’ve connected my flutter app to firebase by adding SHA1 key ( How to Get SHA-1 key in Android Studio for Firebase. ) and package name in firebase console, and also downloaded and provided google-service.json in my flutter app at android/app. But when i run app its Showing an error that i’ve not provided google-service.json file in my app. The Error Says –

E/flutter (15568): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project? 
E/flutter (15568): 

Solution

After hours of struggle, I am able to figure out the solution.

1. First, add the ‘google-services.json‘ plugin as a dependency inside of the android/build.gradle file:

 buildscript {
      dependencies {
        // ... other dependencies
        classpath 'com.google.gms:google-services:4.3.3'
      }
    }

2. Lastly, execute the plugin by adding the following underneath the line apply plugin:
add after ‘com.android.application’, within the /android/app/build.gradle file:

apply plugin: 'com.google.gms.google-services'

That’s All.

Thanks for Reading.

Keep Coding.

Tagged : / / / / / / /