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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 68 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.dart_tool/
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
/build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

build/
ios/.generated/
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

\.idea/
**/ios/Flutter/flutter_export_environment.sh
.flutter-plugins-dependencies
pubspec.lock
33 changes: 9 additions & 24 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,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),
Expand All @@ -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),
Expand Down
135 changes: 68 additions & 67 deletions lib/board_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -37,7 +35,7 @@ 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,36 +44,34 @@ 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;
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(() {});
}
}
}
Expand All @@ -84,50 +80,55 @@ 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!
.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.');
}
}
}
Loading