From 772d43480a19317895a82d3a7eab58a4cbe63b9f Mon Sep 17 00:00:00 2001 From: Philip Brink Date: Tue, 11 Jun 2024 12:47:16 -0400 Subject: [PATCH 1/4] add linter and linting analysis options --- analysis_options.yaml | 28 ++++++++++++++++++++++++++++ pubspec.yaml | 1 + 2 files changed, 29 insertions(+) create mode 100644 analysis_options.yaml diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..773ccf5 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,28 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at https://dart.dev/tools/linter-rules. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/tools/analysis \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 4b28915..a375f74 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,6 +12,7 @@ dependencies: sdk: flutter dev_dependencies: + flutter_lints: ^4.0.0 flutter_test: sdk: flutter From c86481a78d63f2b8d51b888134cca3ec01bdac05 Mon Sep 17 00:00:00 2001 From: Philip Brink Date: Tue, 11 Jun 2024 13:14:04 -0400 Subject: [PATCH 2/4] apply dart fix changes --- lib/drag_and_drop_builder_parameters.dart | 12 ++-- lib/drag_and_drop_item_target.dart | 8 +-- lib/drag_and_drop_item_wrapper.dart | 47 +++++++------- lib/drag_and_drop_list.dart | 10 +-- lib/drag_and_drop_list_expansion.dart | 17 +++-- lib/drag_and_drop_list_interface.dart | 1 + lib/drag_and_drop_list_target.dart | 9 ++- lib/drag_and_drop_list_wrapper.dart | 31 +++++---- lib/drag_and_drop_lists.dart | 79 ++++++++++++----------- lib/drag_handle.dart | 4 +- lib/measure_size.dart | 6 +- 11 files changed, 118 insertions(+), 106 deletions(-) diff --git a/lib/drag_and_drop_builder_parameters.dart b/lib/drag_and_drop_builder_parameters.dart index 5fcc749..6a27c5d 100644 --- a/lib/drag_and_drop_builder_parameters.dart +++ b/lib/drag_and_drop_builder_parameters.dart @@ -2,19 +2,19 @@ import 'package:drag_and_drop_lists/drag_and_drop_list_interface.dart'; import 'package:drag_and_drop_lists/drag_and_drop_lists.dart'; import 'package:flutter/widgets.dart'; -typedef void OnPointerMove(PointerMoveEvent event); -typedef void OnPointerUp(PointerUpEvent event); -typedef void OnPointerDown(PointerDownEvent event); -typedef void OnItemReordered( +typedef OnPointerMove = void Function(PointerMoveEvent event); +typedef OnPointerUp = void Function(PointerUpEvent event); +typedef OnPointerDown = void Function(PointerDownEvent event); +typedef OnItemReordered = void Function( DragAndDropItem reorderedItem, DragAndDropItem receiverItem, ); -typedef void OnItemDropOnLastTarget( +typedef OnItemDropOnLastTarget = void Function( DragAndDropItem newOrReorderedItem, DragAndDropListInterface parentList, DragAndDropItemTarget receiver, ); -typedef void OnListReordered( +typedef OnListReordered = void Function( DragAndDropListInterface reorderedList, DragAndDropListInterface receiverList, ); diff --git a/lib/drag_and_drop_item_target.dart b/lib/drag_and_drop_item_target.dart index 96bf643..f4eec2a 100644 --- a/lib/drag_and_drop_item_target.dart +++ b/lib/drag_and_drop_item_target.dart @@ -9,13 +9,12 @@ class DragAndDropItemTarget extends StatefulWidget { final DragAndDropBuilderParameters parameters; final OnItemDropOnLastTarget onReorderOrAdd; - DragAndDropItemTarget( + const DragAndDropItemTarget( {required this.child, required this.onReorderOrAdd, required this.parameters, this.parent, - Key? key}) - : super(key: key); + super.key}); @override State createState() => _DragAndDropItemTarget(); @@ -55,9 +54,10 @@ class _DragAndDropItemTarget extends State }, onWillAcceptWithDetails: (details) { bool accept = true; - if (widget.parameters.itemTargetOnWillAccept != null) + if (widget.parameters.itemTargetOnWillAccept != null) { accept = widget.parameters.itemTargetOnWillAccept!(details.data, widget); + } if (accept && mounted) { setState(() { _hoveredDraggable = details.data; diff --git a/lib/drag_and_drop_item_wrapper.dart b/lib/drag_and_drop_item_wrapper.dart index 06a80a7..a85241e 100644 --- a/lib/drag_and_drop_item_wrapper.dart +++ b/lib/drag_and_drop_item_wrapper.dart @@ -6,9 +6,8 @@ class DragAndDropItemWrapper extends StatefulWidget { final DragAndDropItem child; final DragAndDropBuilderParameters? parameters; - DragAndDropItemWrapper( - {required this.child, required this.parameters, Key? key}) - : super(key: key); + const DragAndDropItemWrapper( + {required this.child, required this.parameters, super.key}); @override State createState() => _DragAndDropItemWrapper(); @@ -27,7 +26,7 @@ class _DragAndDropItemWrapper extends State Widget draggable; if (widget.child.canDrag) { if (widget.parameters!.itemDragHandle != null) { - Widget feedback = Container( + Widget feedback = SizedBox( width: widget.parameters!.itemDraggingWidth ?? _containerSize.width, child: Stack( children: [ @@ -68,14 +67,6 @@ class _DragAndDropItemWrapper extends State widget.parameters!.constrainDraggingAxis ? Axis.vertical : null, - child: MeasureSize( - onSizeChange: (size) { - setState(() { - _dragHandleSize = size!; - }); - }, - child: widget.parameters!.itemDragHandle, - ), feedback: Transform.translate( offset: _feedbackContainerOffset(), child: Material( @@ -94,6 +85,14 @@ class _DragAndDropItemWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: MeasureSize( + onSizeChange: (size) { + setState(() { + _dragHandleSize = size!; + }); + }, + child: widget.parameters!.itemDragHandle, + ), ), ), ); @@ -120,18 +119,17 @@ class _DragAndDropItemWrapper extends State widget.parameters!.constrainDraggingAxis ? Axis.vertical : null, - child: widget.child.child, - feedback: Container( + feedback: SizedBox( width: widget.parameters!.itemDraggingWidth ?? _containerSize.width, child: Material( + color: Colors.transparent, child: Container( + decoration: widget.parameters!.itemDecorationWhileDragging, child: Directionality( textDirection: Directionality.of(context), child: widget.child.feedbackWidget ?? widget.child.child), - decoration: widget.parameters!.itemDecorationWhileDragging, ), - color: Colors.transparent, ), ), childWhenDragging: Container(), @@ -139,6 +137,7 @@ class _DragAndDropItemWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: widget.child.child, ), ); } else { @@ -150,19 +149,18 @@ class _DragAndDropItemWrapper extends State widget.parameters!.constrainDraggingAxis ? Axis.vertical : null, - child: widget.child.child, - feedback: Container( + feedback: SizedBox( width: widget.parameters!.itemDraggingWidth ?? _containerSize.width, child: Material( + color: Colors.transparent, child: Container( + decoration: widget.parameters!.itemDecorationWhileDragging, child: Directionality( textDirection: Directionality.of(context), child: widget.child.feedbackWidget ?? widget.child.child, ), - decoration: widget.parameters!.itemDecorationWhileDragging, ), - color: Colors.transparent, ), ), childWhenDragging: Container(), @@ -170,6 +168,7 @@ class _DragAndDropItemWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: widget.child.child, ), ); } @@ -200,10 +199,10 @@ class _DragAndDropItemWrapper extends State : Container(), ), Listener( - child: draggable, onPointerMove: _onPointerMove, onPointerDown: widget.parameters!.onPointerDown, onPointerUp: widget.parameters!.onPointerUp, + child: draggable, ), ], ), @@ -215,9 +214,10 @@ class _DragAndDropItemWrapper extends State }, onWillAcceptWithDetails: (details) { bool accept = true; - if (widget.parameters!.itemOnWillAccept != null) + if (widget.parameters!.itemOnWillAccept != null) { accept = widget.parameters!.itemOnWillAccept!( details.data, widget.child); + } if (accept && mounted) { setState(() { _hoveredDraggable = details.data; @@ -235,8 +235,9 @@ class _DragAndDropItemWrapper extends State onAcceptWithDetails: (details) { if (mounted) { setState(() { - if (widget.parameters!.onItemReordered != null) + if (widget.parameters!.onItemReordered != null) { widget.parameters!.onItemReordered!(details.data, widget.child); + } _hoveredDraggable = null; }); } diff --git a/lib/drag_and_drop_list.dart b/lib/drag_and_drop_list.dart index d071581..504a7c6 100644 --- a/lib/drag_and_drop_list.dart +++ b/lib/drag_and_drop_list.dart @@ -41,11 +41,13 @@ class DragAndDropList implements DragAndDropListInterface { /// The child elements that will be contained in this list. /// It is possible to not provide any children when an empty list is desired. + @override final List children; /// Whether or not this item can be dragged. /// Set to true if it can be reordered. /// Set to false if it must remain fixed. + @override final bool canDrag; DragAndDropList({ @@ -77,7 +79,7 @@ class DragAndDropList implements DragAndDropListInterface { ), ); if (params.axis == Axis.horizontal) { - intrinsicHeight = Container( + intrinsicHeight = SizedBox( width: params.listWidth, child: intrinsicHeight, ); @@ -141,7 +143,7 @@ class DragAndDropList implements DragAndDropListInterface { contents.add( Expanded( child: SingleChildScrollView( - physics: NeverScrollableScrollPhysics(), + physics: const NeverScrollableScrollPhysics(), child: Column( crossAxisAlignment: verticalAlignment, mainAxisSize: MainAxisSize.max, @@ -154,12 +156,12 @@ class DragAndDropList implements DragAndDropListInterface { contents.add( Expanded( child: SingleChildScrollView( - physics: NeverScrollableScrollPhysics(), + physics: const NeverScrollableScrollPhysics(), child: Column( mainAxisSize: MainAxisSize.max, children: [ contentsWhenEmpty ?? - Text( + const Text( 'Empty list', style: TextStyle( fontStyle: FontStyle.italic, diff --git a/lib/drag_and_drop_list_expansion.dart b/lib/drag_and_drop_list_expansion.dart index 6965a1b..ee0dcbb 100644 --- a/lib/drag_and_drop_list_expansion.dart +++ b/lib/drag_and_drop_list_expansion.dart @@ -8,7 +8,7 @@ import 'package:drag_and_drop_lists/drag_and_drop_list_interface.dart'; import 'package:drag_and_drop_lists/programmatic_expansion_tile.dart'; import 'package:flutter/material.dart'; -typedef void OnExpansionChanged(bool expanded); +typedef OnExpansionChanged = void Function(bool expanded); /// This class mirrors flutter's [ExpansionTile], with similar options. class DragAndDropListExpansion implements DragAndDropListExpansionInterface { @@ -25,6 +25,7 @@ class DragAndDropListExpansion implements DragAndDropListExpansionInterface { /// This function will be called when the expansion of a tile is changed. final OnExpansionChanged? onExpansionChanged; final Color? backgroundColor; + @override final List? children; final Widget? contentsWhenEmpty; final Widget? lastTarget; @@ -32,13 +33,14 @@ class DragAndDropListExpansion implements DragAndDropListExpansionInterface { /// Whether or not this item can be dragged. /// Set to true if it can be reordered. /// Set to false if it must remain fixed. + @override final bool canDrag; /// Disable to borders displayed at the top and bottom when expanded final bool disableTopAndBottomBorders; - ValueNotifier _expanded = ValueNotifier(true); - GlobalKey _expansionKey = + final ValueNotifier _expanded = ValueNotifier(true); + final GlobalKey _expansionKey = GlobalKey(); DragAndDropListExpansion({ @@ -149,7 +151,7 @@ class DragAndDropListExpansion implements DragAndDropListExpansionInterface { } else { contents.add( contentsWhenEmpty ?? - Text( + const Text( 'Empty list', style: TextStyle( fontStyle: FontStyle.italic, @@ -173,10 +175,11 @@ class DragAndDropListExpansion implements DragAndDropListExpansionInterface { @override toggleExpanded() { - if (isExpanded) + if (isExpanded) { collapse(); - else + } else { expand(); + } } @override @@ -207,7 +210,7 @@ class DragAndDropListExpansion implements DragAndDropListExpansionInterface { late Timer _expansionTimer; _startExpansionTimer() async { - _expansionTimer = Timer(Duration(milliseconds: 400), _expansionCallback); + _expansionTimer = Timer(const Duration(milliseconds: 400), _expansionCallback); } _stopExpansionTimer() async { diff --git a/lib/drag_and_drop_list_interface.dart b/lib/drag_and_drop_list_interface.dart index 839528c..7861c3e 100644 --- a/lib/drag_and_drop_list_interface.dart +++ b/lib/drag_and_drop_list_interface.dart @@ -16,6 +16,7 @@ abstract class DragAndDropListInterface implements DragAndDropInterface { abstract class DragAndDropListExpansionInterface implements DragAndDropListInterface { + @override final List? children; DragAndDropListExpansionInterface({this.children}); diff --git a/lib/drag_and_drop_list_target.dart b/lib/drag_and_drop_list_target.dart index 7a53744..e8184e1 100644 --- a/lib/drag_and_drop_list_target.dart +++ b/lib/drag_and_drop_list_target.dart @@ -3,7 +3,7 @@ import 'package:drag_and_drop_lists/drag_and_drop_list_interface.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -typedef void OnDropOnLastTarget( +typedef OnDropOnLastTarget = void Function( DragAndDropListInterface newOrReordered, DragAndDropListTarget receiver, ); @@ -14,13 +14,12 @@ class DragAndDropListTarget extends StatefulWidget { final OnDropOnLastTarget onDropOnLastTarget; final double lastListTargetSize; - DragAndDropListTarget( + const DragAndDropListTarget( {this.child, required this.parameters, required this.onDropOnLastTarget, this.lastListTargetSize = 110, - Key? key}) - : super(key: key); + super.key}); @override State createState() => _DragAndDropListTarget(); @@ -49,7 +48,7 @@ class _DragAndDropListTarget extends State : Container(), ), widget.child ?? - Container( + SizedBox( height: widget.parameters.axis == Axis.vertical ? widget.lastListTargetSize : null, diff --git a/lib/drag_and_drop_list_wrapper.dart b/lib/drag_and_drop_list_wrapper.dart index fb1928c..48ac580 100644 --- a/lib/drag_and_drop_list_wrapper.dart +++ b/lib/drag_and_drop_list_wrapper.dart @@ -8,9 +8,8 @@ class DragAndDropListWrapper extends StatefulWidget { final DragAndDropListInterface dragAndDropList; final DragAndDropBuilderParameters parameters; - DragAndDropListWrapper( - {required this.dragAndDropList, required this.parameters, Key? key}) - : super(key: key); + const DragAndDropListWrapper( + {required this.dragAndDropList, required this.parameters, super.key}); @override State createState() => _DragAndDropListWrapper(); @@ -65,14 +64,6 @@ class _DragAndDropListWrapper extends State child: Draggable( data: widget.dragAndDropList, axis: draggableAxis(), - child: MeasureSize( - onSizeChange: (size) { - setState(() { - _dragHandleSize = size!; - }); - }, - child: dragHandle, - ), feedback: Transform.translate( offset: _feedbackContainerOffset(), child: feedback, @@ -82,6 +73,14 @@ class _DragAndDropListWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: MeasureSize( + onSizeChange: (size) { + setState(() { + _dragHandleSize = size!; + }); + }, + child: dragHandle, + ), ), ), ], @@ -91,7 +90,6 @@ class _DragAndDropListWrapper extends State draggable = LongPressDraggable( data: widget.dragAndDropList, axis: draggableAxis(), - child: dragAndDropListContents, feedback: buildFeedbackWithoutHandle(context, dragAndDropListContents), childWhenDragging: Container(), @@ -99,12 +97,12 @@ class _DragAndDropListWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: dragAndDropListContents, ); } else { draggable = Draggable( data: widget.dragAndDropList, axis: draggableAxis(), - child: dragAndDropListContents, feedback: buildFeedbackWithoutHandle(context, dragAndDropListContents), childWhenDragging: Container(), @@ -112,6 +110,7 @@ class _DragAndDropListWrapper extends State onDragCompleted: () => _setDragging(false), onDraggableCanceled: (_, __) => _setDragging(false), onDragEnd: (_) => _setDragging(false), + child: dragAndDropListContents, ); } } else { @@ -131,7 +130,7 @@ class _DragAndDropListWrapper extends State child: widget.parameters.listGhost ?? Container( padding: widget.parameters.axis == Axis.vertical - ? EdgeInsets.all(0) + ? const EdgeInsets.all(0) : EdgeInsets.symmetric( horizontal: widget.parameters.listPadding!.horizontal), @@ -142,10 +141,10 @@ class _DragAndDropListWrapper extends State : Container(), ), Listener( - child: draggable, onPointerMove: _onPointerMove, onPointerDown: widget.parameters.onPointerDown, onPointerUp: widget.parameters.onPointerUp, + child: draggable, ), ]; @@ -226,7 +225,7 @@ class _DragAndDropListWrapper extends State color: Colors.transparent, child: Container( decoration: widget.parameters.listDecorationWhileDragging, - child: Container( + child: SizedBox( width: widget.parameters.listDraggingWidth ?? _containerSize.width, child: Stack( children: [ diff --git a/lib/drag_and_drop_lists.dart b/lib/drag_and_drop_lists.dart index 65fcbc4..e5aa67d 100644 --- a/lib/drag_and_drop_lists.dart +++ b/lib/drag_and_drop_lists.dart @@ -35,50 +35,50 @@ export 'package:drag_and_drop_lists/drag_and_drop_list_target.dart'; export 'package:drag_and_drop_lists/drag_and_drop_list_wrapper.dart'; export 'package:drag_and_drop_lists/drag_handle.dart'; -typedef void OnItemReorder( +typedef OnItemReorder = void Function( int oldItemIndex, int oldListIndex, int newItemIndex, int newListIndex, ); -typedef void OnItemAdd( +typedef OnItemAdd = void Function( DragAndDropItem newItem, int listIndex, int newItemIndex, ); -typedef void OnListAdd(DragAndDropListInterface newList, int newListIndex); -typedef void OnListReorder(int oldListIndex, int newListIndex); -typedef void OnListDraggingChanged( +typedef OnListAdd = void Function(DragAndDropListInterface newList, int newListIndex); +typedef OnListReorder = void Function(int oldListIndex, int newListIndex); +typedef OnListDraggingChanged = void Function( DragAndDropListInterface? list, bool dragging, ); -typedef bool ListOnWillAccept( +typedef ListOnWillAccept = bool Function( DragAndDropListInterface? incoming, DragAndDropListInterface? target, ); -typedef void ListOnAccept( +typedef ListOnAccept = void Function( DragAndDropListInterface incoming, DragAndDropListInterface target, ); -typedef bool ListTargetOnWillAccept( +typedef ListTargetOnWillAccept = bool Function( DragAndDropListInterface? incoming, DragAndDropListTarget target); -typedef void ListTargetOnAccept( +typedef ListTargetOnAccept = void Function( DragAndDropListInterface incoming, DragAndDropListTarget target); -typedef void OnItemDraggingChanged( +typedef OnItemDraggingChanged = void Function( DragAndDropItem item, bool dragging, ); -typedef bool ItemOnWillAccept( +typedef ItemOnWillAccept = bool Function( DragAndDropItem? incoming, DragAndDropItem target, ); -typedef void ItemOnAccept( +typedef ItemOnAccept = void Function( DragAndDropItem incoming, DragAndDropItem target, ); -typedef bool ItemTargetOnWillAccept( +typedef ItemTargetOnWillAccept = bool Function( DragAndDropItem? incoming, DragAndDropItemTarget target); -typedef void ItemTargetOnAccept( +typedef ItemTargetOnAccept = void Function( DragAndDropItem incoming, DragAndDropListInterface parentList, DragAndDropItemTarget target, @@ -336,14 +336,15 @@ class DragAndDropLists extends StatefulWidget { this.itemDragHandle, this.constrainDraggingAxis = true, this.removeTopPadding = false, - Key? key, - }) : super(key: key) { + super.key, + }) { if (listGhost == null && children - .where((element) => element is DragAndDropListExpansionInterface) - .isNotEmpty) + .whereType() + .isNotEmpty) { throw Exception( 'If using DragAndDropListExpansion, you must provide a non-null listGhost'); + } if (sliverList && scrollController == null) { throw Exception( 'A scroll controller must be provided when using sliver lists'); @@ -368,14 +369,15 @@ class DragAndDropListsState extends State { double? _pointerYPosition; double? _pointerXPosition; bool _scrolling = false; - PageStorageBucket _pageStorageBucket = PageStorageBucket(); + final PageStorageBucket _pageStorageBucket = PageStorageBucket(); @override void initState() { - if (widget.scrollController != null) + if (widget.scrollController != null) { _scrollController = widget.scrollController; - else + } else { _scrollController = ScrollController(); + } super.initState(); } @@ -422,10 +424,10 @@ class DragAndDropListsState extends State { ); DragAndDropListTarget dragAndDropListTarget = DragAndDropListTarget( - child: widget.listTarget, parameters: parameters, onDropOnLastTarget: _internalOnListDropOnLastTarget, lastListTargetSize: widget.lastListTargetSize, + child: widget.listTarget, ); if (widget.children.isNotEmpty) { @@ -441,11 +443,11 @@ class DragAndDropListsState extends State { } if (widget.children - .where((e) => e is DragAndDropListExpansionInterface) + .whereType() .isNotEmpty) { outerListHolder = PageStorage( - child: outerListHolder, bucket: _pageStorageBucket, + child: outerListHolder, ); } return outerListHolder; @@ -454,7 +456,7 @@ class DragAndDropListsState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - widget.contentsWhenEmpty ?? Text('Empty'), + widget.contentsWhenEmpty ?? const Text('Empty'), dragAndDropListTarget, ], ), @@ -493,7 +495,7 @@ class DragAndDropListsState extends State { Widget _buildListView(DragAndDropBuilderParameters parameters, DragAndDropListTarget dragAndDropListTarget) { - Widget _listView = ListView( + Widget listView = ListView( scrollDirection: widget.axis, controller: _scrollController, children: _buildOuterList(dragAndDropListTarget, parameters), @@ -503,9 +505,9 @@ class DragAndDropListsState extends State { ? MediaQuery.removePadding( removeTop: true, context: context, - child: _listView, + child: listView, ) - : _listView; + : listView; } List _buildOuterList(DragAndDropListTarget dragAndDropListTarget, @@ -520,12 +522,13 @@ class DragAndDropListsState extends State { } int _calculateChildrenCount(bool includeSeparators) { - if (includeSeparators) + if (includeSeparators) { return (widget.children.length * 2) - (widget.listDividerOnLastChild ? 0 : 1) + 1; - else + } else { return widget.children.length + 1; + } } Widget _buildInnerList( @@ -575,8 +578,9 @@ class DragAndDropListsState extends State { if (reorderedItemIndex == -1) { // this is a new item - if (widget.onItemAdd != null) + if (widget.onItemAdd != null) { widget.onItemAdd!(reordered, receiverListIndex, receiverItemIndex); + } } else { if (reorderedListIndex == receiverListIndex && receiverItemIndex > reorderedItemIndex) { @@ -642,9 +646,10 @@ class DragAndDropListsState extends State { } if (reorderedItemIndex == -1) { - if (widget.onItemAdd != null) + if (widget.onItemAdd != null) { widget.onItemAdd!( newOrReordered, receiverListIndex, reorderedItemIndex); + } } else { if (reorderedListIndex == receiverListIndex && receiverItemIndex > reorderedItemIndex) { @@ -662,14 +667,16 @@ class DragAndDropListsState extends State { int reorderedListIndex = widget.children.indexWhere((e) => newOrReordered == e); - if (widget.listOnAccept != null) + if (widget.listOnAccept != null) { widget.listTargetOnAccept!(newOrReordered, receiver); + } if (reorderedListIndex >= 0) { widget.onListReorder(reorderedListIndex, widget.children.length - 1); } else { - if (widget.onListAdd != null) + if (widget.onListAdd != null) { widget.onListAdd!(newOrReordered, reorderedListIndex); + } } } @@ -708,9 +715,9 @@ class DragAndDropListsState extends State { var rb = context.findRenderObject()!; late Size size; - if (rb is RenderBox) + if (rb is RenderBox) { size = rb.size; - else if (rb is RenderSliver) size = rb.paintBounds.size; + } else if (rb is RenderSliver) size = rb.paintBounds.size; var topLeftOffset = localToGlobal(rb, Offset.zero); var bottomRightOffset = localToGlobal(rb, size.bottomRight(Offset.zero)); diff --git a/lib/drag_handle.dart b/lib/drag_handle.dart index 2406fed..1495057 100644 --- a/lib/drag_handle.dart +++ b/lib/drag_handle.dart @@ -17,11 +17,11 @@ class DragHandle extends StatelessWidget { final Widget child; const DragHandle({ - Key? key, + super.key, required this.child, this.onLeft = false, this.verticalAlignment = DragHandleVerticalAlignment.center, - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/lib/measure_size.dart b/lib/measure_size.dart index 0e7c862..4d7dad9 100644 --- a/lib/measure_size.dart +++ b/lib/measure_size.dart @@ -1,17 +1,17 @@ import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; -typedef void OnWidgetSizeChange(Size? size); +typedef OnWidgetSizeChange = void Function(Size? size); class MeasureSize extends StatefulWidget { final Widget? child; final OnWidgetSizeChange onSizeChange; const MeasureSize({ - Key? key, + super.key, required this.onSizeChange, required this.child, - }) : super(key: key); + }); @override _MeasureSizeState createState() => _MeasureSizeState(); From aa0d15df10831dcd9d71d70cbc29c359231a9384 Mon Sep 17 00:00:00 2001 From: Philip Brink Date: Wed, 12 Jun 2024 15:44:17 -0400 Subject: [PATCH 3/4] Update gradle to imperative plugins --- example/android/app/build.gradle | 21 +++++++-------------- example/android/build.gradle | 13 ------------- example/android/settings.gradle | 30 ++++++++++++++++++++++-------- example/pubspec.yaml | 2 +- 4 files changed, 30 insertions(+), 36 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 0833ecf..c1e6719 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,10 +22,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion @@ -64,8 +61,4 @@ android { flutter { source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +} \ No newline at end of file diff --git a/example/android/build.gradle b/example/android/build.gradle index 3cdaac9..bc157bd 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,16 +1,3 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.1.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..765b878 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.1.2" apply false + id "org.jetbrains.kotlin.android" version "1.6.10" apply false +} + +include ":app" \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4b82c00..4f8acb3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.17.6 <3.0.0" + sdk: ">=2.17.6 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions From 4adca047f409efe5105efcf2d0cfdfda5ae5a3f7 Mon Sep 17 00:00:00 2001 From: Philip Brink Date: Wed, 12 Jun 2024 17:01:20 -0400 Subject: [PATCH 4/4] apply dart fix changes --- lib/drag_and_drop_list_wrapper.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/drag_and_drop_list_wrapper.dart b/lib/drag_and_drop_list_wrapper.dart index 48ac580..75c9d4a 100644 --- a/lib/drag_and_drop_list_wrapper.dart +++ b/lib/drag_and_drop_list_wrapper.dart @@ -253,9 +253,9 @@ class _DragAndDropListWrapper extends State ); } - Container buildFeedbackWithoutHandle( + SizedBox buildFeedbackWithoutHandle( BuildContext context, Widget dragAndDropListContents) { - return Container( + return SizedBox( width: widget.parameters.axis == Axis.vertical ? (widget.parameters.listDraggingWidth ?? MediaQuery.of(context).size.width)