栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

flutter(1) 启动页 引导页

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

flutter(1) 启动页 引导页

flutter 启动页 引导页

Android 原生引导页面的方法如下

1 自定义 使用 ViewPager控件

2使用第三方 组建AppIntro AppIntro快速启动页面

flutter  引导页面的方式

1使用 pageView  (指示器需要自定义)

2使用TabBarView,指示器TabPageSelector

代码如下可以直接使用。

启动页面

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State {
  int index = 4;
  late Timer _timer;
 bool isFrist=true;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _timer = new Timer.periodic(Duration(seconds: 1), (timer) {
      setState(() {
        if (index > 0) {
          index--;
        } else {
          //跳转到引导页面
           
          Get.to(new GuidePage());

          index = 0;
          timer.cancel();
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Image.asset(
            "images/logo.png",
            fit: BoxFit.fill,
            width: double.infinity,
            height: double.infinity,
          ),
          Positioned(
              top: 40,
              right: 20,
              child: Container(
                width: 50,
                height: 27,
                alignment: Alignment.center,
                decoration: BoxDecoration(color: Colors.amber,borderRadius: BorderRadius.circular(40) ),
                child: Text("${index}"),
              ))
        ],
      ),
    );
  }
}

引导页面

class GuidePage extends StatefulWidget {
  @override
  _GuidePageState createState() => _GuidePageState();
}

class _GuidePageState extends State
    with SingleTickerProviderStateMixin {
  late PageController _pageController;
  bool isVisible = true;
  TabController? _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _pageController = new PageController();
    _tabController = new TabController(initialIndex: 0, length: 3, vsync: this);
    _tabController?.addListener(() {
      if (_tabController?.index == 2) {
        setState(() {
          isVisible = false;
        });
      } else {
        setState(() {
          isVisible = true;
        });
      }

    });
  }

  final List listImage = [
    Image.asset(
      "images/a.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),
    Image.asset(
      "images/b.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),
    Image.asset(
      "images/c.png",
      fit: BoxFit.fill,
      width: double.infinity,
      height: double.infinity,
    ),

  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          TabBarView(
            controller: _tabController,
            children: [
              listImage[0],
              listImage[1],
              Stack(
                children: [
                  listImage[2],
                  Container(
                    margin: EdgeInsets.only(bottom: 80),
                    child: Align(
                      alignment: Alignment.bottomCenter,
                      child: InkWell(
                        onTap: (){
                          //跳转去======mian
                        },
                        child: Container(
                          width: 150,
                          height: 40,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: Colors.amber,
                              borderRadius: BorderRadius.circular(40)),
                          child: Text("欢迎使用App"),
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ],
          ),
          Visibility(
              visible: isVisible,
              child: Container(
                margin: EdgeInsets.only(bottom: 40),
                child: Align(
                  alignment: Alignment.bottomCenter,
                  child: TabPageSelector(
                    controller: _tabController,
                    selectedColor: Colors.amberAccent,
                    indicatorSize: 17,
                    color: Colors.black12,
                  ),
                ),
              ))
        ],
      ),
    );
  }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/602589.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号