Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildDefaultDragHandles #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,31 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.15.0"
reorderable_grid:
dependency: "direct main"
description:
Expand All @@ -67,5 +59,5 @@ packages:
source: hosted
version: "2.1.4"
sdks:
dart: ">=3.0.0-0 <4.0.0"
dart: ">=3.3.0-0 <4.0.0"
flutter: ">=1.17.0"
59 changes: 38 additions & 21 deletions lib/src/reorderable_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class ReorderableGridView extends StatefulWidget {
this.proxyDecorator,
this.autoScroll,
this.onReorderStart,
this.buildDefaultDragHandles = true,
}) : assert(
children.every((Widget w) => w.key != null),
'All children of this widget must have a key.',
Expand Down Expand Up @@ -309,6 +310,7 @@ class ReorderableGridView extends StatefulWidget {
this.proxyDecorator,
this.autoScroll,
this.onReorderStart,
this.buildDefaultDragHandles = true,
}) : assert(itemCount >= 0),
super(key: key);

Expand Down Expand Up @@ -352,6 +354,7 @@ class ReorderableGridView extends StatefulWidget {
this.proxyDecorator,
this.autoScroll,
this.onReorderStart,
this.buildDefaultDragHandles = true,
}) : gridDelegate = SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
mainAxisSpacing: mainAxisSpacing,
Expand Down Expand Up @@ -406,6 +409,7 @@ class ReorderableGridView extends StatefulWidget {
this.proxyDecorator,
this.autoScroll,
this.onReorderStart,
this.buildDefaultDragHandles = true,
}) : gridDelegate = SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxCrossAxisExtent,
mainAxisSpacing: mainAxisSpacing,
Expand Down Expand Up @@ -493,6 +497,14 @@ class ReorderableGridView extends StatefulWidget {
/// [NeverScrollableScrollPhysics]
final bool? autoScroll;

/// If true, the default drag handles will be built. Defaults to true.
/// If false, you must provide your own drag handles.
///
/// The default drag handles are built based on the platform:
/// - Windows, Linux, macOS: Drag handle is [ReorderableGridDragStartListener]
/// - Android, iOS, Fuchsia: Drag handle is [ReorderableGridDelayedDragStartListener]
final bool buildDefaultDragHandles;

@override
ReorderableGridViewState createState() => ReorderableGridViewState();

Expand All @@ -519,8 +531,7 @@ class ReorderableGridViewState extends State<ReorderableGridView> {
// before index+2, which is after the space at index+1.
void moveAfter() => reorder(index, index + 2);

final MaterialLocalizations localizations =
MaterialLocalizations.of(context);
final WidgetsLocalizations localizations = WidgetsLocalizations.of(context);

// If the item can move to before its current position in the grid.
if (index > 0) {
Expand Down Expand Up @@ -582,26 +593,32 @@ class ReorderableGridViewState extends State<ReorderableGridView> {
_ReorderableGridViewChildGlobalKey(item.key!, this);
final bool enable = widget.itemDragEnable(index);

switch (Theme.of(context).platform) {
case TargetPlatform.linux:
case TargetPlatform.windows:
case TargetPlatform.macOS:
return ReorderableGridDragStartListener(
key: itemGlobalKey,
index: index,
enabled: enable,
child: itemWithSemantics,
);
case TargetPlatform.iOS:
case TargetPlatform.android:
case TargetPlatform.fuchsia:
return ReorderableGridDelayedDragStartListener(
key: itemGlobalKey,
index: index,
enabled: enable,
child: itemWithSemantics,
);
if (widget.buildDefaultDragHandles) {
switch (Theme.of(context).platform) {
case TargetPlatform.linux:
case TargetPlatform.windows:
case TargetPlatform.macOS:
return ReorderableGridDragStartListener(
key: itemGlobalKey,
index: index,
enabled: enable,
child: itemWithSemantics,
);
case TargetPlatform.iOS:
case TargetPlatform.android:
case TargetPlatform.fuchsia:
return ReorderableGridDelayedDragStartListener(
key: itemGlobalKey,
index: index,
enabled: enable,
child: itemWithSemantics,
);
}
}
return KeyedSubtree(
key: itemGlobalKey,
child: itemWithSemantics,
);
}

Widget _proxyDecorator(Widget child, int index, Animation<double> animation) {
Expand Down
80 changes: 52 additions & 28 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
fake_async:
dependency: transitive
description:
Expand All @@ -58,63 +58,79 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "2.0.3"
version: "5.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
js:
leak_tracker:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
name: leak_tracker
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.dev"
source: hosted
version: "0.6.7"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.dev"
source: hosted
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "5.0.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.15.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -124,26 +140,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -164,10 +180,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.7.2"
vector_math:
dependency: transitive
description:
Expand All @@ -176,6 +192,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.5"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=1.17.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
flutter_lints: ^5.0.0
2 changes: 1 addition & 1 deletion test/src/reorderable_grid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void main() {
onReorder: handleReorder,
),
),
const Duration(milliseconds: 100),
duration: const Duration(milliseconds: 100),
);
await tester.pumpAndSettle();

Expand Down
2 changes: 1 addition & 1 deletion test/src/reorderable_grid_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void main() {
MaterialApp(
home: reorderableGridView,
),
const Duration(milliseconds: 100));
duration: const Duration(milliseconds: 100));

final dynamic exception = tester.takeException();
expect(exception, isNotNull);
Expand Down