Flutter顶部滑动渐变
发布日期:2021-10-10 05:30:59
浏览次数:27
分类:技术文章
本文共 3072 字,大约阅读时间需要 10 分钟。
顶部滑动渐变 和 顶部导航 ```pythonimport 'package:flutter/material.dart';import 'package:flutter_swiper/flutter_swiper.dart';import 'package:flutter_screenutil/flutter_screenutil.dart';const APPBAR_SCORLL_OFFSET =100;class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState();}class _HomePageState extends State{ List _imageUrls = [ 'https://qnwww2.autoimg.cn/newsdfs/g26/M09/39/1A/autohomecar__ChsEnF3LyfyAPLEOAAPPcEtAcsc635.jpg', 'https://img2.autoimg.cn/admdfs/g1/M04/0C/D7/ChsEmV236AWAeVxxAADNmEFdNug314.jpg', 'https://qnwww2.autoimg.cn/newsdfs/g25/M03/94/0C/autohomecar__ChsEel3Lcj6Ab6fcAAXx3D2fNSg287.jpg', 'https://qnwww2.autoimg.cn/newsdfs/g1/M09/4F/91/autohomecar__ChsEj13LyA6AVsDHAAexjI07sWo824.jpg' ]; // 定义透明度的变量 double appBarAlpha = 0; _onScroll(offset) { double alpha = offset/APPBAR_SCORLL_OFFSET; if(alpha<0){ alpha = 0; }else if(alpha > 1){ alpha = 1; } setState(() { appBarAlpha = alpha; }); } @override Widget build(BuildContext context) { ScreenUtil.instance = ScreenUtil(width: 750,height: 1334)..init(context); return Scaffold( body: Stack( children: [ MediaQuery.removePadding( removeTop: true, context: context, child: NotificationListener( onNotification: (scrollNotification) { if (scrollNotification is ScrollUpdateNotification && scrollNotification.depth == 0) { // 滚动且列表滚动的时候 _onScroll(scrollNotification.metrics.pixels); } }, child: ListView( children: [ Container( /** * 在需要的页面使用 屏幕适配 */ width: ScreenUtil().setWidth(750), height: ScreenUtil().setHeight(400), child: Swiper( itemCount: _imageUrls.length, autoplay: true, itemBuilder: (BuildContext context, int index) { return Image.network( _imageUrls[index], fit: BoxFit.cover, ); }, pagination: SwiperPagination(), ), ), Container( height: 800.0, child: ListTile( title: Text('哈哈'), ), ) ], ), )), Opacity( opacity:appBarAlpha, child: Container( height: 60, decoration: BoxDecoration( color: Colors.white ), child: Center( child: Padding( padding: EdgeInsets.only(top:20), child: Text('首页'), ), ), ), ) ], )); }}
转载地址:https://blog.csdn.net/qq_22049619/article/details/103160189 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月14日 15时35分03秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Unity中的UI方案(基础版)
2019-04-27
Lua(一)——Lua介绍
2019-04-27
Lua(二)——环境安装
2019-04-27
Unity中父子物体的坑
2019-04-27
基础知识——进位制
2019-04-27
Lua(十二)——表
2019-04-27
Lua(十三)——模块与包
2019-04-27
Lua(四)——变量
2019-04-27
Lua(十四)——元表
2019-04-27
Lua(十五)——协同程序
2019-04-27
Lua(十六)——文件
2019-04-27
Lua(十七)——面向对象
2019-04-27
Lua(十八)——错误处理,垃圾回收
2019-04-27
xLua(一)——介绍
2019-04-27
xLua(二)——下载
2019-04-27
xLua(三)——在C#中访问Lua代码
2019-04-27
xLua(四)——C#访问Lua的基本类型
2019-04-27
xLua(五)——C#访问Lua的table
2019-04-27
xLua(六)——C#访问Lua的function
2019-04-27
基础知识——常用单位介绍
2019-04-27