广告
返回顶部
首页 > 资讯 > 移动开发 >Flutter开发实现底部留言板
  • 137
分享到

Flutter开发实现底部留言板

2024-04-02 19:04:59 137人浏览 安东尼
摘要

本文实例为大家分享了Flutter实现底部留言板的具体代码,供大家参考,具体内容如下 前言 现在大家基本上都会去接触抖音那款app,其中抖音中的留言区域的效果也是要前几天工作的需求,

本文实例为大家分享了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,就是用手势来改变留言板的高度的时候,动画状态没有初始化。希望知道的小伙伴跟我探讨探讨。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Flutter开发实现底部留言板

本文链接: https://www.lsjlt.com/news/143643.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作