Flutter iOS应用程序安装在真实的设备上时卡在启动屏幕上

pftdvrlh  于 2023-08-07  发布在  Flutter
关注(0)|答案(1)|浏览(188)

我有一个flutter应用程序,我已经设置了flutter_native_splash屏幕与包是相同的。我已经使用了安装指南中的命令和描述(pub spec.yaml等),我的应用在Android模拟器、真实的的Android设备和iOS模拟器(和真正的设备)的调试模式上测试时运行良好。现在令人困惑的是,应用程序有时会出现在应用程序打开的启动屏幕中。只有当我从TestFlight安装版本时才会发生这种情况。但当我多次尝试打开应用程序时,它会将应用程序打开到主屏幕。没有错误显示在控制台等,我的Flutter医生是说,一切都安装正确。
以下是我的主要.dart代码:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  //Notifications
  await FirebaseApi().initNotifications();
  HttpOverrides.global = MyHttpOverrides();
  //Hive Database
  await Hive.initFlutter();
  //Analytics init
  FirebaseAnalytics analytics = FirebaseAnalytics.instance;
  final SharedPreferences sharedPreferences =
      await SharedPreferences.getInstance();
  runApp(const AulingerMain());
  // Need await here
  await Future.delayed(const Duration(milliseconds: 1));
  FlutterNativeSplash.remove();
}

class AulingerMain extends StatefulWidget {
  const AulingerMain({super.key});

  @override
  State<AulingerMain> createState() => _AulingerMainState();
}

class _AulingerMainState extends State<AulingerMain> {
  @override
  Widget build(BuildContext context) {
    return OverlaySupport(
      child: MultiProvider(
        providers: [
          ListenableProvider<UserProvider>(create: (_) => UserProvider()),
        ],
        child: ThemeModeHandler(
            manager: ThemeManager(),
            builder: (ThemeMode themeMode) {
              return MaterialApp(
                  title: 'Gasthof zum Sonnenwald',
                  debugShowCheckedModeBanner: false,
                  theme: ThemeData(
                      appBarTheme: const AppBarTheme(
                    centerTitle: true,
                    backgroundColor: Colors.amber,
                  )),
                  darkTheme: ThemeData.dark(),
                  themeMode: themeMode,
                  home: FutureBuilder<bool>(
                    future: checkFirstTime(),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.waiting) {
                        return const Center(
                          child: CircularProgressIndicator(color: Colors.amber),
                        );
                      }

                      final isFirstTime = snapshot.data ?? true;

                      return isFirstTime
                          ? const EinfuehrungFrage()
                          : const AutoLoginHandler();
                    },
                  ), //sets home to autologinhandler at start for auto login
                  builder: (context, child) {
                    return MediaQuery(
                      data:
                          MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
                      child: child!,
                    );
                  },
                  routes: {
                    Settings.routeName: (ctx) => const Settings(),
                    MainPage.routeName: (ctx) => const MainPage(),
                    Speisekarte.routeName: (ctx) => const Speisekarte(),
                    ContactUsPage.routeName: (ctx) => const ContactUsPage(),
                    LoginScreen.routeName: (ctx) => const LoginScreen(),
                    ImprintScreen.routeName: (ctx) => const ImprintScreen(),
                    SelectionScreenEssen.routeName: (ctx) =>
                        const SelectionScreenEssen(),
                    PrivacyPolicyScreen.routeName: (ctx) =>
                        const PrivacyPolicyScreen(),
                  });
            }),
      ),
    );
  }

  Future<bool> checkFirstTime() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    bool isFirstTime = prefs.getBool('isFirstTime') ?? true;
    return isFirstTime;
  }
}

class MyHttpOverrides extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

字符串
这是pubsped.yaml的代码:

flutter_native_splash:
  color: "#FFFFFF"
  image: assets/icons/appstore.png
  image_dark: assets/icons/appstore.png
  color_dark: "#282828"
  android: true
  ios: true


我希望你能帮我这个忙!:)

8i9zcol2

8i9zcol21#

您过早调用FlutterNativeSplash.remove();。您应该在第一个屏幕的initState()方法中调用这一行。

class _AulingerMainState extends State<AulingerMain> {

  @override
  void initState() {
    FlutterNativeSplash.remove();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
  ...

字符串
编辑:在你的主方法中,替换

WidgetsFlutterBinding.ensureInitialized();


WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

相关问题