创建一个flutter的左划重命名,右划隐藏的功能

首先定义一下参数,以及左划右划的方法

double deleteButtonPosition = -120;
  double renameButtonPosition = -120;

  void _onHorizontalDragUpdate(DragUpdateDetails details) {
    setState(() {
      if (details.delta.dx < 0) {
        // 左滑
        deleteButtonPosition = 0; // 显示删除按钮
        renameButtonPosition = 80; // 显示重命名按钮
      } else if (details.delta.dx > 0) {
        // 右滑
        deleteButtonPosition = -120; // 隐藏删除按钮
        renameButtonPosition = -160; // 隐藏重命名按钮
      }
    });
  }

然后再在Widget中加入布局以及方法调用

onHorizontalDragUpdate: _onHorizontalDragUpdate,


AnimatedPositioned(
              duration: const Duration(milliseconds: 200),
              right: deleteButtonPosition,
              child: InkWell(
                onTap: () {
                  _showRenameDialog(context, widget.onRename, widget.index);
                },
                child: Container(
                  height: 100,
                  width: 100,
                  // color: Color.fromARGB(255, 106, 106, 106), // 添加背景颜色
                  alignment: Alignment.center,
                  decoration: const BoxDecoration(
                    color: Color.fromARGB(255, 106, 106, 106), // 添加背景颜色
                    borderRadius: BorderRadius.only(
                      topRight: Radius.circular(10),
                      bottomRight: Radius.circular(10),
                    ),
                  ),
                  child: const Text(
                    'Rename',
                    style: TextStyle(color: Colors.white, fontSize: 16),
                  ),
                ),
              ),
            ),

最近更新

  1. PHP String manipulation: A comprehensive guide

    2024-04-15 06:20:03       0 阅读
  2. Qt5 Ubuntu18 QStackedWidget

    2024-04-15 06:20:03       0 阅读
  3. WebKit源代码探秘:深入理解其组织结构与组件

    2024-04-15 06:20:03       1 阅读
  4. 【回溯+双指针算法题记录】回文字符串汇总

    2024-04-15 06:20:03       1 阅读
  5. 2288. 价格减免

    2024-04-15 06:20:03       1 阅读
  6. Quartz 介绍

    2024-04-15 06:20:03       1 阅读
  7. Taro自定义实现本地路径转换为文件

    2024-04-15 06:20:03       1 阅读
  8. Python 类与对象:深入理解与应用

    2024-04-15 06:20:03       0 阅读

热门阅读

  1. 熟悉JVM体系结构

    2024-04-15 06:20:03       16 阅读
  2. 4.JVM八股

    2024-04-15 06:20:03       16 阅读
  3. LearnOpenGl练习题-纹理

    2024-04-15 06:20:03       16 阅读
  4. Android DB锁问题

    2024-04-15 06:20:03       19 阅读
  5. 赚钱游戏 2.0.1 版 (资源免费)

    2024-04-15 06:20:03       16 阅读
  6. 【面试八股文之Linux系统编程】

    2024-04-15 06:20:03       38 阅读
  7. [蓝桥杯 2018 省 A] 付账问题

    2024-04-15 06:20:03       19 阅读
  8. C语言经典例题(3)

    2024-04-15 06:20:03       18 阅读