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

本文主要是介绍flutter 中使用flutter_slidable 实现左滑显示删除、修改菜单,仿微信,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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);@overrideWidget 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',),],),

实现只有同时只有一个滑块

SlidableAutoCloseBehavior 包住listview部分代码就可以

          body:SlidableAutoCloseBehavior(child: ListView.builder(controller: _scrollController,//需要controller ,不然异常itemCount: datas.length,key: Key(UniqueKey().toString()),itemBuilder: (BuildContext context, int index) { return Slidable(// 禁用滑动enabled:true,dragStartBehavior:DragStartBehavior.start,// key:  ValueKey(index), // 设置只能有一个滑块key: Key(UniqueKey().toString()),// 右滑滑动显示的菜单// startActionPane: ActionPane(//   key: Key(UniqueKey().toString()),//   // A motion is a widget used to control how the pane animates.//   motion: const ScrollMotion(),//   // A pane can dismiss the Slidable.//   dismissible: DismissiblePane(onDismissed: () {//     print("点击了");//   }),//   // 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',//     ),//   ],// ),//左滑划出的菜单endActionPane:  ActionPane(key: Key(UniqueKey().toString()),// 菜单宽度extentRatio:0.2,dragDismissible:false,// 滑动动效// 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',),],),child: ListTile(title: Text('Slide me')),);},),)

这篇关于flutter 中使用flutter_slidable 实现左滑显示删除、修改菜单,仿微信的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/638130

相关文章

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令