直接上图:
1、设置边距主要代码为 new EdgeInsets.fromLTRB(0, 50, 10, 0) LTRB上下左右,可以查看EdgeInsets源码。
2、悬浮按钮代码
Align(
alignment: FractionalOffset.topRight,
child: Padding(
padding: new EdgeInsets.fromLTRB(0, 50, 10, 0),
child: FlatButton(
onPressed: () {
_goLogin(true);
},
textTheme: ButtonTextTheme.normal,
textColor: Colors.green,
disabledTextColor: Colors.red,
color: Color(0xFF82B1FF),
disabledColor: Colors.grey,
highlightColor: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20))),
child: Text(_countdownTime.toString() + "s跳过")),
))
3、相关依赖
# Flutter 轮播图 https://github.com/best-flutter/flutter_swiper
flutter_swiper: ^1.1.6
# 侧滑删除 https://github.com/letsar/flutter_slidable
flutter_slidable: ^0.5.4
# Toast插件 https://github.com/OpenFlutter/flutter_oktoast
oktoast: ^2.3.2
4、整个页面代码
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_deer/util/toast.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class SplashPageDemo extends StatefulWidget {
@override
_SplashPageState createState() => _SplashPageState();
}
class _SplashPageState extends State {
int _status = 0;
final List _guideList = [
'app_start_1.png',
'app_start_2.png',
'app_start_3.png'
];
Timer _timer;
int _countdownTime = 5;
@override
void initState() {
super.initState();
_initSplash();
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
void _initGuide() {
setState(() {
_status = 1;
});
}
void _initSplash() {
const oneSec = const Duration(seconds: 1);
var callback = (timer) =>
{
setState(() {
if (_countdownTime < 1) {
_timer.cancel();
//自己判断 是欢迎页还是主页
_initGuide();
} else {
_countdownTime = _countdownTime - 1;
}
})
};
_timer = Timer.periodic(oneSec, callback);
}
void _goLogin(stopTimer) {
if (stopTimer) {
_timer.cancel();
}
Toast.show('go go go');
}
@override
Widget build(BuildContext context) {
return new Stack(
alignment: const FractionalOffset(0.5, 0.7),
children: _status == 0
? [
FractionallyAlignedSizedBox(
child: Image.asset(
"assets/images/app_start_1.png",
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
/// 忽略图片语义
excludeFromSemantics: true,
)),
Align(
alignment: FractionalOffset.topRight,
child: Padding(
padding: new EdgeInsets.fromLTRB(0, 50, 10, 0),
child: FlatButton(
onPressed: () {
_goLogin(true);
},
textTheme: ButtonTextTheme.normal,
textColor: Colors.green,
disabledTextColor: Colors.red,
color: Color(0xFF82B1FF),
disabledColor: Colors.grey,
highlightColor: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(20))),
child: Text(_countdownTime.toString() + "s跳过")),
))
]
: [
Swiper(
key: const Key('swiper'),
itemCount: _guideList.length,
loop: false,
itemBuilder: (_, index) {
return Image.asset(
"assets/images/" + _guideList[index],
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
/// 忽略图片语义
excludeFromSemantics: true,
);
},
onTap: (index) {
if (index == _guideList.length - 1) {
_goLogin(false);
}
},
)
]);
;
}
}