您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
342 行
12 KiB
342 行
12 KiB
using System.Collections.Generic;
|
|
using Unity.UIWidgets.foundation;
|
|
using Unity.UIWidgets.painting;
|
|
using Unity.UIWidgets.widgets;
|
|
|
|
public class StaggeredGridView : BoxScrollView
|
|
{
|
|
private StaggeredGridView(
|
|
SliverStaggeredGridDelegate gridDelegate,
|
|
SliverChildDelegate childrenDelegate,
|
|
Key key,
|
|
Axis scrollDirection,
|
|
bool reverse,
|
|
ScrollController controller,
|
|
bool? primary,
|
|
ScrollPhysics physics,
|
|
bool shrinkWrap,
|
|
EdgeInsetsGeometry padding
|
|
// string restorationId
|
|
) : base(
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId
|
|
)
|
|
{
|
|
this.gridDelegate = gridDelegate;
|
|
this.childrenDelegate = childrenDelegate;
|
|
}
|
|
|
|
public static StaggeredGridView New(
|
|
SliverStaggeredGridDelegate gridDelegate,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true,
|
|
List<Widget> children = null //public <Widget>[],
|
|
// string restorationId = null
|
|
)
|
|
{
|
|
var childrenDelegate = new SliverChildListDelegate(
|
|
children ?? new List<Widget>(),
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId
|
|
);
|
|
}
|
|
|
|
public static StaggeredGridView builder(
|
|
SliverStaggeredGridDelegate gridDelegate,
|
|
IndexedWidgetBuilder itemBuilder,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
int? itemCount = null,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true,
|
|
string restorationId = null
|
|
)
|
|
{
|
|
var childrenDelegate = new SliverChildBuilderDelegate(
|
|
itemBuilder,
|
|
childCount: itemCount,
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: (SliverChildDelegate) childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId
|
|
);
|
|
}
|
|
|
|
|
|
public StaggeredGridView custom(
|
|
SliverStaggeredGridDelegate gridDelegate,
|
|
SliverChildDelegate childrenDelegate,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null
|
|
// string restorationId = null
|
|
)
|
|
{
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId,
|
|
);
|
|
}
|
|
|
|
public static StaggeredGridView count(
|
|
int crossAxisCount,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
float mainAxisSpacing = 0.0f,
|
|
float crossAxisSpacing = 0.0f,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true,
|
|
List<Widget> children = null, // public <Widget>[],
|
|
List<StaggeredTile> staggeredTiles = null // public <StaggeredTile>[],
|
|
// String? restorationId,
|
|
)
|
|
{
|
|
children = children ?? new List<Widget>();
|
|
staggeredTiles = staggeredTiles ?? new List<StaggeredTile>();
|
|
var gridDelegate = new SliverStaggeredGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: crossAxisCount,
|
|
mainAxisSpacing: mainAxisSpacing,
|
|
crossAxisSpacing: crossAxisSpacing,
|
|
staggeredTileBuilder: (i) => staggeredTiles[i],
|
|
staggeredTileCount: staggeredTiles.Count
|
|
);
|
|
var childrenDelegate = new SliverChildListDelegate(
|
|
children,
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId,
|
|
);
|
|
}
|
|
|
|
public static StaggeredGridView countBuilder(
|
|
int crossAxisCount,
|
|
IndexedWidgetBuilder itemBuilder,
|
|
GridUtil.IndexedStaggeredTileBuilder staggeredTileBuilder,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
int? itemCount = null,
|
|
float mainAxisSpacing = 0.0f,
|
|
float crossAxisSpacing = 0.0f,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true
|
|
// String? restorationId,
|
|
)
|
|
{
|
|
var gridDelegate = new SliverStaggeredGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: crossAxisCount,
|
|
mainAxisSpacing: mainAxisSpacing,
|
|
crossAxisSpacing: crossAxisSpacing,
|
|
staggeredTileBuilder: staggeredTileBuilder,
|
|
staggeredTileCount: itemCount
|
|
);
|
|
var childrenDelegate = new SliverChildBuilderDelegate(
|
|
itemBuilder,
|
|
childCount: itemCount,
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId,
|
|
);
|
|
}
|
|
|
|
public static StaggeredGridView extent(
|
|
float maxCrossAxisExtent,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
float mainAxisSpacing = 0.0f,
|
|
float crossAxisSpacing = 0.0f,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true,
|
|
List<Widget> children = null, // public <Widget>[],
|
|
List<StaggeredTile> staggeredTiles = null // public <StaggeredTile>[],
|
|
// String? restorationId,
|
|
)
|
|
{
|
|
var gridDelegate = new SliverStaggeredGridDelegateWithMaxCrossAxisExtent(
|
|
maxCrossAxisExtent: maxCrossAxisExtent,
|
|
mainAxisSpacing: mainAxisSpacing,
|
|
crossAxisSpacing: crossAxisSpacing,
|
|
staggeredTileBuilder: (i) => staggeredTiles[i],
|
|
staggeredTileCount: staggeredTiles.Count
|
|
);
|
|
var childrenDelegate = new SliverChildListDelegate(
|
|
children,
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId,
|
|
);
|
|
}
|
|
|
|
public static StaggeredGridView extentBuilder(
|
|
float maxCrossAxisExtent,
|
|
IndexedWidgetBuilder itemBuilder,
|
|
GridUtil.IndexedStaggeredTileBuilder staggeredTileBuilder,
|
|
Key key = null,
|
|
Axis scrollDirection = Axis.vertical,
|
|
bool reverse = false,
|
|
ScrollController controller = null,
|
|
bool? primary = null,
|
|
ScrollPhysics physics = null,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = null,
|
|
int? itemCount = null,
|
|
float mainAxisSpacing = 0.0f,
|
|
float crossAxisSpacing = 0.0f,
|
|
bool addAutomaticKeepAlives = true,
|
|
bool addRepaintBoundaries = true
|
|
// String? restorationId = null,
|
|
)
|
|
{
|
|
var gridDelegate = new SliverStaggeredGridDelegateWithMaxCrossAxisExtent(
|
|
maxCrossAxisExtent: maxCrossAxisExtent,
|
|
mainAxisSpacing: mainAxisSpacing,
|
|
crossAxisSpacing: crossAxisSpacing,
|
|
staggeredTileBuilder: staggeredTileBuilder,
|
|
staggeredTileCount: itemCount
|
|
);
|
|
var childrenDelegate = new SliverChildBuilderDelegate(
|
|
itemBuilder,
|
|
childCount: itemCount,
|
|
addAutomaticKeepAlives: addAutomaticKeepAlives,
|
|
addRepaintBoundaries: addRepaintBoundaries
|
|
);
|
|
return new StaggeredGridView(
|
|
gridDelegate: gridDelegate,
|
|
childrenDelegate: childrenDelegate,
|
|
key: key,
|
|
scrollDirection: scrollDirection,
|
|
reverse: reverse,
|
|
controller: controller,
|
|
primary: primary,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
padding: padding
|
|
// restorationId: restorationId,
|
|
);
|
|
}
|
|
|
|
public readonly SliverStaggeredGridDelegate gridDelegate;
|
|
|
|
public readonly SliverChildDelegate childrenDelegate;
|
|
|
|
protected override Widget buildChildLayout(BuildContext context)
|
|
{
|
|
return new SliverStaggeredGrid(
|
|
Delegate: childrenDelegate,
|
|
gridDelegate: gridDelegate
|
|
);
|
|
}
|
|
}
|