flutter 拖拽布局_Flutter 史上最牛拖动控件 Draggable

不多说,我们肯定遇到过这个需求:

把一个控件从当前位置移动到另一个位置。可能需求最多的就像是支付宝应用页面的编辑:

比如,我想把最近使用的 红包 添加到 我的应用 当中,支付宝这里是用的 + 号。

那如果产品说我就想让它拖过去,这可咋整?

不慌,Flutter 也为我们提供了相关的 Widget。

Draggable

Flutter 如果要实现这种效果,那么非 Draggable 不可。

照例我们查看官方文档。

A widget that can be dragged from to a DragTarget.

可拖动到 DragTarget 的小部件。

复制代码

那也就是说,除了 Draggable ,还有一个 DragTarget。

DragTarget 是用来接收我们拖过去的 Widget 的,我们后面再说。

先说Draggable。

在官方文档找了一圈没发现Demo,那没办法了,直接开撸。

先看构造函数:

class Draggable extends StatefulWidget{

/// Createsawidget that can be dragged toa[DragTarget].

///

/// The [child] and [feedback] arguments must not be null. If

/// [maxSimultaneousDrags] is non-null, it must be non-negative.

const Draggable({

Key key,

@required this.child,

@required this.feedback,

this.data,

this.axis,

this.childWhenDragging,

this.feedbackOffset = Offset.zero,

this.dragAnchor = DragAnchor.child,

this.affinity,

this.maxSimultaneousDrags,

this.onDragStarted,

this.onDraggableCanceled,

this.onDragEnd,

this.onDragCompleted,

this.ignoringFeedbackSemantics = true,

}) : assert(child != null),

assert(feedback != null),

assert(ignoringFeedbackSeman

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter Zoomable Image 是一个用于 Flutter 应用程序的库,它提供了一个可缩放和拖动的图像小部件。使用 Flutter Zoomable Image,您可以轻松地实现图像的缩放、拖动和捏放手势操作。这对于创建具有可交互性的图像查看器和画廊等应用程序非常有用。 要使用 Flutter Zoomable Image,您需要在项目的 `pubspec.yaml` 文件中添加依赖项,并运行 `flutter packages get` 命令来获取库。 以下是一个简单的示例代码,演示了如何在 Flutter 中使用 Zoomable Image: ```dart import 'package:flutter/material.dart'; import 'package:flutter_zoomable_image/flutter_zoomable_image.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Zoomable Image Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Zoomable Image Demo'), ), body: Center( child: ZoomableImage( AssetImage('path/to/your/image.jpg'), placeholder: Center(child: CircularProgressIndicator()), backgroundColor: Colors.black, ), ), ); } } ``` 在上面的示例中,我们创建了一个简单的 Flutter 应用程序,其中包含一个使用 ZoomableImage 小部件的页面。ZoomableImage 接受一个 AssetImage 对象作为图像源,并提供了一些可选参数,例如 placeholder(用于在图像加载期间显示的小部件)和 backgroundColor(用于设置图像背景色)。 您可以根据自己的需求定制 Zoomable Image 的样式和行为。要了解更多关于 Flutter Zoomable Image 的信息和用法,请参考官方文档或库的 GitHub 页面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值