Flutter & Shared_Preference & Intro Slider : Shared_Preference 产生异常

Flutter & Shared_Preference & Intro Slider : Shared_Preference produces exception

Flutter & Shared_Preference & Intro Slider:Shared_Preference 产生异常。 我想创建一个介绍滑块。所以我使用 shared_preference (检测用户是否是第一次使用该应用程序)和 intro_slider 插件来制作。出于某种原因,我得到了这个异常错误,它立即停止了我的模拟器。换句话说,应用程序已安装,但我被踢出了应用程序,我的 运行 进程刚刚停止。

由于已经安装了该应用程序,我尝试手动打开它。而且效果很好。

为什么我的 运行 进程停止了?为什么我被踢出了流程?

主要代码

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();
  }
}

错误信息

(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.access00(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.access00(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$ 

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

移动应用开发中总是存在类似的问题。你应该习惯这个。大多数答案将是这样的:

  • 重启IDE,
  • flutter pub cache repair,
  • flutter clean.