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#串口通讯实现数据的发送和接收

《如何使用C#串口通讯实现数据的发送和接收》本文详细介绍了如何使用C#实现基于串口通讯的数据发送和接收,通过SerialPort类,我们可以轻松实现串口通讯,并结合事件机制实现数据的传递和处理,感兴趣... 目录1. 概述2. 关键技术点2.1 SerialPort类2.2 异步接收数据2.3 数据解析2.

详解如何使用Python提取视频文件中的音频

《详解如何使用Python提取视频文件中的音频》在多媒体处理中,有时我们需要从视频文件中提取音频,本文为大家整理了几种使用Python编程语言提取视频文件中的音频的方法,大家可以根据需要进行选择... 目录引言代码部分方法扩展引言在多媒体处理中,有时我们需要从视频文件中提取音频,以便进一步处理或分析。本文

mybatis-plus 实现查询表名动态修改的示例代码

《mybatis-plus实现查询表名动态修改的示例代码》通过MyBatis-Plus实现表名的动态替换,根据配置或入参选择不同的表,本文主要介绍了mybatis-plus实现查询表名动态修改的示... 目录实现数据库初始化依赖包配置读取类设置 myBATis-plus 插件测试通过 mybatis-plu

使用Dify访问mysql数据库详细代码示例

《使用Dify访问mysql数据库详细代码示例》:本文主要介绍使用Dify访问mysql数据库的相关资料,并详细讲解了如何在本地搭建数据库访问服务,使用ngrok暴露到公网,并创建知识库、数据库访... 1、在本地搭建数据库访问的服务,并使用ngrok暴露到公网。#sql_tools.pyfrom

Qt把文件夹从A移动到B的实现示例

《Qt把文件夹从A移动到B的实现示例》本文主要介绍了Qt把文件夹从A移动到B的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录如何移动一个文件? 如何移动文件夹(包含里面的全部内容):如何删除文件夹:QT 文件复制,移动(

Flask 验证码自动生成的实现示例

《Flask验证码自动生成的实现示例》本文主要介绍了Flask验证码自动生成的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习... 目录生成图片以及结果处理验证码蓝图html页面展示想必验证码大家都有所了解,但是可以自己定义图片验证码

VSCode配置Anaconda Python环境的实现

《VSCode配置AnacondaPython环境的实现》VisualStudioCode中可以使用Anaconda环境进行Python开发,本文主要介绍了VSCode配置AnacondaPytho... 目录前言一、安装 Visual Studio Code 和 Anaconda二、创建或激活 conda

使用mvn deploy命令上传jar包的实现

《使用mvndeploy命令上传jar包的实现》本文介绍了使用mvndeploy:deploy-file命令将本地仓库中的JAR包重新发布到Maven私服,文中通过示例代码介绍的非常详细,对大家的学... 目录一、背景二、环境三、配置nexus上传账号四、执行deploy命令上传包1. 首先需要把本地仓中要

JAVA封装多线程实现的方式及原理

《JAVA封装多线程实现的方式及原理》:本文主要介绍Java中封装多线程的原理和常见方式,通过封装可以简化多线程的使用,提高安全性,并增强代码的可维护性和可扩展性,需要的朋友可以参考下... 目录前言一、封装的目标二、常见的封装方式及原理总结前言在 Java 中,封装多线程的原理主要围绕着将多线程相关的操

MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固 通俗易懂版)

《MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固通俗易懂版)》本文主要讲解了MySQL中的多表查询,包括子查询、笛卡尔积、自连接、多表查询的实现方法以及多列子查询等,通过实际例子和操... 目录复合查询1. 回顾查询基本操作group by 分组having1. 显示部门号为10的部门名,员