flutter设置边距,flutter上下左右边距,flutter广告页面,flutter欢迎页,flutter轮播图

直接上图:

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<SplashPageDemo> {
  int _status = 0;
  final List<String> _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
            ? <Widget>[
          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跳过")),
              ))
        ]
            : <Widget>[
          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);
              }
            },
          )
        ]);
    ;
  }
}

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值