Flutter 如何仅在加载颤振数据时显示启动屏幕
当应用程序的启动屏幕显示时,它需要从 FTP 服务器下载文件并处理数据。实现了 flutter 的启动屏幕
class Home extends StatelessWidget {
const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(snapshot.connectionState == ConnectionState.waiting)
return SplashUI(); ///Splash Screen
else
return MainUI(); ///Main Screen
},
);
}
}
现在,延迟 3 秒,启动屏幕显示 3 秒,在此期间从 FTP 下载文件并处理数据。我想保留启动屏幕直到数据处理完成而不是指定的时间。
启动画面
Widget _splashUI(Size size){
return SafeArea(
child: Center(
child: Container(
width: size.width * 0.5,
height: size.height * 0.1,
child: Image(
fit: BoxFit.fill,
image: AssetImage('assets/images/elf_logo.png'),
),
),
),
);
}
Widget build(BuildContext context) {
getFtpFile();
dataProgress();
return Platform.isAndroid ?
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: _splashUI(_size),
),
) :
CupertinoApp(
debugShowCheckedModeBanner: false,
home: CupertinoPageScaffold(
child: _splashUI(_size),
),
);
}
我想知道如何在处理数据时保留启动画面,而不是延迟处理启动画面。谢谢。
While the app's splash screen is displayed, it needs to download files from the FTP server and process data. Implemented splash screen for flutter
class Home extends StatelessWidget {
const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(snapshot.connectionState == ConnectionState.waiting)
return SplashUI(); ///Splash Screen
else
return MainUI(); ///Main Screen
},
);
}
}
Now, with a delay of 3 seconds, the startup screen is displayed for 3 seconds, during which time the file is downloaded from FTP and data is processed. I want to keep the splash screen until the completion of data processing rather than the specified time.
Splash Screen
Widget _splashUI(Size size){
return SafeArea(
child: Center(
child: Container(
width: size.width * 0.5,
height: size.height * 0.1,
child: Image(
fit: BoxFit.fill,
image: AssetImage('assets/images/elf_logo.png'),
),
),
),
);
}
Widget build(BuildContext context) {
getFtpFile();
dataProgress();
return Platform.isAndroid ?
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: _splashUI(_size),
),
) :
CupertinoApp(
debugShowCheckedModeBanner: false,
home: CupertinoPageScaffold(
child: _splashUI(_size),
),
);
}
I want to know how to keep SplashScreen while processing data rather than handling SplashScreen with delayed. thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
包 flutter_native_splash 正是您所要求的。
在
runApp()
之前调用FlutterNativeSplash.preserve()
以将启动画面保留在屏幕上,然后调用FlutterNativeSplash.remove();
您的下载完成:全面披露:我维护这个包。
The package flutter_native_splash does exactly what you are asking for.
Make a call to
FlutterNativeSplash.preserve()
before yourrunApp()
to keep the splash on screen, thenFlutterNativeSplash.remove();
when your download completes:Full disclosure: I maintain this package.
为什么不改变延迟呢?
Why not change the delayed?
你可以像其他人过去做过的那样做;您应该使您的方法 getFTPFile 和 dataProgress 返回一个 Future,然后使用 Future.wait 等待这两个 Future强>,如这个答案
https://stackoverflow.com/a/54465973/871364
You could do like other people have done in the past; you should make both of your methods getFTPFile and dataProgress return a Future, then you wait for both Futures using Future.wait, as in this answer
https://stackoverflow.com/a/54465973/871364