我们可以更改其各自文件夹中的Android和ios启动屏幕。是否有用于启动Web的初始屏幕?加载网页之前,我看到一个白色的屏幕。我们该如何改变呢?是启动画面还是加载等待时间?
答案 0 :(得分:1)
由于加载时间的缘故,您现在看到的白屏
我使用启动画面的工作是
我首先在init
方法内部启动启动屏幕
我正在使用计时器,计时器结束后
我正在呼叫另一个页面
main.dart
import 'package:flutter/material.dart';
import 'src/splash_screen.dart';
main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AppName',
theme: ThemeData(
primaryColor: Colors.white,
backgroundColor: Colors.white,
primaryIconTheme: new IconThemeData(color: Colors.black),
),
home: SplashScreen());
}
}
splash_screen.dart
import "package:flutter/material.dart";
import 'dart:async';
import 'login/login.dart';
class SplashScreen extends StatefulWidget {
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
new Timer(new Duration(milliseconds: 1000), () { // set your desired delay time here
Navigator.of(context).pushReplacement(
new MaterialPageRoute(builder: (context) => new LoginScreen()));
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Container(
alignment: Alignment.center,
child: Image.asset(fullLogoPng,
width: MediaQuery.of(context).size.width / 1.5,
fit: BoxFit.scaleDown),
),
);
}
}
答案 1 :(得分:1)
带有动画的Spash屏幕
main.dart
import 'package:flutter/material.dart';
import 'src/splash_screen.dart';
main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.white,
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.purple,
primarySwatch: Colors.purple,
fontFamily: 'FIRSNEUE'),
home: SplashScreen());
}
}
splashScreen.dart
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SplashScreen extends StatefulWidget {
@override
SplashScreenState createState() => new SplashScreenState();
}
class SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
var _visible = true;
AnimationController animationController;
Animation<double> animation;
startTime() async {
var _duration = new Duration(seconds: 3); //SetUp duration here
return new Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.of(context).pushReplacementNamed(HOME_SCREEN);
}
@override
void initState() {
super.initState();
animationController = new AnimationController(
vsync: this, duration: new Duration(seconds: 2));
animation =
new CurvedAnimation(parent: animationController, curve: Curves.easeOut);
animation.addListener(() => this.setState(() {}));
animationController.forward();
setState(() {
_visible = !_visible;
});
startTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 30.0),child:new
Image.asset('assets/img.png',height: 25.0,fit: BoxFit.scaleDown,))
],),
new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.asset(
'assets/logo.png',
width: animation.value * 250,
height: animation.value * 250,
),
],
),
],
),
);
}
}
答案 2 :(得分:1)
这个答案https://stackoverflow.com/a/60019802/9399778进行了解释。它基本上会显示加载屏幕,直到准备好显示主应用为止。不需要任何初始化方法。