如何创建自定义的启动屏幕在flutter中实现启动屏幕界面



你能给我一个实际的例子吗?我不太明白。

https://flutter.dev/docs/development/ui/advanced/splash-screen#implement-防溅屏接口

private MySplashView mySplashView;
@Override
@Nullable
public View createSplashView(
@NonNull Context context,
@Nullable Bundle savedInstanceState
) {

mySplashView = new MySplashView(context);
return mySplashView;
}
@Override
public void transitionToFlutter(@NonNull Runnable onTransitionComplete) {

mySplashView.animateAway(onTransitionComplete);
}
}

使用此软件包=>https://pub.dev/packages/splashscreen

1( 。在pubsec.yaml中添加以下依赖项,然后在终端中调用$ flutter pub get

dependencies:
splashscreen: ^1.3.5

2( 。然后休耕以下示例

import 'package:flutter/material.dart';
import 'package:splashscreen/splashscreen.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new SplashScreen(
seconds: 14,
navigateAfterSeconds: new AfterSplash(),
title: new Text(
'Welcome In SplashScreen',
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
image: new Image.network(
'https://flutter.io/images/catalog-widget-placeholder.png'),
backgroundColor: Colors.white,
loaderColor: Colors.red,
);
}
}
class AfterSplash extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Welcome In SplashScreen Package"),
automaticallyImplyLeading: false,
),
body: new Center(
child: new Text(
"Succeeded!",
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 30.0),
),
),
);
}
}

示例复制自=>https://pub.dev/packages/splashscreen/example

相关内容

  • 没有找到相关文章

最新更新