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
29 changes: 29 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
11 changes: 0 additions & 11 deletions example/BoardItemObject.dart

This file was deleted.

16 changes: 0 additions & 16 deletions example/BoardListObject.dart

This file was deleted.

5 changes: 5 additions & 0 deletions example/board_item_object.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class BoardItemObject {
String? title;

BoardItemObject({this.title = ''});
}
8 changes: 8 additions & 0 deletions example/board_list_object.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'board_item_object.dart';

class BoardListObject {
String? title;
List<BoardItemObject>? items;

BoardListObject({this.title = '', this.items = const []});
}
48 changes: 19 additions & 29 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import 'package:boardview/board_item.dart';
import 'package:boardview/board_list.dart';
import 'package:boardview/boardview_controller.dart';
import 'package:boardview/board_view_controller.dart';
import 'package:flutter/material.dart';
import 'package:boardview/boardview.dart';
import 'package:boardview/board_view.dart';

import 'BoardItemObject.dart';
import 'BoardListObject.dart';
import 'board_item_object.dart';
import 'board_list_object.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 = BoardViewController();

BoardViewExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -37,19 +33,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,27 +59,23 @@ 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),
backgroundColor: Color.fromARGB(255, 235, 236, 240),
headerBackgroundColor: const Color.fromARGB(255, 235, 236, 240),
backgroundColor: const Color.fromARGB(255, 235, 236, 240),
header: [
Expanded(
child: Padding(
padding: EdgeInsets.all(5),
padding: const EdgeInsets.all(5),
child: Text(
list.title!,
style: TextStyle(fontSize: 20),
style: const TextStyle(fontSize: 20),
))),
],
items: items,
Expand Down
141 changes: 75 additions & 66 deletions lib/board_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ 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 OnTapItem(int? listIndex, int? itemIndex, BoardItemState state);
typedef void OnStartDragItem(
typedef OnDropItem = void Function(int? listIndex, int? itemIndex,
int? oldListIndex, int? oldItemIndex, BoardItemState state);
typedef OnTapItem = void Function(
int? listIndex, int? itemIndex, BoardItemState state);
typedef void OnDragItem(int oldListIndex, int oldItemIndex, int newListIndex,
int newItemIndex, BoardItemState state);
typedef OnStartDragItem = void Function(
int? listIndex, int? itemIndex, BoardItemState state);
typedef OnDragItem = void Function(int oldListIndex, int oldItemIndex,
int newListIndex, int newItemIndex, BoardItemState state);

class BoardItem extends StatefulWidget {
final BoardListState? boardList;
Expand All @@ -21,14 +23,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,96 +39,103 @@ class BoardItem extends StatefulWidget {
}
}

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

@override
bool get wantKeepAlive => true;

void onDropItem(int? listIndex, int? itemIndex) {
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(() {});
}
}

bool get canStartDragging =>
widget.boardList!.widget.boardView!.widget.isNotSelecting &&
widget.draggable;

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(() { });
}
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!.startItemIndex = widget.index;
widget.boardList!.widget.boardView!.draggedItem = item;
if (widget.onStartDragItem != null) {
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 (canStartDragging) {
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;

if (widget.boardList!.widget.boardView != null) {
widget.boardList!.widget.boardView!.onDropItem = _onDropItem;
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!.startItemIndex = widget.index;
widget.boardList!.widget.boardView!.draggedItem = item;
if (widget.onStartDragItem != null) {
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(() {});
}
}
}
}

void afterFirstLayout(BuildContext context) {
try {
if (context.size != null) {
height = context.size!.height;
width = context.size!.width;
}catch(e){}
}
}

@override
Widget build(BuildContext context) {
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) {
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);
}
},
onHorizontalDragStart: (DragStartDetails _) =>
_startDrag(widget, context),
onVerticalDragStart: (DragStartDetails _) => _startDrag(widget, context),
child: widget.item,
);
}
Expand Down
Loading