首页 技术 正文
技术 2022年11月11日
0 收藏 988 点赞 4,006 浏览 3389 个字

更多代码参考

有短暂的白屏时间

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '启动图demo',
debugShowCheckedModeBanner: false,
home: AnimatedSplashScreen(
home: HomePage(),
),
);
}
}class AnimatedSplashScreen extends StatefulWidget {
final Widget home; const AnimatedSplashScreen({Key key, @required this.home}) : super(key: key);
@override
SplashScreenState createState() => new SplashScreenState();
}class SplashScreenState extends State<AnimatedSplashScreen>
with SingleTickerProviderStateMixin {
AnimationController animationController;
Animation<double> animation;
Duration keepTimer = Duration(seconds: 3);
int get showSecond => keepTimer.inSeconds;
Timer timer;
bool isSkip = false; startTime() async {
await Future.delayed(keepTimer);
_toHome();
} _toHome() {
if (isSkip) return;
isSkip = true;
Navigator.of(context)
.pushReplacement(MaterialPageRoute(builder: (context) => widget.home));
} @override
void initState() {
super.initState();
animationController =
AnimationController(vsync: this, duration: Duration(seconds: 2));
animation =
CurvedAnimation(parent: animationController, curve: Curves.easeOut); animation.addListener(() => this.setState(() {}));
animationController.forward();
// startTime();
Duration step = Duration(seconds: 1);
timer = Timer.periodic(Duration(seconds: 1), (_) {
setState(() {
keepTimer -= step;
});
if (keepTimer == Duration.zero) {
timer.cancel();
}
});
} @override
void dispose() {
animationController?.dispose();
timer?.cancel();
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
super.dispose();
} @override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Positioned(
right: 10,
bottom: 50,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: FlatButton(
color: Colors.grey[300],
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
onPressed: _toHome,
child: Text('跳过 $showSecond'),
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 30.0),
child: Image.asset(
'assets/images/powered_by.png',
height: 25.0,
fit: BoxFit.scaleDown,
))
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
'assets/images/logo.png',
width: animation.value * 250,
height: animation.value * 250,
),
],
),
],
),
);
}
}class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: RaisedButton(
child: Text('data'),
onPressed: () async {},
),
),
);
}
}

配置xml

λ flutter --version
Flutter 1.12.17-pre.61 • channel master • https://github.com/flutter/flutter.git
Framework • revision 1c7a1c3873 (4 hours ago) • 2019-12-04 07:51:54 +0100
Engine • revision 3e6d6bc612
Tools • Dart 2.7.0 (build 2.7.0-dev.2.1 19fc1016da)
  1. 添加启动图 android\app\src\main\res\drawable\bg.png

  2. 修改android\app\src\main\res\drawable\launch_background.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/holo_blue_light" /> <!-- You can insert your own image assets here 删除下面的注释 -->
<item>
<bitmap
android:gravity="center"
android:src="@drawable/bg" />
</item>
</layer-list>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290