drag_select_grid_view
a gr,id that supports both dragging and tapping to select its items.
basic usage
first of all, dragselectg,ridview
constructor is very similar to gridview.builder
, so you should take your time to understand the latter before diving into this library.
once you are familiar with gridview.builder
, probably the only additional piece of information you’ll need is dragselectgri,dviewcontroller
. with it, you’re able to know which indexes are selected.
check this example:
class myapp extends statefulwidget {
@override
_myappstate createstate() => _myappstate();
}
class _myappstate extends state<myapp> {
final controller = dragselectgr,idviewcontroller();
@override
void initstate() {
super.initstate();
controller.addlistener(schedulerebuild);
}
@override
void dispose() {
controller.removelistener(schedulerebuild);
super.dispose();
}
@override
widget build(buildcontext context) {
return scaffold(
appbar: selectionappbar(
selection: controller.selection,
),
body: dragselectgri,dview(
gr,idcontroller: controller,
itemcount: 20,
itembuilder: (context, index, selected) {
return selectableitem(
index: index,
selected: selected,
);
},
g,riddelegate: slivergr,iddelegatewithmaxcrossaxisextent(
maxcrossaxisextent: 80,
),
),
);
}
void schedulerebuild() => setstate(() {});
}
as you may have noticed in the code above, dragselectg,ridview
must be used along two other widgets in order to provide a proper user experience. in the example, they are:
selectableitem
: a selectable widget, which is going to visually indicate whether the item is selected or not.selectionappbar
: a customappbar
, which shows the amount of selected items and an option to unselect them.
the example project provides some samples of those widgets. i won’t add them to the library, since they are unrelated to the ,grid itself, but feel free to copy them into your project, as long as you respect the license terms.
advanced usage
you can use the setter dragselectgridviewcontroller.selection
to directly change the selection (i’m not quite sure why you’d need this, but i don’t ask questions).
it allows this sort of interaction:
you can check the code here.
there are some other minor settings you can do to make dragselectgridview
fit your needs, like dragselectgridview.autoscrollhotspotheight
and dragselectgridview.unselectonwillpop
. those features are well documented, so i’ll let you take your discovery time.
hopefully, this is everything you need to know to use this library.
Comments are closed.