waterfall_flow
a flutter grid view easy to build waterfall flow layout quickly.
use
- add library to your pubspec.yaml
dependencies:
waterfall_flow: any
- import library in dart file
import 'package:waterfall_flow/waterfall_flow.dart';
easy to use
you can define waterfall flow layout within sliverwaterfallflowdelegate.
parameter | description | default |
---|---|---|
crossaxiscount | the number of children in the cross axis. | required |
mainaxisspacing | the number of logical pixels between each child along the main axis. | 0.0 |
crossaxisspacing | the number of logical pixels between each child along the cross axis. | 0.0 |
collectgarbage | call when collect garbage, return indexs to collect | – |
lastchildlayouttypebuilder | the builder to get layout type of last child ,notice: it should only for last child | – |
viewportbuilder | the builder to get indexs in viewport | – |
closetotrailing | whether make layout close to trailing | false |
waterfallflow.builder(
//cacheextent: 0.0,
padding: edgeinsets.all(5.0),
griddelegate: sliverwaterfallflowdelegate(
crossaxiscount: 2,
crossaxisspacing: 5.0,
mainaxisspacing: 5.0,
/// follow max child trailing layout offset and layout with full cross axis extend
/// last child as loadmore item/no more item in [gridview] and [waterfallflow]
/// with full cross axis extend
// lastchildlayouttype.fullcrossaxisextend,
/// as foot at trailing and layout with full cross axis extend
/// show no more item at trailing when children are not full of viewport
/// if children is full of viewport, it's the same as fullcrossaxisextend
// lastchildlayouttype.foot,
lastchildlayouttypebuilder: (index) => index == _list.length
? lastchildlayouttype.foot
: lastchildlayouttype.none,
),
collectgarbage
track the indexes are collect, you can collect garbage at that monment(for example image cache)
waterfallflow.builder(
griddelegate: sliverwaterfallflowdelegate(
collectgarbage: (list<int> garbages) {
///collectgarbage
garbages.foreach((index) {
final provider = extendednetworkimageprovider(
_list[index].imageurl,
);
provider.evict();
});
},
),
viewportbuilder
track the indexes go into the viewport, it’s not include cache extent.
waterfallflow.builder(
griddelegate: sliverwaterfallflowdelegate(
viewportbuilder: (int firstindex, int lastindex) {
print("viewport : [$firstindex,$lastindex]");
}),
lastchildlayouttypebuilder
build lastchild as special child in the case that it is loadmore/no more item.
enum lastchildlayouttype {
/// as default child
none,
/// follow max child trailing layout offset and layout with full cross axis extend
/// last child as loadmore item/no more item in [extendedgridview] and [waterfallflow]
/// with full cross axis extend
fullcrossaxisextend,
/// as foot at trailing and layout with full cross axis extend
/// show no more item at trailing when children are not full of viewport
/// if children is full of viewport, it's the same as fullcrossaxisextend
foot,
}
waterfallflow.builder(
griddelegate: sliverwaterfallflowdelegate(
lastchildlayouttypebuilder: (index) => index == length
? lastchildlayouttype.foot
: lastchildlayouttype.none,
),
closetotrailing
when reverse property of list is true, layout is as following.
it likes chat list, and new session will insert to zero index.
but it’s not right when items are not full of viewport.
trailing
-----------------
| |
| |
| item2 |
| item1 |
| item0 |
-----------------
leading
to solve it, you could set closetotrailing to true, layout is as following.
support [extendedgridview],[extendedlist],[waterfallflow].
and it also works when reverse is flase, layout will close to trailing.
trailing
-----------------
| item2 |
| item1 |
| item0 |
| |
| |
-----------------
leading
waterfallflow.builder(
reverse: true,
griddelegate: sliverwaterfallflowdelegate(closetotrailing: true),
Comments are closed.