網站首頁 編程語言 正文
本文實例為大家分享了Flutter實現底部留言板的具體代碼,供大家參考,具體內容如下
前言
現在大家基本上都會去接觸抖音那款app,其中抖音中的留言區(qū)域的效果也是要前幾天工作的需求,看了網上對這塊并沒有什么博客介紹。只能自己封裝編寫了。
主要技術
其實這個技術就是運用了動畫這個功能封裝實現的
實例代碼分析
初始化封裝
?/*初始化狀態(tài)*/ ? initState() { ? ? super.initState(); ? ? /*創(chuàng)建動畫控制類對象*/ ? ? controller = new AnimationController( ? ? ? ? duration: const Duration(milliseconds: 1000), ? ? ? ? vsync: this); ? ? /*創(chuàng)建補間對象*/ ? ? tween = new Tween(begin: 0.0, end: 1.0) ? ? ? ? .animate(controller) ? ?//返回Animation對象 ? ? ? ..addListener(() { ? ? ? ?//添加監(jiān)聽 ? ? ? ? setState(() { ? ? ? ? ? Provide.value(context).changHeight(tween.value); ? ? ? ? ?// print(tween.value); ? //打印補間插值 ? ? ? ? }); ? ? ? }); ? ? // controller.forward(); ? ? ? //執(zhí)行動畫 ? }
全部代碼
import 'package:flutter/material.dart'; void main(){ ? runApp( ? ? MaterialApp( ? ? ? debugShowCheckedModeBanner: false, ? ? ? home: cityContent(), ? ? ) ? ); } class cityContent extends StatefulWidget { ? cityContent({Key key}) : super(key: key); ? _cityContentState createState() => _cityContentState(); } class _cityContentState extends Statewith SingleTickerProviderStateMixin{ ? Animation tween; ? AnimationController controller; ? /*初始化狀態(tài)*/ ? initState() { ? ? super.initState(); ? ? /*創(chuàng)建動畫控制類對象*/ ? ? controller = new AnimationController( ? ? ? ? duration: const Duration(milliseconds: 1000), ? ? ? ? vsync: this); ? ? /*創(chuàng)建補間對象*/ ? ? tween = new Tween(begin: 0.0, end: 1.0) ? ? ? ? .animate(controller) ? ?//返回Animation對象 ? ? ? ..addListener(() { ? ? ? ?//添加監(jiān)聽 ? ? ? ? setState(() { ? ? ? ? ? Provide.value (context).changHeight(tween.value); ? ? ? ? ?// print(tween.value); ? //打印補間插值 ? ? ? ? }); ? ? ? }); ? ? // controller.forward(); ? ? ? //執(zhí)行動畫 ? } ? @override ? Widget build(BuildContext context) { ? ? return Scaffold( ? ? ? ? body: Stack( ? ? ? ? children: [ ? ? ? ? ? InkWell( ? ? ? ? ? ? ? onTap: (){ ? ? ? ? ? ? ? ? // 動作反方向執(zhí)行,即關閉留言板 ? ? ? ? ? ? ? ? controller.reverse(); ? ? ? ? ? ? ? }, ? ? ? ? ? ? child: ?ListView( ? ? ? ? ? ? ? children: [ ? ? ? ? ? ? ? ? Center( ? ? ? ? ? ? ? ? child: InkWell( ? ? ? ? ? ? ? ? ? onTap: (){ ? ? ? ? ? ? ? ? ? ? controller.forward(); ? ? ? //執(zhí)行動畫,即打開留言板 ? ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? ? child: Text( ? ? ? ? ? ? ? ? ? ? '打開底部抽屜' ? ? ? ? ? ? ? ? ? ), ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ), ? ? ? ? ? ? ? ], ? ? ? ? ? ? ), ? ? ? ? ? ), ? ? ? ? ? Positioned( ? ? ? ? ? ? bottom: 0, ? ? ? ? ? ? child: Container( ? ? ? ? ? ? ? margin: EdgeInsets.fromLTRB(20, 0, 20, 0), ? ? ? ? ? ? ? height: 400*controller.value, ? ? ? ? ? ? ? width: 300, ? ? ? ? ? ? ? color: Colors.grey.shade300, ? ? ? ? ? ? ? child: ListView( ? ? ? ? ? ? ? // physics: NeverScrollableScrollPhysics(), ? ? ? ? ? ? ? children: [ ? ? ? ? ? ? ? ? Container( ? ? ? ? ? ? ? ? ? margin: EdgeInsets.only(left: 240), ? ? ? ? ? ? ? ? ? child: InkWell( ? ? ? ? ? ? ? ? ? ? onTap: (){ ? ? ? ? ? ? ? ? ? ? ? // 動作反方向執(zhí)行,即關閉留言板 ? ? ? ? ? ? ? ? ? ? ? controller.reverse(); ? ? ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? ? ? child: Icon(Icons.clear), ? ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ? ), ? ? ? ? ? ? ? ? Center( ? ? ? ? ? ? ? ? ? child: Text('留言列表'), ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ], ? ? ? ? ? ? ), ? ? ? ? ? ) ? ? ? ? ), ? ? ? ? ], ? ? ? ) ? ? ); ? } }
現在這個大部分的功能是現在的,不過還是差一個手勢的問題。我有一個初步的想法是結合狀態(tài)管理可以做的,不過有一個bug,就是用手勢來改變留言板的高度的時候,動畫狀態(tài)沒有初始化。希望知道的小伙伴跟我探討探討。
原文鏈接:https://blog.csdn.net/qq_35905501/article/details/96476775
相關推薦
- 2022-05-26 pandas進行數據輸入和輸出的方法詳解_python
- 2022-08-07 QT實戰(zhàn)之打開最近文檔功能的實現_C 語言
- 2022-12-06 c++入門必學算法之快速冪思想及實現_C 語言
- 2023-07-03 Python?Thread虛假喚醒概念與防范詳解_python
- 2022-06-08 問題記錄:HttpServletRequestWrapper導致跨域失敗的問題
- 2022-02-21 css 改變input光標顏色
- 2022-03-19 android?Service基礎(啟動服務與綁定服務)_Android
- 2022-11-17 C#實現表格數據轉實體的示例代碼_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支