我有一个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
型
我希望你能帮我这个忙!:)
1条答案
按热度按时间8i9zcol21#
您过早调用
FlutterNativeSplash.remove();
。您应该在第一个屏幕的initState()
方法中调用这一行。字符串
编辑:在你的主方法中,替换
型
与
型