这篇文章主要为大家详细介绍了Flutter开发实现底部留言板,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Flutter实现底部留言板的具体代码,供大家参考,具体内容如下
前言
现在大家基本上都会去接触抖音那款app,其中抖音中的留言区域的效果也是要前几天工作的需求,看了网上对这块并没有什么博客介绍。只能自己封装编写了。
主要技术
其实这个技术就是运用了动画这个功能封装实现的
实例代码分析
初始化封装
/*初始化状态*/
initState() {
super.initState();
/*创建动画控制类对象*/
controller = new AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this);
/*创建补间对象*/
tween = new Tween(begin: 0.0, end: 1.0)
.animate(controller) //返回Animation对象
..addListener(() { //添加监听
setState(() {
Provide.value<IndexProvide>(context).changHeight(tween.value);
// print(tween.value); //打印补间插值
});
});
// controller.forward(); //执行动画
}
全部代码
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;
/*初始化状态*/
initState() {
super.initState();
/*创建动画控制类对象*/
controller = new AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this);
/*创建补间对象*/
tween = new Tween(begin: 0.0, end: 1.0)
.animate(controller) //返回Animation对象
..addListener(() { //添加监听
setState(() {
Provide.value<IndexProvide>(context).changHeight(tween.value);
// print(tween.value); //打印补间插值
});
});
// controller.forward(); //执行动画
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
InkWell(
onTap: (){
// 动作反方向执行,即关闭留言板
controller.reverse();
},
child: ListView(
children: <Widget>[
Center(
child: InkWell(
onTap: (){
controller.forward(); //执行动画,即打开留言板
},
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: (){
// 动作反方向执行,即关闭留言板
controller.reverse();
},
child: Icon(Icons.clear),
)
),
Center(
child: Text('留言列表'),
)
],
),
)
),
],
)
);
}
}
现在这个大部分的功能是现在的,不过还是差一个手势的问题。我有一个初步的想法是结合状态管理可以做的,不过有一个bug,就是用手势来改变留言板的高度的时候,动画状态没有初始化。希望知道的小伙伴跟我探讨探讨。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:Flutter开发实现底部留言板


基础教程推荐
猜你喜欢
- Flutter手势密码的实现示例(附demo) 2023-04-11
- Android多返回栈技术 2023-04-15
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- Android中的webview监听每次URL变化实例 2023-01-23
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Flutter绘图组件之CustomPaint使用详解 2023-05-12