dragablegridview_flutter 0.2.5

DragableGridview #

pub package

用GridView编写的可拖动排序View,可任意拖动位置.长按触发拖动,松开手指重新排序,为满足大家的需求,现在增加了“删除动画” ;可能有的人只需要删除动画,而有的人却需要拖动动画,还有的人2个都需要, 我们可以在代码里通过属性来控制使用哪个功能

请不要在拖动的时候更新增加或者删除的数据

A dragable gridview,Long-pressed triggers draggable state,When dragging until covere other items, other Items trigger the animation to make room for the draggable Item,GridView reordering after release your finger,Now I have added "Delete Animation"; some people may only need the delete animation, some people only need the drag animation, and some people need it all. We can control the function by properties.

Please do not update the added data or deleted data while dragging

HomePage:https://github.com/baoolong/DragableGridview

MoreWidght:https://github.com/OpenFlutter/PullToRefresh

Usage #

Add this to your package's pubspec.yaml file:

dependencies:
  dragablegridview_flutter: ^0.2.5
  

Add it to your dart file:

import 'package:dragablegridview_flutter/dragablegridview_flutter.dart';

And GridView dataBin must extends DragAbleGridViewBin ,Add it to your dataBin file

import 'package:dragablegridview_flutter/dragablegridviewbin.dart';

Example #

DataBin example (must extends DragAbleGridViewBin) #

import 'package:dragablegridview_flutter/dragablegridviewbin.dart';

class ItemBin extends DragAbleGridViewBin{

  ItemBin( this.data);

  String data;

  @override
  String toString() {
    return 'ItemBin{data: $data, dragPointX: $dragPointX, dragPointY: $dragPointY, lastTimePositionX: $lastTimePositionX, lastTimePositionY: $lastTimePositionY, containerKey: $containerKey, containerKeyChild: $containerKeyChild, isLongPress: $isLongPress, dragAble: $dragAble}';
  }

}

Widget Usage Example #

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

import 'gridviewitembin.dart';


class DragAbleGridViewDemo extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return new DragAbleGridViewDemoState();
  }
}

class DragAbleGridViewDemoState extends State<DragAbleGridViewDemo>{

  List<ItemBin> itemBins=new List();
  String actionTxtEdit="编辑";
  String actionTxtComplete="完成";
  String actionTxt;
  var editSwitchController=EditSwitchController();
  final List<String> heroes=["鲁班","虞姬","甄姬","黄盖","张飞","关羽","刘备","曹操","赵云","孙策","庄周","廉颇","后裔","妲己","荆轲",];

  @override
  void initState() {
    super.initState();
    actionTxt=actionTxtEdit;
    heroes.forEach((heroName) {
        itemBins.add(new ItemBin(heroName));
      }
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("可拖拽GridView"),
        actions: <Widget>[
          new Center(
              child: new GestureDetector(
                child: new Container(
                  child: new Text(actionTxt,style: TextStyle(fontSize: 19.0),),
                  margin: EdgeInsets.only(right: 12),
                ),
                onTap: (){
                  changeActionState();
                  editSwitchController.editStateChanged();
                },
              )
          )
        ],
      ),
      body: new DragAbleGridView(
        mainAxisSpacing:10.0,
        crossAxisSpacing:10.0,
        childAspectRatio:1.8,
        crossAxisCount: 4,
        itemBins:itemBins,
        editSwitchController:editSwitchController,
        /******************************new parameter*********************************/
        isOpenDragAble: true,
        animationDuration: 300, //milliseconds
        longPressDuration: 800, //milliseconds
        /******************************new parameter*********************************/
        deleteIcon: new Image.asset("images/close.png",width: 15.0 ,height: 15.0 ),
        child: (int position){
          return new Container(
            padding: EdgeInsets.fromLTRB(8.0, 5.0, 8.0, 5.0),
            decoration: new BoxDecoration(
              borderRadius: BorderRadius.all(new Radius.circular(3.0)),
              border: new Border.all(color: Colors.blue),
            ),
            //因为本布局和删除图标同处于一个Stack内,设置marginTop和marginRight能让图标处于合适的位置
            //Because this layout and the delete_Icon are in the same Stack, setting marginTop and marginRight will make the icon in the proper position.
            margin: EdgeInsets.only(top: 6.0,right: 6.0),
            child: new Text(
              itemBins[position].data,
              style: new TextStyle(fontSize: 16.0,color: Colors.blue),),
          );
        },
        editChangeListener: (){
          changeActionState();
        },
      ),
    );
  }

  void changeActionState(){
    if(actionTxt==actionTxtEdit){
      setState(() {
        actionTxt=actionTxtComplete;
      });
    }else{
      setState(() {
        actionTxt=actionTxtEdit;
      });
    }
  }
}

Properties #

propertiestypedefaultsdescription
childtypedef@requiredgridview's child at each position
itemBinsList@requiredthe data to be show by gridview's children
crossAxisCountint4how many children to be show in a row ; 一行显示几个child
crossAxisSpacingdouble1.0cross axis spacing ; 和滑动方向垂直的那个方向上 child之间的空隙
mainAxisSpacingdouble0.0main axis spacing ; 滑动方向child之间的空隙
childAspectRatiodouble0.0child aspect ratio ; child的纵横比
editSwitchControllerclassnullthe switch controller that to trigger editing by clicking the button ; 编辑开关控制器,可通过点击按钮触发编辑
editChangeListenertypedefnullwhen you long press to trigger the edit state, you can listener this state to change the state of the edit button ; 长按触发编辑状态,可监听状态来改变编辑按钮(编辑开关 ,通过按钮触发编辑)的状态
isOpenDragAbleboolfalsewhether to enable the dragable function;是否启用拖动功能
animationDurationint300animation duration;动画持续的时长
longPressDurationint800long press duration;长按触发拖动的时长
deleteIconImagenullDelete button icon,Do not set this property if you do not use the delete function;删除按钮的图标,如果不使用删除功能,不要设置此属性

LICENSE #

MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

[0.2.5] - 2019.05.31

  • add deleteIcon click listener

[0.2.3] - 2019.05.31

  • Fix a bug when deleteIcon is null

[0.2.2] - 2019.05.25

  • Fix the stuck when dragging

[0.2.1] - 2019.05.24

  • Fix some problems that Android 9.0 and above can't use

[0.2.0] - 2019.04.25

  • Repair adsorption effect

[0.1.9] - 2019.04.24

  • Update deleteIcon from Image to Widget

[0.1.8] - 2019.04.23

  • Fix bug

[0.1.7] - 2019.04.23

  • Performance optimization

[0.1.6] - 2019.02.20

  • Reduce parameters

[0.1.5] - 2019.02.18

  • Dragable function is controllable, animation duration is controllable

[0.1.4] - 2019.01.27

  • Optimize code and fix bugs

[0.1.3] - 2019.01.23

  • Add delete item function

[0.1.1] - 2018.10.15

  • Add a detailed description
  • Upgrade version to above 0.1
  • Specification sample code

[0.0.4] - 2018.10.13

  • Modify README description error and format code

[0.0.1] - 2018.09.30

  • Describe initial release.

example/example.dart

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

import 'gridviewitembin.dart';


class DragAbleGridViewDemo extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return new DragAbleGridViewDemoState();
  }
}

class DragAbleGridViewDemoState extends State<DragAbleGridViewDemo>{

  List<ItemBin> itemBins=new List();
  String actionTxtEdit="编辑";
  String actionTxtComplete="完成";
  String actionTxt;
  var editSwitchController=EditSwitchController();
  final List<String> heroes=["鲁班","虞姬","甄姬","黄盖","张飞","关羽","刘备","曹操","赵云","孙策","庄周","廉颇","后裔","妲己","荆轲",];

  @override
  void initState() {
    super.initState();
    actionTxt=actionTxtEdit;
    heroes.forEach((heroName) {
        itemBins.add(new ItemBin(heroName));
      }
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("可拖拽GridView"),
        actions: <Widget>[
          new Center(
              child: new GestureDetector(
                child: new Container(
                  child: new Text(actionTxt,style: TextStyle(fontSize: 19.0),),
                  margin: EdgeInsets.only(right: 12),
                ),
                onTap: (){
                  changeActionState();
                  editSwitchController.editStateChanged();
                },
              )
          )
        ],
      ),
      body: new DragAbleGridView(
        mainAxisSpacing:10.0,
        crossAxisSpacing:10.0,
        childAspectRatio:1.8,
        crossAxisCount: 4,
        itemBins:itemBins,
        editSwitchController:editSwitchController,
        /******************************new parameter*********************************/
        isOpenDragAble: true,
        animationDuration: 300, //milliseconds
        longPressDuration: 800, //milliseconds
        /******************************new parameter*********************************/
        deleteIcon: new Image.asset("images/close.png",width: 15.0 ,height: 15.0 ),
        child: (int position){
          return new Container(
            padding: EdgeInsets.fromLTRB(8.0, 5.0, 8.0, 5.0),
            decoration: new BoxDecoration(
              borderRadius: BorderRadius.all(new Radius.circular(3.0)),
              border: new Border.all(color: Colors.blue),
            ),
            //因为本布局和删除图标同处于一个Stack内,设置marginTop和marginRight能让图标处于合适的位置
            //Because this layout and the delete_Icon are in the same Stack, setting marginTop and marginRight will make the icon in the proper position.
            margin: EdgeInsets.only(top: 6.0,right: 6.0),
            child: new Text(
              itemBins[position].data,
              style: new TextStyle(fontSize: 16.0,color: Colors.blue),),
          );
        },
        editChangeListener: (){
          changeActionState();
        },
      ),
    );
  }

  void changeActionState(){
    if(actionTxt==actionTxtEdit){
      setState(() {
        actionTxt=actionTxtComplete;
      });
    }else{
      setState(() {
        actionTxt=actionTxtEdit;
      });
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dragablegridview_flutter: ^0.2.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dragablegridview_flutter/dragablegridview_flutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jul 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/dragablegridview_flutter.dart.

Run flutter format to format lib/dragablegridview_flutter.dart.

Format lib/dragablegridviewbin.dart.

Run flutter format to format lib/dragablegridviewbin.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test

Admin