flutter 中使用flutter_slidable 实现左滑显示删除、修改菜单,仿微信

news/2024/7/24 2:26:17 标签: flutter, 微信, javascript
flutter pub add flutter_slidable

导入

import 'package:flutter_slidable/flutter_slidable.dart';

使用

import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Slidable Example',
      home: Scaffold(
        body: ListView(
          children: [
            Slidable(
              // Specify a key if the Slidable is dismissible.
              key: const ValueKey(0),

              // The start action pane is the one at the left or the top side.
              startActionPane: ActionPane(
                // A motion is a widget used to control how the pane animates.
                motion: const ScrollMotion(),

                // A pane can dismiss the Slidable.
                dismissible: DismissiblePane(onDismissed: () {}),

                // All actions are defined in the children parameter.
                children: const [
                  // A SlidableAction can have an icon and/or a label.
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFFFE4A49),
                    foregroundColor: Colors.white,
                    icon: Icons.delete,
                    label: 'Delete',
                  ),
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF21B7CA),
                    foregroundColor: Colors.white,
                    icon: Icons.share,
                    label: 'Share',
                  ),
                ],
              ),

              // The end action pane is the one at the right or the bottom side.
              endActionPane: const ActionPane(
                motion: ScrollMotion(),
                children: [
                  SlidableAction(
                    // An action can be bigger than the others.
                    flex: 2,
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF7BC043),
                    foregroundColor: Colors.white,
                    icon: Icons.archive,
                    label: 'Archive',
                  ),
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF0392CF),
                    foregroundColor: Colors.white,
                    icon: Icons.save,
                    label: 'Save',
                  ),
                ],
              ),

              // The child of the Slidable is what the user sees when the
              // component is not dragged.
              child: const ListTile(title: Text('Slide me')),
            ),
            Slidable(
              // Specify a key if the Slidable is dismissible.
              key: const ValueKey(1),

              // The start action pane is the one at the left or the top side.
              startActionPane: const ActionPane(
                // A motion is a widget used to control how the pane animates.
                motion: ScrollMotion(),

                // All actions are defined in the children parameter.
                children: [
                  // A SlidableAction can have an icon and/or a label.
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFFFE4A49),
                    foregroundColor: Colors.white,
                    icon: Icons.delete,
                    label: 'Delete',
                  ),
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF21B7CA),
                    foregroundColor: Colors.white,
                    icon: Icons.share,
                    label: 'Share',
                  ),
                ],
              ),

              // The end action pane is the one at the right or the bottom side.
              endActionPane: ActionPane(
                motion: const ScrollMotion(),
                dismissible: DismissiblePane(onDismissed: () {}),
                children: const [
                  SlidableAction(
                    // An action can be bigger than the others.
                    flex: 2,
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF7BC043),
                    foregroundColor: Colors.white,
                    icon: Icons.archive,
                    label: 'Archive',
                  ),
                  SlidableAction(
                    onPressed: doNothing,
                    backgroundColor: Color(0xFF0392CF),
                    foregroundColor: Colors.white,
                    icon: Icons.save,
                    label: 'Save',
                  ),
                ],
              ),

              // The child of the Slidable is what the user sees when the
              // component is not dragged.
              child: const ListTile(title: Text('Slide me')),
            ),
          ],
        ),
      ),
    );
  }
}

void doNothing(BuildContext context) {}

ActionPane的参数说明

ActionPane(
                    key: Key(UniqueKey().toString()),
                    extentRatio:0.2,
                    // 滑动动效
                    // DrawerMotion() StretchMotion()
                    // motion: ScrollMotion(),
                    motion: BehindMotion(),
                    children: const [
                      // SlidableAction(
                      //   // An action can be bigger than the others.
                      //   flex: 2,
                      //   onPressed: doNothing,
                      //   backgroundColor: Color(0xFF7BC043),
                      //   foregroundColor: Colors.white,
                      //   icon: Icons.archive,
                      //   label: 'Archive',
                      // ),
                      SlidableAction(
                        onPressed: doNothing,
                        backgroundColor: Color(0xFF0392CF),
                        foregroundColor: Colors.white,
                        icon: Icons.save,
                        label: 'Save',
                      ),
                    ],
                  ),

http://www.niftyadmin.cn/n/5339573.html

相关文章

面试高频知识点:1集合 1.1HashSet集合的特点

HashSet(哈希集合)是Java集合框架中的一种实现Set接口的类,它具有以下特点: 无序性: HashSet不保证元素的顺序,即元素在集合中的存储顺序与它们的插入顺序无关。这是因为HashSet使用哈希表来存储元素&#…

华为网络设备常用命令大全

♥️作者:小刘在C站 ♥️个人主页: 小刘主页 ♥️不能因为人生的道路坎坷,就使自己的身躯变得弯曲;不能因为生活的历程漫长,就使求索的 脚步迟缓。 ♥️学习两年总结出的运维经验,以及思科模拟器全套网络实验教程。专栏:云计算技…

OpenGL API 变换 纹理

learnOpenGL里面讲变换,其变换本身没有任何问题。唯一的问题在于纹理坐标没有跟着变换。 预期有差异,就来挖坑。 GPT给出解释: OpenGL的变换操作通常是应用于顶点而不是纹理坐标。这是因为变换的目标是将3D模型从模型空间转换到屏幕空间&a…

网络安全产品之认识入侵防御系统

由于网络安全威胁的不断演变和增长。随着网络技术的不断发展和普及,网络攻击的种类和数量也在不断增加,给企业和个人带来了巨大的安全风险。传统的防火墙、入侵检测防护体系等安全产品在面对这些威胁时,存在一定的局限性和不足,无…

2024年华为OD机试真题-素数之积-Java-OD统一考试(C卷)

题目描述: RSA加密算法在网络安全世界中无处不在,它利用了极大整数因数分解的困难度,数据越大,安全系数越高,给定一个32位正整数,请对其进行因数分解,找出是哪两个素数的乘积。 输入描述: 一个正整数num 0 < num <= 2147483647 输出描述: 如果成功找到,以单个空…

mysql中MyISAM和InnoDB的区别是什么

InnoDB&#xff1a;MySQL默认的事务型引擎&#xff0c;也是最重要和使用最广泛的存储引擎。它被设计为大量的短期事务&#xff0c;短期事务大部分情况下是正常提交的&#xff0c;很少被回滚。InnoDB的性能与自动崩溃恢复的特性&#xff0c;使得它在非事务存储需求中也很流行。除…

MySQL——第一章 MySQL基础1

第一章 MySQL基础1 1.1 启动1.2关闭1.3与客户端进行连接 1.1 启动 net start mysql80 1.2关闭 net stop mysql80 1.3与客户端进行连接 mysql -u root -p MySQL下载及安装 MySQL社区版

conda修改默认环境安装位置

conda修改默认环境安装位置 文章目录 conda修改默认环境安装位置查看conda配置信息创建.condarc&#xff08;conda runtime controlling)配置文件没有.condarc怎么办 即使创建正确放置了.condarc创建环境时还是默认指定C盘目录写权限目录修改权限 查看conda配置信息 conda con…