我做了一个GridView
ontap,我可以显示网格项目。通过双击。我可以删除一个网格。现在我想添加可重新排序的属性。
这是我的代码:
//import 'dart:html';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
int treenumber = 7;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Garden",
home: new Home(),
theme: new ThemeData(primaryColor: Colors.deepOrange),
);
}
}
class Home extends StatefulWidget {
_Homesatate createState() => new _Homesatate();
}
class Tree {
String name;
bool visible;
Tree(this.name, this.visible);
}
class _Homesatate extends State<Home> {
var trees = [
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true),
Tree('mango', true),
Tree('apple', true)
];
@override
Widget build(BuildContext context) {
var gridview = new GridView.builder(
itemCount: trees.length,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: treenumber),
itemBuilder: (BuildContext context, int index) {
return new GestureDetector(
child: new Visibility(
visible: trees[index].visible,
child: new Card(
elevation: 2.0,
child: new Container(
alignment: Alignment.center,
margin: new EdgeInsets.all(2.0),
child: new Text(trees[index].name),
),
),
),
onTap: () {
showDialog(
builder: (context) => new CupertinoAlertDialog(
title: new Column(
children: <Widget>[
new Text("Tree"),
new Icon(
Icons.favorite,
color: Colors.red,
)
],
),
content: new Text(trees[index].name),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("Ok"))
],
),
barrierDismissible: false,
context: context);
},
onDoubleTap: () => setState(() {
trees[index].visible = !trees[index].visible;
}),
);
},
);
return new Scaffold(
appBar: new AppBar(
title: new Text("Garden"),
),
body: gridview,
);
}
}
void main(List<String> args) {
runApp(MyApp());
}
通过长按网格,我可以在任何地方替换它。将重新排序其他网格。
我尝试了几种方法。但是,这不包括我的 ontap 和 doubletap 功能。
如何保留这些属性并且还想添加可重新排序的网格?