gpt4 book ai didi

flutter - 带自动路线的启动画面

转载 作者:行者123 更新时间:2023-12-03 08:11:35 25 4
gpt4 key购买 nike

我想实现一个动画启动画面

通常在MaterialApp中,我们有一个名为home的属性,但是当我使用自动路由(MaterialApp.router)时,我无法在其中找到一个home,那么如何使用自动路由实现启动屏幕

package link

main.dart 文件

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();

runApp(
EasyLocalization(
supportedLocales: const <Locale>[Locale('en')],
path: 'assets/i18n',
fallbackLocale: const Locale('en'),
child: const App(),
),
);
}
class Appp extends StatefulWidget {
const Appp({Key? key}) : super(key: key);

@override
State<Appp> createState() =>
_ApppState();
}

class _ApppState extends State<Appp> {
final _themeStore = ThemeStore();
final _appRouter = AppRouter();

@override
Widget build(BuildContext context) {
return MaterialApp.router(
debugShowCheckedModeBanner: false,
title: 'App',
theme: _themeStore.selectedThemeData,
routerDelegate: _appRouter.delegate(),
routeInformationParser: _appRouter.defaultRouteParser(),
);
}
}

最佳答案

首先您必须显示启动屏幕,然后对于下一个屏幕,您可以使用 MaterialApp.router

例如。

void main() {
runApp(SplashScreen());
}

class SplashScreen extends StatelessWidget {
SplashScreen({Key? key}) : super(key: key);
final _appRouter = AppRouter();

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Splash App',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: AnimatedSplashScreen(
animationDuration: const Duration(seconds: 2),
splashTransition: SplashTransition.slideTransition,
splash: Icons.code,
nextScreen: MaterialApp.router(
routeInformationParser: _appRouter.defaultRouteParser(),
routerDelegate: _appRouter.delegate(),
),
),
);
}
}

使用的包:

关于flutter - 带自动路线的启动画面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70661874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com