
Flutter顶部滑动渐变
发布日期:2021-10-10 05:30:59
浏览次数:9
分类:技术文章
本文共 2538 字,大约阅读时间需要 8 分钟。
顶部滑动渐变 和 顶部导航 ```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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.191.171.38]2022年12月07日 11时54分51秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
最新文章
构建自己的C/C++插件开发框架(四)——核心层设计和实现
2019-07-31 22:59:27
构建自己的C/C++插件开发框架(三)——总体结构
2019-07-31 22:59:26
构建自己的C/C++插件开发框架(二)——总体功能
2019-07-31 22:59:26
构建自己的C/C++插件开发框架(一)——初步设想
2019-07-31 22:59:25
linux下C++ 插件(plugin)实现技术
2019-07-31 22:59:25
UNIX下C++实现动态载入对象
2019-07-31 22:59:25
轻量级C++插件框架 x3py 可以用了
2019-07-31 22:59:24
Qt插件机制的学习
2019-07-31 22:59:24
Qt 插件学习(二)
2019-07-31 22:59:23
Qt 插件学习(一)
2019-07-31 22:59:23
QT中插件分析
2019-07-31 22:59:22
qt 实现单例
2019-07-31 22:59:22
软件架构模式-读书笔记(5)-基于空间的架构
2019-07-31 22:59:21
软件架构模式-读书笔记(4)-微服务架构
2019-07-31 22:59:21
软件架构模式-读书笔记(3)-微内核架构
2019-07-31 22:59:20
软件架构模式-读书笔记(2)-事件驱动架构
2019-07-31 22:59:20
软件架构模式-读书笔记(1)-分层架构
2019-07-31 22:59:19
架构师都需要了解的康威定律(Konway‘s Law)
2019-07-31 22:59:19
开源JSON库Rapidjson与cJSON对比
2019-07-31 22:59:18
Docker Image,Container,Repository的概念理解
2019-07-31 22:59:18