dragablegridview_flutter 0.2.5官方demo怎么没法通过右上角的叉删除图标啊??

发布于 2022-09-13 00:09:12 字数 4094 浏览 19 评论 0

官方的demo:
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}';

}

}

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

//import 'gridviewitembin.dart';

void main() => runApp(DragAbleGridViewDemo());

class DragAbleGridViewDemo extends StatefulWidget{
@override
State<StatefulWidget> createState() => 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));
  }
);

}

deleteicon(String value){

setState(() {
  this.itemBins.remove(value);
});

}

@override
Widget build(BuildContext context) {

return MaterialApp(
  //debugShowCheckedModeBanner: false,  可以删除右上角的debug图标  
  home: 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();
              //点击编辑,itemBins右上角出现删除图标;点击完成,itemBins右上角删除图标消失               
              editSwitchController.editStateChanged();
              //deleteicon(value);
            },
          )
      )
    ],
  ),
  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("assets/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;
  });
}

}
}

我怎么都没法删除啊????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文