300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 17-flutter导航栏渐变效果

17-flutter导航栏渐变效果

时间:2023-04-04 06:12:16

相关推荐

17-flutter导航栏渐变效果

MediaQuery.removePadding 移除顶部的 padding

import 'package:flutter/material.dart';// 导入swiper 组件import 'package:flutter_swiper/flutter_swiper.dart';const APPBAR_SCROLL_OFFSET = 200;class HomePage extends StatefulWidget{// 重写Create State 方法@override_HomePageState createState() => _HomePageState();}class _HomePageState extends State<HomePage>{//定义一个AppBar 的透明度默认值double appBarAlpha = 0;List _imgUrls = ['/-12-05/12584425541_2.jpg','/1129/4155754_234055006000_2.jpg','http://b-/uploads/item/12/25/1225204152_aYEc3.jpeg'];@override Widget build(BuildContext context) {return Scaffold(// MediaQuery.removePadding 移除顶部的 padding// 使用Stack 的作用就是让AppBar 叠加在上面body: Stack(children: <Widget>[MediaQuery.removePadding(removeTop: true,context: context,// 监听列表的滚动child: NotificationListener(// 滚动的回调onNotification: (scrollNotifation){// 判断ListView滚动的效果if (scrollNotifation is ScrollUpdateNotification && scrollNotifation.depth == 0){// 滚动且是列表滚动的的的时候double offset = scrollNotifation.metrics.pixels;print(offset);double alpha = offset / APPBAR_SCROLL_OFFSET;if(alpha < 0){alpha = 0;}else if (alpha > 0){alpha = 1;}setState(() {appBarAlpha = alpha;});print(alpha);}}, child: ListView(children: <Widget>[Column(children: <Widget>[Container(height: 160,// child:Swiper(itemCount: _imgUrls.length,autoplay: true,itemBuilder: (BuildContext context,int index){// 获取图片return work(_imgUrls[index],// 适配方式fit: BoxFit.fill,);},// 添加一个页码指示器pagination: SwiperPagination(),),),Container(height: 800,child: ListTile(title: Text("Nice"),),)],),],),),),// 创建AppBarOpacity(// 当列表滚动的时候 改变其透明度的值opacity: appBarAlpha,child: Container(height: 80,decoration: BoxDecoration(color: Colors.white),child: Center(child: Padding(padding: EdgeInsets.only(top: 20),child: Text('首页'),),),),)],));}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。