0

I'm facing an issue after building my Flutter app (especially in release mode). The app crashes or throws the following errors related to SharedPreferences and FlutterToast plugins.

I/flutter (10569): SharedPreferences init failed: 
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.shared_preferences_android.SharedPreferencesApi.getAll", null, null)

I/flutter (10569): user auth permission

E/flutter (10569): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] 
Unhandled Exception: MissingPluginException(No implementation found for method showToast on channel PonnamKarthik/fluttertoast)
E/flutter (10569): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:365)

Flutter version: 3.35.7

Plugins used:

  • shared_preferences: ^2.5.3

  • fluttertoast: ^9.0.0

5
  • Did you Google the error? github.com/ponnamkarthik/FlutterToast/issues/… Commented Nov 3 at 12:47
  • What fixes do you try? Did you try flutter clean before you build? Do you use ProGuard rules in your app? Commented Nov 3 at 12:48
  • Please share your pubspec.yaml file Commented Nov 3 at 17:18
  • Yes, I already tried running flutter clean before building. And yes, my app also uses ProGuard rules. I’ve added the required keep rules for Play Core, Flutter Sound, and other plugins. Still getting the same MissingPluginException and PlatformException errors in release build. @MostafaSoliman Commented Nov 4 at 3:32
  • @MostafaSoliman Yes, I already tried flutter clean before building, and I’m using ProGuard rules in my app. I also added this rule for Flutter Toast: -keep class io.github.ponnamkarthik.toast.** { *; } But it still didn’t fix the issue — I’m still getting the same errors in the release build. Commented Nov 4 at 3:59

1 Answer 1

0

You are probably trying to initialize SharedPreferences & Toast before the runApp happen (in your main) if that's the case this should solve your issue:

Add this to the begining of your main:

WidgetsFlutterBinding.ensureInitialized();

This will start the Native Binding process before, ensuring is ready when you call the plugins

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.