IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> flutter 底部滑动抽屉(短视频评论) -> 正文阅读

[移动开发]flutter 底部滑动抽屉(短视频评论)

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
? const MyApp({Key? key}) : super(key: key);

? static const String _title = 'Flutter Code Sample';

? @override
? Widget build(BuildContext context) {
? ? return const MaterialApp(
? ? ? title: _title,
? ? ? home: MyStatefulWidget(),
? ? );
? }
}

class MyStatefulWidget extends StatefulWidget {
? const MyStatefulWidget({Key? key}) : super(key: key);

? @override
? State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget>
? ? with TickerProviderStateMixin {
? late final AnimationController _controller = AnimationController(
? ? duration: const Duration(seconds: 10),
? ? vsync: this,
? );

? final VelocityTracker _vt =
? ? ? VelocityTracker.withKind(PointerDeviceKind.touch); //手速控制

? //最大高度
? double maxHeight = 700;
? //最小高度
? double minHeight = 100;
? @override
? void dispose() {
? ? _controller.dispose();
? ? super.dispose();
? }

? @override
? Widget build(BuildContext context) {
? ? return Scaffold(body: LayoutBuilder(
? ? ? builder: (BuildContext context, BoxConstraints constraints) {
? ? ? ? return Container(
? ? ? ? ? ? height: constraints.maxHeight,
? ? ? ? ? ? width: constraints.maxWidth,
? ? ? ? ? ? child: Stack(
? ? ? ? ? ? ? children: [
? ? ? ? ? ? ? ? Positioned(
? ? ? ? ? ? ? ? ? left: 0,
? ? ? ? ? ? ? ? ? // top: 0,
? ? ? ? ? ? ? ? ? right: 0,
? ? ? ? ? ? ? ? ? bottom: 0,
? ? ? ? ? ? ? ? ? child: Listener(
? ? ? ? ? ? ? ? ? ? onPointerDown: (PointerDownEvent p) =>
? ? ? ? ? ? ? ? ? ? ? ? _vt.addPosition(p.timeStamp, p.position),
? ? ? ? ? ? ? ? ? ? onPointerMove: (PointerMoveEvent p) {
? ? ? ? ? ? ? ? ? ? ? _vt.addPosition(p.timeStamp,
? ? ? ? ? ? ? ? ? ? ? ? ? p.position); // add current position for velocity tracking
? ? ? ? ? ? ? ? ? ? ? _onGestureSlide(p.delta.dy);
? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? onPointerUp: (PointerUpEvent p) =>
? ? ? ? ? ? ? ? ? ? ? ? _onGestureEnd(_vt.getVelocity()),
? ? ? ? ? ? ? ? ? ? child: AnimatedBuilder(
? ? ? ? ? ? ? ? ? ? ? animation: _controller,
? ? ? ? ? ? ? ? ? ? ? builder: (BuildContext context, Widget? child) {
? ? ? ? ? ? ? ? ? ? ? ? return Container(
? ? ? ? ? ? ? ? ? ? ? ? ? height: _controller.value * (maxHeight - minHeight) +
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? minHeight,
? ? ? ? ? ? ? ? ? ? ? ? ? color: Colors.purple,
? ? ? ? ? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? ? ),
? ? ? ? ? ? ? ? )
? ? ? ? ? ? ? ],
? ? ? ? ? ? ));
? ? ? },
? ? ));
? }

? void _onGestureSlide(double dy) {
? ? _controller.value -= dy / (maxHeight - minHeight); //滑动距离 ?跟高度差值的比例值
? }

? void _onGestureEnd(Velocity v) {
? ? double minFlingVelocity = 365.0;

? ? if (_controller.isAnimating) return;

? ? double visualVelocity =
? ? ? ? -v.pixelsPerSecond.dy / (maxHeight - minHeight); //判断下滑还是上滑

? ? //这是速度很大时候
? ? if (v.pixelsPerSecond.dy.abs() >= minFlingVelocity) {
? ? ? if (visualVelocity > 0) {
? ? ? ? _controller.value = 1; //如果是
? ? ? } else {
? ? ? ? _controller.value = 0;
? ? ? }

? ? ? return;
? ? }

? ? // 检查控制器是否已经在一半的位置
? ? if (_controller.value >= 0.5) {
? ? ? _controller.value = 1;
? ? } else {
? ? ? _controller.value = 0;
? ? }
? }
}

这个思路由??sliding_up_panel? 这个插件而来。需要的朋友可以选择这个插件,很不错的

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-10-22 21:26:57  更:2022-10-22 21:27:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/20 3:26:19-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码