Flutter開發(fā)實現(xiàn)底部留言板
本文實例為大家分享了Flutter實現(xiàn)底部留言板的具體代碼,供大家參考,具體內(nèi)容如下
前言
現(xiàn)在大家基本上都會去接觸抖音那款app,其中抖音中的留言區(qū)域的效果也是要前幾天工作的需求,看了網(wǎng)上對這塊并沒有什么博客介紹。只能自己封裝編寫了。
主要技術(shù)
其實這個技術(shù)就是運用了動畫這個功能封裝實現(xiàn)的
實例代碼分析
初始化封裝
?/*初始化狀態(tài)*/ ? initState() { ? ? super.initState(); ? ? /*創(chuàng)建動畫控制類對象*/ ? ? controller = new AnimationController( ? ? ? ? duration: const Duration(milliseconds: 1000), ? ? ? ? vsync: this); ? ? /*創(chuàng)建補(bǔ)間對象*/ ? ? tween = new Tween(begin: 0.0, end: 1.0) ? ? ? ? .animate(controller) ? ?//返回Animation對象 ? ? ? ..addListener(() { ? ? ? ?//添加監(jiān)聽 ? ? ? ? setState(() { ? ? ? ? ? Provide.value<IndexProvide>(context).changHeight(tween.value); ? ? ? ? ?// print(tween.value); ? //打印補(bǔ)間插值 ? ? ? ? }); ? ? ? }); ? ? // 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 State<cityContent> with SingleTickerProviderStateMixin{ ? Animation<double> tween; ? AnimationController controller; ? /*初始化狀態(tài)*/ ? initState() { ? ? super.initState(); ? ? /*創(chuàng)建動畫控制類對象*/ ? ? controller = new AnimationController( ? ? ? ? duration: const Duration(milliseconds: 1000), ? ? ? ? vsync: this); ? ? /*創(chuàng)建補(bǔ)間對象*/ ? ? tween = new Tween(begin: 0.0, end: 1.0) ? ? ? ? .animate(controller) ? ?//返回Animation對象 ? ? ? ..addListener(() { ? ? ? ?//添加監(jiān)聽 ? ? ? ? setState(() { ? ? ? ? ? Provide.value<IndexProvide>(context).changHeight(tween.value); ? ? ? ? ?// print(tween.value); ? //打印補(bǔ)間插值 ? ? ? ? }); ? ? ? }); ? ? // controller.forward(); ? ? ? //執(zhí)行動畫 ? } ? @override ? Widget build(BuildContext context) { ? ? return Scaffold( ? ? ? ? body: Stack( ? ? ? ? children: <Widget>[ ? ? ? ? ? InkWell( ? ? ? ? ? ? ? onTap: (){ ? ? ? ? ? ? ? ? // 動作反方向執(zhí)行,即關(guān)閉留言板 ? ? ? ? ? ? ? ? controller.reverse(); ? ? ? ? ? ? ? }, ? ? ? ? ? ? child: ?ListView( ? ? ? ? ? ? ? children: <Widget>[ ? ? ? ? ? ? ? ? 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: <Widget>[ ? ? ? ? ? ? ? ? Container( ? ? ? ? ? ? ? ? ? margin: EdgeInsets.only(left: 240), ? ? ? ? ? ? ? ? ? child: InkWell( ? ? ? ? ? ? ? ? ? ? onTap: (){ ? ? ? ? ? ? ? ? ? ? ? // 動作反方向執(zhí)行,即關(guān)閉留言板 ? ? ? ? ? ? ? ? ? ? ? controller.reverse(); ? ? ? ? ? ? ? ? ? ? }, ? ? ? ? ? ? ? ? ? ? child: Icon(Icons.clear), ? ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ? ), ? ? ? ? ? ? ? ? Center( ? ? ? ? ? ? ? ? ? child: Text('留言列表'), ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? ? ], ? ? ? ? ? ? ), ? ? ? ? ? ) ? ? ? ? ), ? ? ? ? ], ? ? ? ) ? ? ); ? } }
現(xiàn)在這個大部分的功能是現(xiàn)在的,不過還是差一個手勢的問題。我有一個初步的想法是結(jié)合狀態(tài)管理可以做的,不過有一個bug,就是用手勢來改變留言板的高度的時候,動畫狀態(tài)沒有初始化。希望知道的小伙伴跟我探討探討。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android進(jìn)階之從IO到NIO的模型機(jī)制演進(jìn)
這篇文章主要為大家介紹了Android進(jìn)階之從IO到NIO的模型機(jī)制演進(jìn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android RecyclerView四級緩存源碼層詳細(xì)分析
RecyclerView是Android一個更強(qiáng)大的控件,其不僅可以實現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實現(xiàn)數(shù)據(jù)縱向滾動,也可以實現(xiàn)橫向滾動(ListView做不到橫向滾動)。接下來講解RecyclerView的用法2022-11-11Android開發(fā)中Activity的生命周期及加載模式詳解
這篇文章主要介紹了Android開發(fā)中Activity的生命周期及加載模式詳解的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-05-05OnSharedPreferenceChangeListener詳解及出現(xiàn)不觸發(fā)解決辦法
本文主要介紹 Android OnSharedPreferenceChangeListener的知識,在Android應(yīng)用開發(fā)過程中會遇到監(jiān)聽器不觸發(fā)事件問題,這里介紹了相應(yīng)的解決辦法2016-08-08簡析Android五大布局(LinearLayout、FrameLayout、RelativeLayout等)
這篇文章主要為大家簡單分析了Android五大布局,內(nèi)容有LinearLayout、FrameLayout、RelativeLayout、AbsoluteLayout和TableLayout的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-06-06