Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ import 'BoardItemObject.dart';
import 'BoardListObject.dart';

class BoardViewExample extends StatelessWidget {



List<BoardListObject> _listData = [
final List<BoardListObject> _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) {
Expand All @@ -37,19 +31,17 @@ class BoardViewExample extends StatelessWidget {

Widget buildBoardItem(BoardItemObject itemObject) {
return BoardItem(
onStartDragItem: (int? listIndex, int? itemIndex, 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),
Expand All @@ -65,16 +57,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),
Expand Down
55 changes: 33 additions & 22 deletions lib/board_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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);
Expand All @@ -21,14 +22,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
Expand All @@ -37,7 +38,8 @@ class BoardItem extends StatefulWidget {
}
}

class BoardItemState extends State<BoardItem> with AutomaticKeepAliveClientMixin{
class BoardItemState extends State<BoardItem>
with AutomaticKeepAliveClientMixin {
late double height;
double? width;

Expand All @@ -46,20 +48,25 @@ class BoardItemState extends State<BoardItem> 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;
Expand All @@ -74,8 +81,8 @@ class BoardItemState extends State<BoardItem> with AutomaticKeepAliveClientMixin
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(() {});
}
}
}
Expand All @@ -84,23 +91,26 @@ class BoardItemState extends State<BoardItem> with AutomaticKeepAliveClientMixin
try {
height = context.size!.height;
width = context.size!.width;
}catch(e){}
} catch (e) {}
}

@override
Widget build(BuildContext context) {
WidgetsBinding.instance!
super.build(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) {
if (widget.draggable) {
RenderBox object = context.findRenderObject() as RenderBox;
Offset pos = object.localToGlobal(Offset.zero);
RenderBox box = widget.boardList!.context.findRenderObject() as RenderBox;
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;
Expand All @@ -123,7 +133,8 @@ class BoardItemState extends State<BoardItem> with AutomaticKeepAliveClientMixin
}
},
onLongPress: () {
if(!widget.boardList!.widget.boardView!.widget.isSelecting && widget.draggable) {
if (!widget.boardList!.widget.boardView!.widget.isSelecting &&
widget.draggable) {
_startDrag(widget, context);
}
},
Expand Down
44 changes: 22 additions & 22 deletions lib/board_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -39,25 +42,24 @@ class BoardList extends StatefulWidget {
}
}

class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin{
class BoardListState extends State<BoardList>
with AutomaticKeepAliveClientMixin {
List<BoardItemState> 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;
Expand All @@ -67,7 +69,7 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin
widget.boardView!.draggedItem = item;
widget.boardView!.onDropList = onDropList;
widget.boardView!.run();
if(widget.boardView!.mounted) {
if (widget.boardView!.mounted) {
widget.boardView!.setState(() {});
}
}
Expand All @@ -78,20 +80,18 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin

@override
Widget build(BuildContext context) {
super.build(context);

List<Widget> 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;
Expand All @@ -103,7 +103,7 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin
},
onTapCancel: () {},
onLongPress: () {
if(!widget.boardView!.widget.isSelecting && widget.draggable) {
if (!widget.boardView!.widget.isSelecting && widget.draggable) {
_startDrag(widget, context);
}
},
Expand All @@ -114,7 +114,6 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin
mainAxisAlignment: MainAxisAlignment.center,
children: widget.header!),
)));

}
if (widget.items != null) {
listWidgets.add(Container(
Expand All @@ -128,7 +127,8 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin
itemBuilder: (ctx, index) {
if (widget.items![index].boardList == null ||
widget.items![index].index != index ||
widget.items![index].boardList!.widget.index != widget.index ||
widget.items![index].boardList!.widget.index !=
widget.index ||
widget.items![index].boardList != this) {
widget.items![index] = new BoardItem(
boardList: this,
Expand Down Expand Up @@ -174,7 +174,7 @@ class BoardListState extends State<BoardList> with AutomaticKeepAliveClientMixin
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: listWidgets as List<Widget>,
children: listWidgets,
));
}
}
Loading