Flutter & Shared_Preference & Intro Slider : Shared_Preference produces exception

234 views Asked by At

Flutter & Shared_Preference & Intro Slider: Shared_Preference produces exception. I wanted to create an introduction slider. So I use shared_preference (Detect if the user uses the app for the first time) and intro_slider plugin to make. For some reason, I got this exception error, which stopped my emulator immediately. In other word, the app was installed but I was kicked out from the app and my running process just stopped.

Since the app was already installed, I tried to open it manually. And it worked fine.

Why did my running process stop? Why was I kicked out from the process?

Main code

import 'package:PhotoEarn/screens/wrapper.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'introduction_slider/introduction_slider.dart';

class AppStarter extends StatefulWidget {
  @override
  _AppStarterState createState() => _AppStarterState();
}

class _AppStarterState extends State<AppStarter> {
  @override
  void initState() {
    super.initState();
    //  checkIsFirstTime();
  }

  Future<Widget> checkIsFirstTime() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    final bool isFirstTime = prefs.getBool('isFirstTime');

    // check is null or true
    if (isFirstTime == null || isFirstTime) {
      prefs.setBool('isFirstTime', false);
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(
          builder: (context) => IntroductionSlider(),
          //builder: (context) => ImageEvaluation(),
          //builder: (context) => CameraTwo(),
        ),
      );
    } else {
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(
          builder: (context) => Wrapper(),
          //builder: (context) => ImageEvaluation(),
          //builder: (context) => CameraTwo(),
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
}

Error message

(base) Punreachs-MacBook-Pro:PhotoEarn punreachrany$ flutter run
Using hardware rendering with device AOSP on IA Emulator. If you notice graphics
artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib/main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                         7,2s
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...                 3,2s
Waiting for AOSP on IA Emulator to report its views...               4ms
D/EGL_emulation( 8483): eglMakeCurrent: 0xdc517240: ver 3 0 (tinfo 0xdc4a6d00)
D/eglCodecCommon( 8483): setVertexArrayObject: set vao to 0 (0) 1 0     
I/sterable.pe.an( 8483): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.messaging.FirebaseMessagingService>: java.lang.VerifyError: Superclass com.google.firebase.iid.zzb of com.google.firebase.messaging.FirebaseMessagingService is declared final (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.oysterable.pe.and-x4wuluezItpEc-2nGrSGUg==/base.apk!classes3.dex)
I/sterable.pe.an( 8483):   at java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2)
I/sterable.pe.an( 8483):   at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:738)
I/sterable.pe.an( 8483):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:363)
I/sterable.pe.an( 8483):   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I/sterable.pe.an( 8483):   at android.app.Service android.app.AppComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (AppComponentFactory.java:103)
I/sterable.pe.an( 8483):   at android.app.Service androidx.core.app.CoreComponentFactory.instantiateService(java.lang.ClassLoader, java.lang.String, android.content.Intent) (CoreComponentFactory.java:66)
I/sterable.pe.an( 8483):   at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:3514)
I/sterable.pe.an( 8483):   at void android.app.ActivityThread.access$1300(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:199)
I/sterable.pe.an( 8483):   at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1666)
I/sterable.pe.an( 8483):   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
I/sterable.pe.an( 8483):   at void android.os.Looper.loop() (Looper.java:193)
I/sterable.pe.an( 8483):   at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6669)
I/sterable.pe.an( 8483):   at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
I/sterable.pe.an( 8483):   at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
I/sterable.pe.an( 8483):   at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)
I/sterable.pe.an( 8483):                                                
D/AndroidRuntime( 8483): Shutting down VM                               
E/AndroidRuntime( 8483): FATAL EXCEPTION: main                          
E/AndroidRuntime( 8483): Process: com.oysterable.pe.and, PID: 8483      
E/AndroidRuntime( 8483): java.lang.VerifyError: Superclass com.google.firebase.iid.zzb of com.google.firebase.messaging.FirebaseMessagingService is declared final (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.oysterable.pe.and-x4wuluezItpEc-2nGrSGUg==/base.apk!classes3.dex)
E/AndroidRuntime( 8483):        at java.lang.VMClassLoader.findLoadedClass(Native Method)
E/AndroidRuntime( 8483):        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
E/AndroidRuntime( 8483):        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
E/AndroidRuntime( 8483):        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 8483):        at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
E/AndroidRuntime( 8483):        at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:66)
E/AndroidRuntime( 8483):        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3514)
E/AndroidRuntime( 8483):        at android.app.ActivityThread.access$1300(ActivityThread.java:199)
E/AndroidRuntime( 8483):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1666)
E/AndroidRuntime( 8483):        at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 8483):        at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 8483):        at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime( 8483):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8483):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 8483):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process ( 8483): Sending signal. PID: 8483 SIG: 9                     
Lost connection to device.                                              
Syncing files to device AOSP on IA Emulator...                          
Could not update files on device: HttpException: Connection closed before full
header was received, uri = http://127.0.0.1:55559/9hULGLtexbI=/
Syncing files to device AOSP on IA Emulator...                                                                                       
(base) Punreachs-MacBook-Pro:PhotoEarn punreachrany$ 
1

There are 1 answers

0
Akif On BEST ANSWER

Why did my running process stop? Why was I kicked out of the process?

There are always similar problems in mobile app development. You should get used to this. Most of the answers will be something like this:

  • restart IDE,
  • flutter pub cache repair,
  • flutter clean.