From e5b81744c8c89d9f3c138d28178125bc3e35fa6f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 13 May 2023 18:17:37 +0200 Subject: [PATCH 1/4] Upgraded to flutter 3.10 and fixed problems --- example/example.dart | 33 +-- lib/board_item.dart | 135 +++++------ lib/board_list.dart | 49 ++-- lib/boardview.dart | 406 ++++++++++++++++++++-------------- lib/boardview_controller.dart | 12 +- pubspec.lock | 117 ++++++---- pubspec.yaml | 4 +- test/boardview_test.dart | 9 - 8 files changed, 412 insertions(+), 353 deletions(-) delete mode 100644 test/boardview_test.dart diff --git a/example/example.dart b/example/example.dart index c5c7fdb..ae8e7af 100644 --- a/example/example.dart +++ b/example/example.dart @@ -8,20 +8,14 @@ import 'BoardItemObject.dart'; import 'BoardListObject.dart'; class BoardViewExample extends StatelessWidget { - - - - List _listData = [ + final List _listData = [ BoardListObject(title: "List title 1"), BoardListObject(title: "List title 2"), BoardListObject(title: "List title 3") ]; - //Can be used to animate to different sections of the BoardView - BoardViewController boardViewController = new BoardViewController(); - - + final BoardViewController boardViewController = new BoardViewController(); @override Widget build(BuildContext context) { @@ -37,19 +31,14 @@ class BoardViewExample extends StatelessWidget { Widget buildBoardItem(BoardItemObject itemObject) { return BoardItem( - onStartDragItem: (int? listIndex, int? itemIndex, BoardItemState? state) { - - }, - onDropItem: (int? listIndex, int? itemIndex, int? oldListIndex, - int? oldItemIndex, BoardItemState? state) { + onStartDragItem: (int? listIndex, int? itemIndex, BoardItemState? state) {}, + onDropItem: (int? listIndex, int? itemIndex, int? oldListIndex, int? oldItemIndex, BoardItemState? state) { //Used to update our local item data var item = _listData[oldListIndex!].items![oldItemIndex!]; - _listData[oldListIndex].items!.removeAt(oldItemIndex!); + _listData[oldListIndex].items!.removeAt(oldItemIndex); _listData[listIndex!].items!.insert(itemIndex!, item); }, - onTapItem: (int? listIndex, int? itemIndex, BoardItemState? state) async { - - }, + onTapItem: (int? listIndex, int? itemIndex, BoardItemState? state) async {}, item: Card( child: Padding( padding: const EdgeInsets.all(8.0), @@ -65,16 +54,12 @@ class BoardViewExample extends StatelessWidget { } return BoardList( - onStartDragList: (int? listIndex) { - - }, - onTapList: (int? listIndex) async { - - }, + onStartDragList: (int? listIndex) {}, + onTapList: (int? listIndex) async {}, onDropList: (int? listIndex, int? oldListIndex) { //Update our local list data var list = _listData[oldListIndex!]; - _listData.removeAt(oldListIndex!); + _listData.removeAt(oldListIndex); _listData.insert(listIndex!, list); }, headerBackgroundColor: Color.fromARGB(255, 235, 236, 240), diff --git a/lib/board_item.dart b/lib/board_item.dart index c00cd2f..4f6c4f3 100644 --- a/lib/board_item.dart +++ b/lib/board_item.dart @@ -2,12 +2,10 @@ import 'package:boardview/board_list.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -typedef void OnDropItem(int? listIndex, int? itemIndex,int? oldListIndex,int? oldItemIndex, BoardItemState state); +typedef void OnDropItem(int? listIndex, int? itemIndex, int? oldListIndex, int? oldItemIndex, BoardItemState state); typedef void OnTapItem(int? listIndex, int? itemIndex, BoardItemState state); -typedef void OnStartDragItem( - int? listIndex, int? itemIndex, BoardItemState state); -typedef void OnDragItem(int oldListIndex, int oldItemIndex, int newListIndex, - int newItemIndex, BoardItemState state); +typedef void OnStartDragItem(int? listIndex, int? itemIndex, BoardItemState state); +typedef void OnDragItem(int oldListIndex, int oldItemIndex, int newListIndex, int newItemIndex, BoardItemState state); class BoardItem extends StatefulWidget { final BoardListState? boardList; @@ -21,14 +19,14 @@ class BoardItem extends StatefulWidget { const BoardItem( {Key? key, - this.boardList, - this.item, - this.index, - this.onDropItem, - this.onTapItem, - this.onStartDragItem, - this.draggable = true, - this.onDragItem}) + this.boardList, + this.item, + this.index, + this.onDropItem, + this.onTapItem, + this.onStartDragItem, + this.draggable = true, + this.onDragItem}) : super(key: key); @override @@ -37,7 +35,7 @@ class BoardItem extends StatefulWidget { } } -class BoardItemState extends State with AutomaticKeepAliveClientMixin{ +class BoardItemState extends State with AutomaticKeepAliveClientMixin { late double height; double? width; @@ -46,36 +44,34 @@ class BoardItemState extends State with AutomaticKeepAliveClientMixin void onDropItem(int? listIndex, int? itemIndex) { if (widget.onDropItem != null) { - widget.onDropItem!(listIndex, itemIndex,widget.boardList!.widget.boardView!.startListIndex,widget.boardList!.widget.boardView!.startItemIndex, this); + widget.onDropItem!( + listIndex, itemIndex, widget.boardList!.widget.boardView!.startListIndex, widget.boardList!.widget.boardView!.startItemIndex, this); } widget.boardList!.widget.boardView!.draggedItemIndex = null; widget.boardList!.widget.boardView!.draggedListIndex = null; - if(widget.boardList!.widget.boardView!.listStates[listIndex!].mounted) { - widget.boardList!.widget.boardView!.listStates[listIndex].setState(() { }); + if (widget.boardList!.widget.boardView!.listStates[listIndex!].mounted) { + widget.boardList!.widget.boardView!.listStates[listIndex].setState(() {}); } } void _startDrag(Widget item, BuildContext context) { if (widget.boardList!.widget.boardView != null) { widget.boardList!.widget.boardView!.onDropItem = onDropItem; - if(widget.boardList!.mounted) { - widget.boardList!.setState(() { }); + if (widget.boardList!.mounted) { + widget.boardList!.setState(() {}); } widget.boardList!.widget.boardView!.draggedItemIndex = widget.index; widget.boardList!.widget.boardView!.height = context.size!.height; - widget.boardList!.widget.boardView!.draggedListIndex = - widget.boardList!.widget.index; - widget.boardList!.widget.boardView!.startListIndex = - widget.boardList!.widget.index; + widget.boardList!.widget.boardView!.draggedListIndex = widget.boardList!.widget.index; + widget.boardList!.widget.boardView!.startListIndex = widget.boardList!.widget.index; widget.boardList!.widget.boardView!.startItemIndex = widget.index; widget.boardList!.widget.boardView!.draggedItem = item; if (widget.onStartDragItem != null) { - widget.onStartDragItem!( - widget.boardList!.widget.index, widget.index, this); + widget.onStartDragItem!(widget.boardList!.widget.index, widget.index, this); } widget.boardList!.widget.boardView!.run(); - if(widget.boardList!.widget.boardView!.mounted) { - widget.boardList!.widget.boardView!.setState(() { }); + if (widget.boardList!.widget.boardView!.mounted) { + widget.boardList!.widget.boardView!.setState(() {}); } } } @@ -84,50 +80,55 @@ class BoardItemState extends State with AutomaticKeepAliveClientMixin try { height = context.size!.height; width = context.size!.width; - }catch(e){} + } catch (e) {} } @override Widget build(BuildContext context) { - WidgetsBinding.instance! - .addPostFrameCallback((_) => afterFirstLayout(context)); - if (widget.boardList!.itemStates.length > widget.index!) { - widget.boardList!.itemStates.removeAt(widget.index!); - } - widget.boardList!.itemStates.insert(widget.index!, this); - return GestureDetector( - onTapDown: (otd) { - if(widget.draggable) { - RenderBox object = context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); - RenderBox box = widget.boardList!.context.findRenderObject() as RenderBox; - Offset listPos = box.localToGlobal(Offset.zero); - widget.boardList!.widget.boardView!.leftListX = listPos.dx; - widget.boardList!.widget.boardView!.topListY = listPos.dy; - widget.boardList!.widget.boardView!.topItemY = pos.dy; - widget.boardList!.widget.boardView!.bottomItemY = - pos.dy + object.size.height; - widget.boardList!.widget.boardView!.bottomListY = - listPos.dy + box.size.height; - widget.boardList!.widget.boardView!.rightListX = - listPos.dx + box.size.width; + super.build(context); + + WidgetsBinding.instance.addPostFrameCallback((_) => afterFirstLayout(context)); + + if (widget.boardList != null) { + if (widget.boardList!.itemStates.length > widget.index!) { + widget.boardList!.itemStates.removeAt(widget.index!); + } - widget.boardList!.widget.boardView!.initialX = pos.dx; - widget.boardList!.widget.boardView!.initialY = pos.dy; - } - }, - onTapCancel: () {}, - onTap: () { - if (widget.onTapItem != null) { - widget.onTapItem!(widget.boardList!.widget.index, widget.index, this); - } - }, - onLongPress: () { - if(!widget.boardList!.widget.boardView!.widget.isSelecting && widget.draggable) { - _startDrag(widget, context); - } - }, - child: widget.item, - ); + widget.boardList!.itemStates.insert(widget.index!, this); + + return GestureDetector( + onTapDown: (otd) { + if (widget.draggable) { + RenderBox object = context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); + RenderBox box = widget.boardList!.context.findRenderObject() as RenderBox; + Offset listPos = box.localToGlobal(Offset.zero); + widget.boardList!.widget.boardView!.leftListX = listPos.dx; + widget.boardList!.widget.boardView!.topListY = listPos.dy; + widget.boardList!.widget.boardView!.topItemY = pos.dy; + widget.boardList!.widget.boardView!.bottomItemY = pos.dy + object.size.height; + widget.boardList!.widget.boardView!.bottomListY = listPos.dy + box.size.height; + widget.boardList!.widget.boardView!.rightListX = listPos.dx + box.size.width; + + widget.boardList!.widget.boardView!.initialX = pos.dx; + widget.boardList!.widget.boardView!.initialY = pos.dy; + } + }, + onTapCancel: () {}, + onTap: () { + if (widget.onTapItem != null) { + widget.onTapItem!(widget.boardList!.widget.index, widget.index, this); + } + }, + onLongPress: () { + if (!widget.boardList!.widget.boardView!.widget.isSelecting && widget.draggable) { + _startDrag(widget, context); + } + }, + child: widget.item, + ); + } else { + return Text('Error on loading boardlist.'); + } } } diff --git a/lib/board_list.dart b/lib/board_list.dart index f9d95ec..bcca4e5 100644 --- a/lib/board_list.dart +++ b/lib/board_list.dart @@ -3,7 +3,7 @@ import 'package:boardview/boardview.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -typedef void OnDropList(int? listIndex,int? oldListIndex); +typedef void OnDropList(int? listIndex, int? oldListIndex); typedef void OnTapList(int? listIndex); typedef void OnStartDragList(int? listIndex); @@ -28,7 +28,10 @@ class BoardList extends StatefulWidget { this.headerBackgroundColor, this.boardView, this.draggable = true, - this.index, this.onDropList, this.onTapList, this.onStartDragList, + this.index, + this.onDropList, + this.onTapList, + this.onStartDragList, }) : super(key: key); final int? index; @@ -39,25 +42,23 @@ class BoardList extends StatefulWidget { } } -class BoardListState extends State with AutomaticKeepAliveClientMixin{ +class BoardListState extends State with AutomaticKeepAliveClientMixin { List itemStates = []; ScrollController boardListController = new ScrollController(); void onDropList(int? listIndex) { - if(widget.onDropList != null){ - widget.onDropList!(listIndex,widget.boardView!.startListIndex); + if (widget.onDropList != null) { + widget.onDropList!(listIndex, widget.boardView!.startListIndex); } widget.boardView!.draggedListIndex = null; - if(widget.boardView!.mounted) { - widget.boardView!.setState(() { - - }); + if (widget.boardView!.mounted) { + widget.boardView!.setState(() {}); } } void _startDrag(Widget item, BuildContext context) { if (widget.boardView != null && widget.draggable) { - if(widget.onStartDragList != null){ + if (widget.onStartDragList != null) { widget.onStartDragList!(widget.index); } widget.boardView!.startListIndex = widget.index; @@ -67,7 +68,7 @@ class BoardListState extends State with AutomaticKeepAliveClientMixin widget.boardView!.draggedItem = item; widget.boardView!.onDropList = onDropList; widget.boardView!.run(); - if(widget.boardView!.mounted) { + if (widget.boardView!.mounted) { widget.boardView!.setState(() {}); } } @@ -78,20 +79,19 @@ class BoardListState extends State with AutomaticKeepAliveClientMixin @override Widget build(BuildContext context) { + super.build(context); + List listWidgets = []; + if (widget.header != null) { - Color? headerBackgroundColor = Color.fromARGB(255, 255, 255, 255); - if (widget.headerBackgroundColor != null) { - headerBackgroundColor = widget.headerBackgroundColor; - } listWidgets.add(GestureDetector( - onTap: (){ - if(widget.onTapList != null){ + onTap: () { + if (widget.onTapList != null) { widget.onTapList!(widget.index); } }, onTapDown: (otd) { - if(widget.draggable) { + if (widget.draggable) { RenderBox object = context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); widget.boardView!.initialX = pos.dx; @@ -103,18 +103,14 @@ class BoardListState extends State with AutomaticKeepAliveClientMixin }, onTapCancel: () {}, onLongPress: () { - if(!widget.boardView!.widget.isSelecting && widget.draggable) { + if (!widget.boardView!.widget.isSelecting && widget.draggable) { _startDrag(widget, context); } }, child: Container( color: widget.headerBackgroundColor, - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - children: widget.header!), + child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: widget.header!), ))); - } if (widget.items != null) { listWidgets.add(Container( @@ -141,8 +137,7 @@ class BoardListState extends State with AutomaticKeepAliveClientMixin onStartDragItem: widget.items![index].onStartDragItem, ); } - if (widget.boardView!.draggedItemIndex == index && - widget.boardView!.draggedListIndex == widget.index) { + if (widget.boardView!.draggedItemIndex == index && widget.boardView!.draggedListIndex == widget.index) { return Opacity( opacity: 0.0, child: widget.items![index], @@ -174,7 +169,7 @@ class BoardListState extends State with AutomaticKeepAliveClientMixin child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, - children: listWidgets as List, + children: listWidgets, )); } } diff --git a/lib/boardview.dart b/lib/boardview.dart index dfbe9b2..96d7bb2 100644 --- a/lib/boardview.dart +++ b/lib/boardview.dart @@ -1,10 +1,7 @@ library boardview; -import 'dart:math'; - import 'package:boardview/boardview_controller.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'dart:core'; import 'package:boardview/board_list.dart'; import 'package:vs_scrollbar/vs_scrollbar.dart'; @@ -12,17 +9,31 @@ import 'package:vs_scrollbar/vs_scrollbar.dart'; class BoardView extends StatefulWidget { final List? lists; final double width; - Widget? middleWidget; - double? bottomPadding; - bool isSelecting; - bool? scrollbar; - ScrollbarStyle? scrollbarStyle; - BoardViewController? boardViewController; - int dragDelay; - - Function(bool)? itemInMiddleWidget; - OnDropBottomWidget? onDropItemInMiddleWidget; - BoardView({Key? key, this.itemInMiddleWidget,this.scrollbar,this.scrollbarStyle,this.boardViewController,this.dragDelay=300,this.onDropItemInMiddleWidget, this.isSelecting = false, this.lists, this.width = 280, this.middleWidget, this.bottomPadding}) : super(key: key); + final Widget? middleWidget; + final double? bottomPadding; + final bool isSelecting; + final bool? scrollbar; + final ScrollbarStyle? scrollbarStyle; + final BoardViewController? boardViewController; + final int dragDelay; + + final Function(bool)? itemInMiddleWidget; + final OnDropBottomWidget? onDropItemInMiddleWidget; + + BoardView( + {Key? key, + this.itemInMiddleWidget, + this.scrollbar, + this.scrollbarStyle, + this.boardViewController, + this.dragDelay = 300, + this.onDropItemInMiddleWidget, + this.isSelecting = false, + this.lists, + this.width = 280, + this.middleWidget, + this.bottomPadding}) + : super(key: key); @override State createState() { @@ -30,7 +41,7 @@ class BoardView extends StatefulWidget { } } -typedef void OnDropBottomWidget(int? listIndex, int? itemIndex,double percentX); +typedef void OnDropBottomWidget(int? listIndex, int? itemIndex, double percentX); typedef void OnDropItem(int? listIndex, int? itemIndex); typedef void OnDropList(int? listIndex); @@ -79,49 +90,61 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin @override void initState() { super.initState(); - if(widget.boardViewController != null){ + if (widget.boardViewController != null) { widget.boardViewController!.state = this; } } void moveDown() { - if(topItemY != null){ + if (topItemY != null) { topItemY = topItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; } - if(bottomItemY != null){ + + if (bottomItemY != null) { bottomItemY = bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; } + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if(draggedItemIndex != null){ + + if (draggedItemIndex != null) { draggedItemIndex = draggedItemIndex! + 1; } + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } } void moveUp() { - if(topItemY != null){ + if (topItemY != null) { topItemY = topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; } - if(bottomItemY != null){ - bottomItemY = bottomItemY!-listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; + + if (bottomItemY != null) { + bottomItemY = bottomItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; } + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if(draggedItemIndex != null){ + + if (draggedItemIndex != null) { draggedItemIndex = draggedItemIndex! - 1; } + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } } @@ -129,19 +152,22 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin void moveListRight() { var list = widget.lists![draggedListIndex!]; var listState = listStates[draggedListIndex!]; + widget.lists!.removeAt(draggedListIndex!); listStates.removeAt(draggedListIndex!); - if(draggedListIndex != null){ + + if (draggedListIndex != null) { draggedListIndex = draggedListIndex! + 1; } + widget.lists!.insert(draggedListIndex!, list); listStates.insert(draggedListIndex!, listState); + canDrag = false; - if (boardViewController != null && boardViewController.hasClients) { + + if (boardViewController.hasClients) { int? tempListIndex = draggedListIndex; - boardViewController - .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) - .whenComplete(() { + boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); leftListX = pos.dx; @@ -151,7 +177,8 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin }); }); } - if(mounted){ + + if (mounted) { setState(() {}); } } @@ -159,84 +186,102 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin void moveRight() { var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } - if(draggedListIndex != null){ + + if (draggedListIndex != null) { draggedListIndex = draggedListIndex! + 1; } + double closestValue = 10000; draggedItemIndex = 0; + for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { - if (listStates[draggedListIndex!].itemStates[i].mounted && listStates[draggedListIndex!].itemStates[i].context != null) { - RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; - Offset pos = box.localToGlobal(Offset.zero); - var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); - if (temp < closestValue) { - closestValue = temp; - draggedItemIndex = i; - dyInit = dy; - } + RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; + Offset pos = box.localToGlobal(Offset.zero); + var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); + + if (temp < closestValue) { + closestValue = temp; + draggedItemIndex = i; + dyInit = dy; } } + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); canDrag = false; - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } - if (boardViewController != null && boardViewController.hasClients) { + + if (boardViewController.hasClients) { int? tempListIndex = draggedListIndex; int? tempItemIndex = draggedItemIndex; - boardViewController - .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) - .whenComplete(() { + + boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; rightListX = pos.dx + object.size.width; + RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; Offset itemPos = box.localToGlobal(Offset.zero); + topItemY = itemPos.dy; bottomItemY = itemPos.dy + box.size.height; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); } - if(mounted){ - setState(() { }); + if (mounted) { + setState(() {}); } } void moveListLeft() { var list = widget.lists![draggedListIndex!]; var listState = listStates[draggedListIndex!]; + widget.lists!.removeAt(draggedListIndex!); listStates.removeAt(draggedListIndex!); - if(draggedListIndex != null){ + + if (draggedListIndex != null) { draggedListIndex = draggedListIndex! - 1; } + widget.lists!.insert(draggedListIndex!, list); listStates.insert(draggedListIndex!, listState); canDrag = false; - if (boardViewController != null && boardViewController.hasClients) { + + if (boardViewController.hasClients) { int? tempListIndex = draggedListIndex; + boardViewController .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: widget.dragDelay), curve: Curves.ease) .whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; rightListX = pos.dx + object.size.width; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); } - if(mounted) { + + if (mounted) { setState(() {}); } } @@ -244,54 +289,64 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin void moveLeft() { var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } - if(draggedListIndex != null){ + + if (draggedListIndex != null) { draggedListIndex = draggedListIndex! - 1; } + double closestValue = 10000; draggedItemIndex = 0; + for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { - if (listStates[draggedListIndex!].itemStates[i].mounted && listStates[draggedListIndex!].itemStates[i].context != null) { - RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; - Offset pos = box.localToGlobal(Offset.zero); - var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); - if (temp < closestValue) { - closestValue = temp; - draggedItemIndex = i; - dyInit = dy; - } + RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; + Offset pos = box.localToGlobal(Offset.zero); + var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); + if (temp < closestValue) { + closestValue = temp; + draggedItemIndex = i; + dyInit = dy; } } + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + canDrag = false; - if(listStates[draggedListIndex!].mounted) { + + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); } - if (boardViewController != null && boardViewController.hasClients) { + + if (boardViewController.hasClients) { int? tempListIndex = draggedListIndex; int? tempItemIndex = draggedItemIndex; - boardViewController - .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) - .whenComplete(() { + + boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; rightListX = pos.dx + object.size.width; + RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; Offset itemPos = box.localToGlobal(Offset.zero); + topItemY = itemPos.dy; bottomItemY = itemPos.dy + box.size.height; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); } - if(mounted) { + if (mounted) { setState(() {}); } } @@ -300,22 +355,24 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin @override Widget build(BuildContext context) { - print("dy:${dy}"); - print("topListY:${topListY}"); - print("bottomListY:${bottomListY}"); - if(boardViewController.hasClients) { - WidgetsBinding.instance!.addPostFrameCallback((Duration duration) { + super.build(context); + + if (boardViewController.hasClients) { + WidgetsBinding.instance.addPostFrameCallback((Duration duration) { try { boardViewController.position.didUpdateScrollPositionBy(0); - }catch(e){} - bool _shown = boardViewController.position.maxScrollExtent!=0; - if(_shown != shown){ + } catch (e) {} + + bool _shown = boardViewController.position.maxScrollExtent != 0; + + if (_shown != shown) { setState(() { shown = _shown; }); } }); } + Widget listWidget = ListView.builder( physics: ClampingScrollPhysics(), itemCount: widget.lists!.length, @@ -336,6 +393,7 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin onStartDragList: widget.lists![index].onStartDragList, ); } + if (widget.lists![index].index != index) { widget.lists![index] = BoardList( items: widget.lists![index].items, @@ -370,155 +428,154 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin } }, ); - if(widget.scrollbar == true){ + + if (widget.scrollbar == true) { listWidget = VsScrollbar( controller: boardViewController, - showTrackOnHover: true,// default false - isAlwaysShown: shown&&widget.lists!.length>1, // default false + showTrackOnHover: true, // default false + isAlwaysShown: shown && widget.lists!.length > 1, // default false scrollbarFadeDuration: Duration(milliseconds: 500), // default : Duration(milliseconds: 300) - scrollbarTimeToFade: Duration(milliseconds: 800),// default : Duration(milliseconds: 600) - style: widget.scrollbarStyle!=null?VsScrollbarStyle( - hoverThickness: widget.scrollbarStyle!.hoverThickness, - radius: widget.scrollbarStyle!.radius, - thickness: widget.scrollbarStyle!.thickness, - color: widget.scrollbarStyle!.color - ):VsScrollbarStyle(), - child:listWidget); - } - List stackWidgets = [ - listWidget - ]; + scrollbarTimeToFade: Duration(milliseconds: 800), // default : Duration(milliseconds: 600) + style: widget.scrollbarStyle != null + ? VsScrollbarStyle( + hoverThickness: widget.scrollbarStyle!.hoverThickness, + radius: widget.scrollbarStyle!.radius, + thickness: widget.scrollbarStyle!.thickness, + color: widget.scrollbarStyle!.color) + : VsScrollbarStyle(), + child: listWidget); + } + + List stackWidgets = [listWidget]; bool isInBottomWidget = false; + if (dy != null) { if (MediaQuery.of(context).size.height - dy! < 80) { isInBottomWidget = true; } } - if(widget.itemInMiddleWidget != null && _isInWidget != isInBottomWidget) { + + if (widget.itemInMiddleWidget != null && _isInWidget != isInBottomWidget) { widget.itemInMiddleWidget!(isInBottomWidget); _isInWidget = isInBottomWidget; } - if (initialX != null && - initialY != null && - offsetX != null && - offsetY != null && - dx != null && - dy != null && - height != null && - widget.width != null) { + + if (initialX != null && initialY != null && offsetX != null && offsetY != null && dx != null && dy != null && height != null) { if (canDrag && dxInit != null && dyInit != null && !isInBottomWidget) { if (draggedItemIndex != null && draggedItem != null && topItemY != null && bottomItemY != null) { //dragging item if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { //scroll left - if (boardViewController != null && boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels - 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease); - if(listStates[draggedListIndex!].mounted) { - RenderBox object = listStates[draggedListIndex!].context - .findRenderObject() as RenderBox; + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + if (listStates[draggedListIndex!].mounted) { + RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); leftListX = pos.dx; rightListX = pos.dx + object.size.width; } } } + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { //scroll right - if (boardViewController != null && boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels + 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease); - if(listStates[draggedListIndex!].mounted) { - RenderBox object = listStates[draggedListIndex!].context - .findRenderObject() as RenderBox; + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + if (listStates[draggedListIndex!].mounted) { + RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; Offset pos = object.localToGlobal(Offset.zero); leftListX = pos.dx; rightListX = pos.dx + object.size.width; } } } + if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { //move left moveLeft(); } + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { //move right moveRight(); } + if (dy! < topListY! + 70) { //scroll up - if (listStates[draggedListIndex!].boardListController != null && - listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { + if (listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { isScrolling = true; double pos = listStates[draggedListIndex!].boardListController.position.pixels; - listStates[draggedListIndex!].boardListController.animateTo( - listStates[draggedListIndex!].boardListController.position.pixels - 5, - duration: new Duration(milliseconds: 10), - curve: Curves.ease).whenComplete((){ - + listStates[draggedListIndex!] + .boardListController + .animateTo(listStates[draggedListIndex!].boardListController.position.pixels - 5, + duration: new Duration(milliseconds: 10), curve: Curves.ease) + .whenComplete(() { pos -= listStates[draggedListIndex!].boardListController.position.pixels; - if(initialY == null) - initialY = 0; + if (initialY == null) initialY = 0; // if(widget.boardViewController != null) { // initialY -= pos; // } isScrolling = false; - if(topItemY != null) { + if (topItemY != null) { topItemY = topItemY! + pos; } - if(bottomItemY != null) { + if (bottomItemY != null) { bottomItemY = bottomItemY! + pos; } - if(mounted){ - setState(() { }); + if (mounted) { + setState(() {}); } }); } } - if (0 <= draggedItemIndex! - 1 && - dy! < topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height / 2) { + if (0 <= draggedItemIndex! - 1 && dy! < topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height / 2) { //move up moveUp(); } double? tempBottom = bottomListY; - if(widget.middleWidget != null){ - if(_middleWidgetKey.currentContext != null) { - RenderBox _box = _middleWidgetKey.currentContext! - .findRenderObject() as RenderBox; + if (widget.middleWidget != null) { + if (_middleWidgetKey.currentContext != null) { + RenderBox _box = _middleWidgetKey.currentContext!.findRenderObject() as RenderBox; tempBottom = _box.size.height; - print("tempBottom:${tempBottom}"); } } if (dy! > tempBottom! - 70) { //scroll down - if (listStates[draggedListIndex!].boardListController != null && - listStates[draggedListIndex!].boardListController.hasClients) { + if (listStates[draggedListIndex!].boardListController.hasClients) { isScrolling = true; double pos = listStates[draggedListIndex!].boardListController.position.pixels; - listStates[draggedListIndex!].boardListController.animateTo( - listStates[draggedListIndex!].boardListController.position.pixels + 5, - duration: new Duration(milliseconds: 10), - curve: Curves.ease).whenComplete((){ + listStates[draggedListIndex!] + .boardListController + .animateTo(listStates[draggedListIndex!].boardListController.position.pixels + 5, + duration: new Duration(milliseconds: 10), curve: Curves.ease) + .whenComplete(() { pos -= listStates[draggedListIndex!].boardListController.position.pixels; - if(initialY == null) + + if (initialY == null) { initialY = 0; + } // if(widget.boardViewController != null) { // initialY -= pos; // } + isScrolling = false; - if(topItemY != null) { + + if (topItemY != null) { topItemY = topItemY! + pos; } - if(bottomItemY != null) { + + if (bottomItemY != null) { bottomItemY = bottomItemY! + pos; } - if(mounted){ + + if (mounted) { setState(() {}); } }); } } + if (widget.lists![draggedListIndex!].items!.length > draggedItemIndex! + 1 && dy! > bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height / 2) { //move down @@ -528,13 +585,14 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin //dragging list if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { //scroll left - if (boardViewController != null && boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels - 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease); - if(leftListX != null){ + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + + if (leftListX != null) { leftListX = leftListX! + 5; } - if(rightListX != null){ + + if (rightListX != null) { rightListX = rightListX! + 5; } } @@ -542,35 +600,41 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { //scroll right - if (boardViewController != null && boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels + 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease); - if(leftListX != null){ + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + + if (leftListX != null) { leftListX = leftListX! - 5; } - if(rightListX != null){ + + if (rightListX != null) { rightListX = rightListX! - 5; } } } + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { //move right moveListRight(); } + if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { //move left moveListLeft(); } } } + if (widget.middleWidget != null) { - stackWidgets.add(Container(key:_middleWidgetKey,child:widget.middleWidget)); + stackWidgets.add(Container(key: _middleWidgetKey, child: widget.middleWidget)); } - WidgetsBinding.instance!.addPostFrameCallback((timeStamp) { - if(mounted){ + + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + if (mounted) { setState(() {}); } }); + stackWidgets.add(Positioned( width: widget.width, height: height, @@ -587,12 +651,15 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin if (dxInit == null) { dxInit = opm.position.dx; } + if (dyInit == null) { dyInit = opm.position.dy; } + dx = opm.position.dx; dy = opm.position.dy; - if(mounted) { + + if (mounted) { setState(() {}); } } @@ -600,10 +667,12 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin onPointerDown: (opd) { RenderBox box = context.findRenderObject() as RenderBox; Offset pos = box.localToGlobal(opd.position); + offsetX = pos.dx; offsetY = pos.dy; pointer = opd; - if(mounted) { + + if (mounted) { setState(() {}); } }, @@ -614,19 +683,20 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin int? startDraggedItemIndex = startItemIndex; int? startDraggedListIndex = startListIndex; - if(_isInWidget && widget.onDropItemInMiddleWidget != null){ + if (_isInWidget && widget.onDropItemInMiddleWidget != null) { onDropItem!(startDraggedListIndex, startDraggedItemIndex); - widget.onDropItemInMiddleWidget!(startDraggedListIndex, startDraggedItemIndex,opu.position.dx/MediaQuery.of(context).size.width); - }else{ + widget.onDropItemInMiddleWidget!(startDraggedListIndex, startDraggedItemIndex, opu.position.dx / MediaQuery.of(context).size.width); + } else { onDropItem!(tempDraggedListIndex, tempDraggedItemIndex); } } if (onDropList != null) { int? tempDraggedListIndex = draggedListIndex; - if(_isInWidget && widget.onDropItemInMiddleWidget != null){ + + if (_isInWidget && widget.onDropItemInMiddleWidget != null) { onDropList!(tempDraggedListIndex); - widget.onDropItemInMiddleWidget!(tempDraggedListIndex,null,opu.position.dx/MediaQuery.of(context).size.width); - }else{ + widget.onDropItemInMiddleWidget!(tempDraggedListIndex, null, opu.position.dx / MediaQuery.of(context).size.width); + } else { onDropList!(tempDraggedListIndex); } } @@ -651,7 +721,7 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin bottomItemY = null; startListIndex = null; startItemIndex = null; - if(mounted) { + if (mounted) { setState(() {}); } }, @@ -664,17 +734,17 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin if (pointer != null) { dx = pointer.position.dx; dy = pointer.position.dy; - if(mounted) { + if (mounted) { setState(() {}); } } } } -class ScrollbarStyle{ +class ScrollbarStyle { double hoverThickness; double thickness; Radius radius; Color color; - ScrollbarStyle({this.radius = const Radius.circular(10),this.hoverThickness = 10,this.thickness = 10,this.color = Colors.black}); + ScrollbarStyle({this.radius = const Radius.circular(10), this.hoverThickness = 10, this.thickness = 10, this.color = Colors.black}); } diff --git a/lib/boardview_controller.dart b/lib/boardview_controller.dart index 0123e13..117454f 100644 --- a/lib/boardview_controller.dart +++ b/lib/boardview_controller.dart @@ -2,17 +2,15 @@ import 'package:flutter/animation.dart'; import 'boardview.dart'; -class BoardViewController{ - +class BoardViewController { BoardViewController(); late BoardViewState state; - Future animateTo(int index,{Duration? duration,Curve? curve})async{ + Future animateTo(int index, {Duration? duration, Curve? curve}) async { double offset = index * state.widget.width; - if (state.boardViewController != null && state.boardViewController.hasClients) { - await state.boardViewController.animateTo( - offset, duration: duration!, curve: curve!); + if (state.boardViewController.hasClients) { + await state.boardViewController.animateTo(offset, duration: duration!, curve: curve!); } } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index 69b2334..306cfca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -60,27 +59,46 @@ packages: 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" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -90,65 +108,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.3.0" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" vs_scrollbar: dependency: "direct main" description: name: vs_scrollbar - url: "https://pub.dartlang.org" + sha256: "1c602b0a2d5cb8e1b025ee448c0a459af6786e4d1d5460f984666e81706dbce0" + url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.2.1" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index a62a47a..248ee90 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: boardview description: This is a custom Flutter widget that can create a draggable BoardView or also known as a kanban. The view can be reordered with drag and drop. -version: 0.2.1 +version: 0.2.3 homepage: https://github.com/jakebonk/FlutterBoardView environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.17.0 <3.0.0" dependencies: flutter: diff --git a/test/boardview_test.dart b/test/boardview_test.dart deleted file mode 100644 index 6f79cb0..0000000 --- a/test/boardview_test.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; - -import 'package:boardview/boardview.dart'; - -void main() { - test('adds one to input values', () { - final boardview = BoardView(); - }); -} From e5c182c9fe29e5683e2252a5f1dee160cda5ad00 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 22 May 2023 18:43:05 +0200 Subject: [PATCH 2/4] fix-#23: null checker exceptions --- lib/boardview.dart | 584 +++++++++++++++++++++++---------------------- 1 file changed, 298 insertions(+), 286 deletions(-) diff --git a/lib/boardview.dart b/lib/boardview.dart index 96d7bb2..c8104b7 100644 --- a/lib/boardview.dart +++ b/lib/boardview.dart @@ -96,86 +96,90 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin } void moveDown() { - if (topItemY != null) { - topItemY = topItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; - } + if (draggedListIndex != null && draggedItemIndex != null && widget.lists != null) { + if (topItemY != null) { + topItemY = topItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; + } - if (bottomItemY != null) { - bottomItemY = bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; - } + if (bottomItemY != null) { + bottomItemY = bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height; + } - var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; - widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); - var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; - listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if (draggedItemIndex != null) { - draggedItemIndex = draggedItemIndex! + 1; - } + if (draggedItemIndex != null) { + draggedItemIndex = draggedItemIndex! + 1; + } - widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); - listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); + listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } } } void moveUp() { - if (topItemY != null) { - topItemY = topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; - } + if (draggedListIndex != null && draggedItemIndex != null && widget.lists != null) { + if (topItemY != null) { + topItemY = topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; + } - if (bottomItemY != null) { - bottomItemY = bottomItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; - } + if (bottomItemY != null) { + bottomItemY = bottomItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height; + } - var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; - widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); - var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; - listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if (draggedItemIndex != null) { draggedItemIndex = draggedItemIndex! - 1; - } - widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); - listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); + listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } } } void moveListRight() { - var list = widget.lists![draggedListIndex!]; - var listState = listStates[draggedListIndex!]; + if (draggedListIndex != null && widget.lists != null) { + var list = widget.lists![draggedListIndex!]; + var listState = listStates[draggedListIndex!]; - widget.lists!.removeAt(draggedListIndex!); - listStates.removeAt(draggedListIndex!); + widget.lists!.removeAt(draggedListIndex!); + listStates.removeAt(draggedListIndex!); - if (draggedListIndex != null) { draggedListIndex = draggedListIndex! + 1; - } - - widget.lists!.insert(draggedListIndex!, list); - listStates.insert(draggedListIndex!, listState); - canDrag = false; - - if (boardViewController.hasClients) { - int? tempListIndex = draggedListIndex; - boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { - RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { - canDrag = true; + widget.lists!.insert(draggedListIndex!, list); + listStates.insert(draggedListIndex!, listState); + + canDrag = false; + + if (boardViewController.hasClients) { + int? tempListIndex = draggedListIndex; + boardViewController + .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) + .whenComplete(() { + RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + canDrag = true; + }); }); - }); + } } if (mounted) { @@ -184,101 +188,104 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin } void moveRight() { - var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; - var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + if (draggedListIndex != null && draggedItemIndex != null && widget.lists != null) { + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; - widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); - listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); - } + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } - if (draggedListIndex != null) { draggedListIndex = draggedListIndex! + 1; - } - double closestValue = 10000; - draggedItemIndex = 0; + double closestValue = 10000; + draggedItemIndex = 0; - for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { - RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; - Offset pos = box.localToGlobal(Offset.zero); - var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); + for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { + RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; + Offset pos = box.localToGlobal(Offset.zero); + var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); - if (temp < closestValue) { - closestValue = temp; - draggedItemIndex = i; - dyInit = dy; - } - } + if (temp < closestValue) { + closestValue = temp; + draggedItemIndex = i; + dyInit = dy; + } - widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); - listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - canDrag = false; + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); + listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + canDrag = false; + } - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); - } + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } - if (boardViewController.hasClients) { - int? tempListIndex = draggedListIndex; - int? tempItemIndex = draggedItemIndex; + if (boardViewController.hasClients) { + int? tempListIndex = draggedListIndex; + int? tempItemIndex = draggedItemIndex; - boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { - RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); + boardViewController + .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) + .whenComplete(() { + RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; - RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; - Offset itemPos = box.localToGlobal(Offset.zero); + RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; + Offset itemPos = box.localToGlobal(Offset.zero); - topItemY = itemPos.dy; - bottomItemY = itemPos.dy + box.size.height; + topItemY = itemPos.dy; + bottomItemY = itemPos.dy + box.size.height; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { - canDrag = true; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + canDrag = true; + }); }); - }); + } } + if (mounted) { setState(() {}); } } void moveListLeft() { - var list = widget.lists![draggedListIndex!]; - var listState = listStates[draggedListIndex!]; + if (draggedListIndex != null && widget.lists != null) { + var list = widget.lists![draggedListIndex!]; + var listState = listStates[draggedListIndex!]; - widget.lists!.removeAt(draggedListIndex!); - listStates.removeAt(draggedListIndex!); + widget.lists!.removeAt(draggedListIndex!); + listStates.removeAt(draggedListIndex!); - if (draggedListIndex != null) { draggedListIndex = draggedListIndex! - 1; - } - widget.lists!.insert(draggedListIndex!, list); - listStates.insert(draggedListIndex!, listState); - canDrag = false; + widget.lists!.insert(draggedListIndex!, list); + listStates.insert(draggedListIndex!, listState); + canDrag = false; - if (boardViewController.hasClients) { - int? tempListIndex = draggedListIndex; + if (boardViewController.hasClients) { + int? tempListIndex = draggedListIndex; - boardViewController - .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: widget.dragDelay), curve: Curves.ease) - .whenComplete(() { - RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); + boardViewController + .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: widget.dragDelay), curve: Curves.ease) + .whenComplete(() { + RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { - canDrag = true; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + canDrag = true; + }); }); - }); + } } if (mounted) { @@ -287,65 +294,68 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin } void moveLeft() { - var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; - var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; + if (draggedListIndex != null && draggedItemIndex != null && widget.lists != null) { + var item = widget.lists![draggedListIndex!].items![draggedItemIndex!]; + var itemState = listStates[draggedListIndex!].itemStates[draggedItemIndex!]; - widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); - listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); + widget.lists![draggedListIndex!].items!.removeAt(draggedItemIndex!); + listStates[draggedListIndex!].itemStates.removeAt(draggedItemIndex!); - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); - } + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } - if (draggedListIndex != null) { draggedListIndex = draggedListIndex! - 1; - } - double closestValue = 10000; - draggedItemIndex = 0; - - for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { - RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; - Offset pos = box.localToGlobal(Offset.zero); - var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); - if (temp < closestValue) { - closestValue = temp; - draggedItemIndex = i; - dyInit = dy; + double closestValue = 10000; + draggedItemIndex = 0; + + for (int i = 0; i < listStates[draggedListIndex!].itemStates.length; i++) { + RenderBox box = listStates[draggedListIndex!].itemStates[i].context.findRenderObject() as RenderBox; + Offset pos = box.localToGlobal(Offset.zero); + var temp = (pos.dy - dy! + (box.size.height / 2)).abs(); + if (temp < closestValue) { + closestValue = temp; + draggedItemIndex = i; + dyInit = dy; + } } - } - widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); - listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); + listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - canDrag = false; + canDrag = false; - if (listStates[draggedListIndex!].mounted) { - listStates[draggedListIndex!].setState(() {}); - } + if (listStates[draggedListIndex!].mounted) { + listStates[draggedListIndex!].setState(() {}); + } - if (boardViewController.hasClients) { - int? tempListIndex = draggedListIndex; - int? tempItemIndex = draggedItemIndex; + if (boardViewController.hasClients) { + int? tempListIndex = draggedListIndex; + int? tempItemIndex = draggedItemIndex; - boardViewController.animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease).whenComplete(() { - RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); + boardViewController + .animateTo(draggedListIndex! * widget.width, duration: new Duration(milliseconds: 400), curve: Curves.ease) + .whenComplete(() { + RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; - RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; - Offset itemPos = box.localToGlobal(Offset.zero); + RenderBox box = listStates[tempListIndex].itemStates[tempItemIndex!].context.findRenderObject() as RenderBox; + Offset itemPos = box.localToGlobal(Offset.zero); - topItemY = itemPos.dy; - bottomItemY = itemPos.dy + box.size.height; + topItemY = itemPos.dy; + bottomItemY = itemPos.dy + box.size.height; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { - canDrag = true; + Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + canDrag = true; + }); }); - }); + } } + if (mounted) { setState(() {}); } @@ -462,165 +472,167 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin if (initialX != null && initialY != null && offsetX != null && offsetY != null && dx != null && dy != null && height != null) { if (canDrag && dxInit != null && dyInit != null && !isInBottomWidget) { - if (draggedItemIndex != null && draggedItem != null && topItemY != null && bottomItemY != null) { - //dragging item - if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { - //scroll left - if (boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); - if (listStates[draggedListIndex!].mounted) { - RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; + if (draggedListIndex != null) { + if (draggedItemIndex != null && draggedItem != null && topItemY != null && bottomItemY != null) { + //dragging item + if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { + //scroll left + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + if (listStates[draggedListIndex!].mounted) { + RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; + } } } - } - if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { - //scroll right - if (boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); - if (listStates[draggedListIndex!].mounted) { - RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; - Offset pos = object.localToGlobal(Offset.zero); - leftListX = pos.dx; - rightListX = pos.dx + object.size.width; + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { + //scroll right + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + if (listStates[draggedListIndex!].mounted) { + RenderBox object = listStates[draggedListIndex!].context.findRenderObject() as RenderBox; + Offset pos = object.localToGlobal(Offset.zero); + leftListX = pos.dx; + rightListX = pos.dx + object.size.width; + } } } - } - if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { - //move left - moveLeft(); - } + if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { + //move left + moveLeft(); + } - if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { - //move right - moveRight(); - } + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { + //move right + moveRight(); + } - if (dy! < topListY! + 70) { - //scroll up - if (listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { - isScrolling = true; - double pos = listStates[draggedListIndex!].boardListController.position.pixels; - listStates[draggedListIndex!] - .boardListController - .animateTo(listStates[draggedListIndex!].boardListController.position.pixels - 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease) - .whenComplete(() { - pos -= listStates[draggedListIndex!].boardListController.position.pixels; - if (initialY == null) initialY = 0; + if (dy! < topListY! + 70) { + //scroll up + if (listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { + isScrolling = true; + double pos = listStates[draggedListIndex!].boardListController.position.pixels; + listStates[draggedListIndex!] + .boardListController + .animateTo(listStates[draggedListIndex!].boardListController.position.pixels - 5, + duration: new Duration(milliseconds: 10), curve: Curves.ease) + .whenComplete(() { + pos -= listStates[draggedListIndex!].boardListController.position.pixels; + if (initialY == null) initialY = 0; // if(widget.boardViewController != null) { // initialY -= pos; // } - isScrolling = false; - if (topItemY != null) { - topItemY = topItemY! + pos; - } - if (bottomItemY != null) { - bottomItemY = bottomItemY! + pos; - } - if (mounted) { - setState(() {}); - } - }); + isScrolling = false; + if (topItemY != null) { + topItemY = topItemY! + pos; + } + if (bottomItemY != null) { + bottomItemY = bottomItemY! + pos; + } + if (mounted) { + setState(() {}); + } + }); + } } - } - if (0 <= draggedItemIndex! - 1 && dy! < topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height / 2) { - //move up - moveUp(); - } - double? tempBottom = bottomListY; - if (widget.middleWidget != null) { - if (_middleWidgetKey.currentContext != null) { - RenderBox _box = _middleWidgetKey.currentContext!.findRenderObject() as RenderBox; - tempBottom = _box.size.height; + if (0 <= draggedItemIndex! - 1 && dy! < topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height / 2) { + //move up + moveUp(); } - } - if (dy! > tempBottom! - 70) { - //scroll down - - if (listStates[draggedListIndex!].boardListController.hasClients) { - isScrolling = true; - double pos = listStates[draggedListIndex!].boardListController.position.pixels; - listStates[draggedListIndex!] - .boardListController - .animateTo(listStates[draggedListIndex!].boardListController.position.pixels + 5, - duration: new Duration(milliseconds: 10), curve: Curves.ease) - .whenComplete(() { - pos -= listStates[draggedListIndex!].boardListController.position.pixels; - - if (initialY == null) { - initialY = 0; - } + double? tempBottom = bottomListY; + if (widget.middleWidget != null) { + if (_middleWidgetKey.currentContext != null) { + RenderBox _box = _middleWidgetKey.currentContext!.findRenderObject() as RenderBox; + tempBottom = _box.size.height; + } + } + if (dy! > tempBottom! - 70) { + //scroll down + + if (listStates[draggedListIndex!].boardListController.hasClients) { + isScrolling = true; + double pos = listStates[draggedListIndex!].boardListController.position.pixels; + listStates[draggedListIndex!] + .boardListController + .animateTo(listStates[draggedListIndex!].boardListController.position.pixels + 5, + duration: new Duration(milliseconds: 10), curve: Curves.ease) + .whenComplete(() { + pos -= listStates[draggedListIndex!].boardListController.position.pixels; + + if (initialY == null) { + initialY = 0; + } // if(widget.boardViewController != null) { // initialY -= pos; // } - isScrolling = false; + isScrolling = false; - if (topItemY != null) { - topItemY = topItemY! + pos; - } + if (topItemY != null) { + topItemY = topItemY! + pos; + } - if (bottomItemY != null) { - bottomItemY = bottomItemY! + pos; - } + if (bottomItemY != null) { + bottomItemY = bottomItemY! + pos; + } - if (mounted) { - setState(() {}); - } - }); + if (mounted) { + setState(() {}); + } + }); + } } - } - if (widget.lists![draggedListIndex!].items!.length > draggedItemIndex! + 1 && - dy! > bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height / 2) { - //move down - moveDown(); - } - } else { - //dragging list - if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { - //scroll left - if (boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); - - if (leftListX != null) { - leftListX = leftListX! + 5; - } + if (widget.lists![draggedListIndex!].items!.length > draggedItemIndex! + 1 && + dy! > bottomItemY! + listStates[draggedListIndex!].itemStates[draggedItemIndex! + 1].height / 2) { + //move down + moveDown(); + } + } else { + //dragging list + if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { + //scroll left + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels - 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + + if (leftListX != null) { + leftListX = leftListX! + 5; + } - if (rightListX != null) { - rightListX = rightListX! + 5; + if (rightListX != null) { + rightListX = rightListX! + 5; + } } } - } - if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { - //scroll right - if (boardViewController.hasClients) { - boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { + //scroll right + if (boardViewController.hasClients) { + boardViewController.animateTo(boardViewController.position.pixels + 5, duration: new Duration(milliseconds: 10), curve: Curves.ease); - if (leftListX != null) { - leftListX = leftListX! - 5; - } + if (leftListX != null) { + leftListX = leftListX! - 5; + } - if (rightListX != null) { - rightListX = rightListX! - 5; + if (rightListX != null) { + rightListX = rightListX! - 5; + } } } - } - if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { - //move right - moveListRight(); - } + if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX!) { + //move right + moveListRight(); + } - if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { - //move left - moveListLeft(); + if (0 <= draggedListIndex! - 1 && dx! < leftListX!) { + //move left + moveListLeft(); + } } } } From 85594031642133f159993de531301e2cf0807670 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 22 May 2023 20:27:05 +0200 Subject: [PATCH 3/4] fix-#23: some more null exceptions - needs rework --- lib/boardview.dart | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/boardview.dart b/lib/boardview.dart index c8104b7..78d744a 100644 --- a/lib/boardview.dart +++ b/lib/boardview.dart @@ -511,7 +511,7 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin moveRight(); } - if (dy! < topListY! + 70) { + if (dy != null && topListY != null && dy! < topListY! + 70) { //scroll up if (listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { isScrolling = true; @@ -522,11 +522,13 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin duration: new Duration(milliseconds: 10), curve: Curves.ease) .whenComplete(() { pos -= listStates[draggedListIndex!].boardListController.position.pixels; - if (initialY == null) initialY = 0; -// if(widget.boardViewController != null) { -// initialY -= pos; -// } + + if (initialY == null) { + initialY = 0; + } + isScrolling = false; + if (topItemY != null) { topItemY = topItemY! + pos; } @@ -539,18 +541,22 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin }); } } + if (0 <= draggedItemIndex! - 1 && dy! < topItemY! - listStates[draggedListIndex!].itemStates[draggedItemIndex! - 1].height / 2) { //move up moveUp(); } + double? tempBottom = bottomListY; + if (widget.middleWidget != null) { if (_middleWidgetKey.currentContext != null) { RenderBox _box = _middleWidgetKey.currentContext!.findRenderObject() as RenderBox; tempBottom = _box.size.height; } } - if (dy! > tempBottom! - 70) { + + if (dy != null && tempBottom != null && dy! > tempBottom - 70) { //scroll down if (listStates[draggedListIndex!].boardListController.hasClients) { @@ -566,9 +572,6 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin if (initialY == null) { initialY = 0; } -// if(widget.boardViewController != null) { -// initialY -= pos; -// } isScrolling = false; From ab84ffb99b8339e9f5036c973d4ae470cf09d895 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 27 May 2023 13:58:13 +0200 Subject: [PATCH 4/4] fix-#23: oh no some endless loop --- lib/boardview.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/boardview.dart b/lib/boardview.dart index 78d744a..1d23793 100644 --- a/lib/boardview.dart +++ b/lib/boardview.dart @@ -214,12 +214,12 @@ class BoardViewState extends State with AutomaticKeepAliveClientMixin draggedItemIndex = i; dyInit = dy; } - - widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); - listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); - canDrag = false; } + widget.lists![draggedListIndex!].items!.insert(draggedItemIndex!, item); + listStates[draggedListIndex!].itemStates.insert(draggedItemIndex!, itemState); + canDrag = false; + if (listStates[draggedListIndex!].mounted) { listStates[draggedListIndex!].setState(() {}); }