美文网首页
Flutter实战一(框架,轮播图,自定义AppBars滚动渐变

Flutter实战一(框架,轮播图,自定义AppBars滚动渐变

作者: 景小帮 | 来源:发表于2021-02-16 15:37 被阅读0次

目录:

1.APP首页框架搭建

2.侧滑抽屉效果 drawer

3.轮播图Banner功能开发

4.自定义AppBar实现滚动渐变

使用到的框架:在pubspec.yaml进行配置

#  Toast 打印

  toast: ^0.1.5

#  网络请求组件

  dio: ^3.0.10

#  轮播图组建

  flutter_swiper: ^1.1.6

重点总结:

底部导航栏:BottomNavigationBar

侧滑动抽屉效果:drawer

轮播图:Swiper

ListView 滚动监听:NotificationListener

删除掉顶部导航栏:MediaQuery.removePadding

透明度:opacity

框架搭建:

图片

TabNavigator:框架页面

import 'package:flutter/material.dart';

import 'package:flutter_app1/module/mine/pages/MinePage.dart';

import 'package:flutter_app1/module/search/pages/SearchPage.dart';

import 'package:flutter_app1/module/travel/TravelPage.dart';

import 'package:flutter_app1/module/home/pages/HomePage.dart';

class TabNavigatorextends StatefulWidget {

@override

  _NavigatorStatecreateState() =>_NavigatorState();

}

class _NavigatorStateextends State {

intcurrentIndex =0;

  final _defultColor = Colors.black;

  final _activeColor = Colors.blue;

  Listlist = [

HomePage(),

    SearchPage(),

    TravelPage(),

    MinePage(),

  ];

  @override

  Widgetbuild(BuildContext context) {

return Scaffold(

body:this.list[this.currentIndex],

      bottomNavigationBar:BottomNavigationBar(

currentIndex:this.currentIndex,

        iconSize:25,

        type: BottomNavigationBarType.fixed,

        onTap: (index){

setState(() {

this.currentIndex=index;

          });

        },

        items: [

BottomNavigationBarItem(

icon:Icon(

Icons.home,

                color:_defultColor,

              ),

              activeIcon:Icon(

Icons.home,

                color:_activeColor,

              ),

              title:Text(

"首页",

                style:TextStyle(

color:currentIndex!=0 ?_defultColor:_activeColor

                ),

              )

),

          BottomNavigationBarItem(

icon:Icon(

Icons.search,

                color:_defultColor,

              ),

              activeIcon:Icon(

Icons.search,

                color:_activeColor,

              ),

              title:Text(

"搜索",

                style:TextStyle(

color:currentIndex!=1 ?_defultColor:_activeColor

                ),

              )

),

          BottomNavigationBarItem(

icon:Icon(

Icons.camera_alt,

                color:_defultColor,

              ),

              activeIcon:Icon(

Icons.camera_alt,

                color:_activeColor,

              ),

              title:Text(

"旅拍",

                style:TextStyle(

color:currentIndex!=2 ?_defultColor:_activeColor

                ),

              )

),

          BottomNavigationBarItem(

icon:Icon(

Icons.account_circle,

                color:_defultColor,

              ),

              activeIcon:Icon(

Icons.account_circle,

                color:_activeColor,

              ),

              title:Text(

"我的",

                style:TextStyle(

color:currentIndex!=3 ?_defultColor:_activeColor

                ),

              )

),

        ],

      ),

      drawer:Drawer(

child:ListView(

padding: EdgeInsets.zero,

          children: [

DrawerHeader(

child:Text("Drawer Header"),

              decoration:BoxDecoration(

color: Colors.blue,

              ),

            ),

            ListTile(

title:Text("item 1"),

              onTap: (){

Navigator.pop(context);

              },

            ),

            ListTile(

title:Text("item 2"),

              onTap: (){

Navigator.pop(context);

              },

            )

],

        ),

      ),

    );

  }

}

HomePage:

import 'package:flutter/material.dart';

import 'package:flutter_swiper/flutter_swiper.dart';

const APPBAR_SCROLLOW_OFFSET =100;

class HomePageextends StatefulWidget {

@override

  _HomePageStatecreateState() =>_HomePageState();

}

class _HomePageStateextends State {

final _imageUrl = [

"https://gss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=e9873bfca944ad342eea8f81e09220cc/a8ec8a13632762d08fa73daea8ec08fa513dc602.jpg",

    "https://gss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=e9873bfca944ad342eea8f81e09220cc/a8ec8a13632762d08fa73daea8ec08fa513dc602.jpg",

    "https://gss0.baidu.com/94o3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=e9873bfca944ad342eea8f81e09220cc/a8ec8a13632762d08fa73daea8ec08fa513dc602.jpg",

  ];

  doubleappBarAlpha =0;

  _onScroll(offset){

double alpha = offset/APPBAR_SCROLLOW_OFFSET;

    if(alpha<0){

alpha =0;

    }else if(alpha>1){

alpha =1;

    }

setState(() {

appBarAlpha = alpha;

    });

    print(appBarAlpha);

  }

@override

  Widgetbuild(BuildContext context) {

return Scaffold(

body:Stack(

children: [

MediaQuery.removePadding(//删除掉顶部导航栏

            removeTop:true,

            context: context,

            child:NotificationListener(//滑动监听所有的类

// ignore: missing_return

              onNotification:(scrollNotification){

if(scrollNotificationis ScrollUpdateNotification && scrollNotification.depth ==0){

_onScroll(scrollNotification.metrics.pixels);

                }

},

              child:ListView(

children: [

Container(

height:160,

                    child:Swiper(

itemCount:_imageUrl.length,

                      autoplay:true,

                      itemBuilder: (BuildContext context, int index) {

return Image.network(

_imageUrl[index],

                          fit: BoxFit.fill,

                        );

                      },

                      pagination:SwiperPagination(),//指示器

                    ),

                  ),

                  Container(

height:800,

                    child:ListTile(

title:Text("哈哈哈"),

                    ),

                  )

],

              ),

            ),

          ),

          Opacity(

opacity:appBarAlpha,//改变appBar的透明度

            child:Container(

height:80,

              decoration:BoxDecoration(color: Colors.white),

              child:Center(

child:Padding(

padding:EdgeInsets.only(top:20),

                  child:Text("首页"),

                ),

              ),

            ),

          )

],

      ),

    );

  }

}

相关文章

  • Flutter实战一(框架,轮播图,自定义AppBars滚动渐变

    目录: 1.APP首页框架搭建 2.侧滑抽屉效果drawer 3.轮播图Banner功能开发 4.自定义AppBa...

  • Flutter 自定义AppBar实现滚动渐变

    通过 Flutter 携程网实战项目,实现自定义AppBar实现滚动渐变。 项目地址 效果如下: 代码实现(注意注释):

  • Slider - 轮播图

    简介: 用react开发的轮播图组件,支持淡入淡出、水平滚动、垂直滚动的无缝轮播效果。可自定义轮播内容。 API ...

  • 5.首页轮播图

    轮播图框架(GitHub搜索)flutter_swiper : ^1.1.6 静态轮播图 根据网络请求数据动态加载轮播图

  • Flutter学习六之实现一个带筛选的列表页面

    上期实现了一个网络轮播图的效果,自定义了一个轮播图组件,继承自StatefulWidget,我们知道Flutter...

  • 自定义View实战-仿京东首页轮播文字(又名垂直跑马灯)

    自定义View实战-仿京东首页轮播文字(又名垂直跑马灯) 京东客户端的轮播文字效果: 本次要实现的只是后面滚动的文...

  • 无标题文章

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。它们各具特色,各有用处。 1.传统轮播图 第一步...

  • 轮播图

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。 1.传统轮播图 第一步,得到元素 第二步,设置...

  • 原生JS实现轮播(上)

    这是前阵子写的2款原生JS轮播,一个是渐变轮播预览,一个是滚动轮播预览,现在补充博文总结。 渐变轮播 因为是梳理自...

  • Flutter实现Text渐变

    Flutter实现Text渐变 首先展示效果图image.png 自定义GradientText Widget(直...

网友评论

      本文标题:Flutter实战一(框架,轮播图,自定义AppBars滚动渐变

      本文链接:https://www.haomeiwen.com/subject/lysytltx.html