1

I've tried to do WidgetsFlutterBinding.ensureInitialized() before runApp() but am still getting the same problem.Please help

my main:

"void main() {WidgetsFlutterBinding.ensureInitialized();runApp(MaterialApp(initialRoute'/',
routes:
{
  '/':(context) => Splash(),
  '/register' : (context) => Register(),
  '/login' : (context) => Login(),
},
debugShowCheckedModeBanner: false,));}"
  • Add the code for main.dart, flutter doctor -v, and are you running in debug mode or release mode? These details will help narrow the problem – Siddharth Agrawal Mar 12 '21 at 13:11
  • if I run "flutter build apk" or "flutter build apk --release" then take that apk an install it in an android device, i get stuck on the splash screen. but when i run the app on a device connected to my laptop through a cable the issue disappears – Michael Wayne Mar 12 '21 at 13:46
  • @MichaelWayne have added internet permission in android manifest file? – Shubham Narkhede Mar 12 '21 at 13:48
  • void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(MaterialApp( initialRoute: '/', routes: { '/':(context) => Splash(), '/register' : (context) => Register(), '/login' : (context) => Login(), }, debugShowCheckedModeBanner: false, )); } – Michael Wayne Mar 12 '21 at 13:48
  • 1
    I am 99 percent sure I know the problem because it happened to me like 5 days ago. Just do these two things to make sure. Run flutter run --release in the terminal and paste the error in your code and do you have firebase in your app or not. And edit your question and place it in between of `````` to do it. Please dont paste it in the comments – Siddharth Agrawal Mar 12 '21 at 13:48
  • @ShubhamNarkhede yes – Michael Wayne Mar 12 '21 at 13:49
  • @SiddharthAgrawal no am not using firebase – Michael Wayne Mar 12 '21 at 13:50
  • ooohhh . Just paste the output when you try to install app with flutter run --release – Siddharth Agrawal Mar 12 '21 at 13:52
  • E/flutter (20853): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) @SiddharthAgrawal E/flutter (20853): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method showToast – Michael Wayne Mar 12 '21 at 14:03
  • Yay we got the answer. I have answered it in another question too so let me just paste the answer here and add a link to that one too – Siddharth Agrawal Mar 12 '21 at 14:05
  • Check my answer @MichaelWayne . I hope it works – Siddharth Agrawal Mar 12 '21 at 14:14
  • As the answer worked, upvote my answer and click the check mark next to it to accept it. This will give me points for helping you and allow others who face this problem know whart the right answer is @MichaelWayne – Siddharth Agrawal Mar 15 '21 at 09:41

1 Answers1

2

After doing a lot of research, I found the answer. Add this to your code before you use shared preferences.

SharedPreferences.setMockInitialValues({});

It is because if you use getAll where there is nothing, it will go crazy. I don't think it is anything to do with iOS. If you even use normal getString, the internal program uses getAll so it will still crash https://stackoverflow.com/a/63027655/13858991

You can check the answer here too

Siddharth Agrawal
  • 2,960
  • 3
  • 16
  • 37
  • If the answer works dont forget to accept it and give it an upvote, on this answer and the place where I answered. Just telling you because you are new. This will help me and people who face this problem in future – Siddharth Agrawal Mar 12 '21 at 14:07
  • SharedPreferences.setMockInitialValues({}) solves the problem of app being stuck at splash screen but it is not the ideal solution as it clears shared preferences every time when this code snippet is executed. Adding android:allowBackup="false" tag inside object in app manifest solved for me – Rajath Dec 22 '22 at 08:04