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

相关文章

C#实现将Excel表格转换为图片(JPG/ PNG)

《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

Java使用ANTLR4对Lua脚本语法校验详解

《Java使用ANTLR4对Lua脚本语法校验详解》ANTLR是一个强大的解析器生成器,用于读取、处理、执行或翻译结构化文本或二进制文件,下面就跟随小编一起看看Java如何使用ANTLR4对Lua脚本... 目录什么是ANTLR?第一个例子ANTLR4 的工作流程Lua脚本语法校验准备一个Lua Gramm

Java Optional的使用技巧与最佳实践

《JavaOptional的使用技巧与最佳实践》在Java中,Optional是用于优雅处理null的容器类,其核心目标是显式提醒开发者处理空值场景,避免NullPointerExce... 目录一、Optional 的核心用途二、使用技巧与最佳实践三、常见误区与反模式四、替代方案与扩展五、总结在 Java

基于Java实现回调监听工具类

《基于Java实现回调监听工具类》这篇文章主要为大家详细介绍了如何基于Java实现一个回调监听工具类,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录监听接口类 Listenable实际用法打印结果首先,会用到 函数式接口 Consumer, 通过这个可以解耦回调方法,下面先写一个

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QGroupBox控件的实现

《Qt中QGroupBox控件的实现》QGroupBox是Qt框架中一个非常有用的控件,它主要用于组织和管理一组相关的控件,本文主要介绍了Qt中QGroupBox控件的实现,具有一定的参考价值,感兴趣... 目录引言一、基本属性二、常用方法2.1 构造函数 2.2 设置标题2.3 设置复选框模式2.4 是否

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法

《springboot整合阿里云百炼DeepSeek实现sse流式打印的操作方法》:本文主要介绍springboot整合阿里云百炼DeepSeek实现sse流式打印,本文给大家介绍的非常详细,对大... 目录1.开通阿里云百炼,获取到key2.新建SpringBoot项目3.工具类4.启动类5.测试类6.测

pytorch自动求梯度autograd的实现

《pytorch自动求梯度autograd的实现》autograd是一个自动微分引擎,它可以自动计算张量的梯度,本文主要介绍了pytorch自动求梯度autograd的实现,具有一定的参考价值,感兴趣... autograd是pytorch构建神经网络的核心。在 PyTorch 中,结合以下代码例子,当你