diff --git a/demos/supabase-trello/lib/features/board/presentation/index.dart b/demos/supabase-trello/lib/features/board/presentation/index.dart index b71b38a..f1092bd 100644 --- a/demos/supabase-trello/lib/features/board/presentation/index.dart +++ b/demos/supabase-trello/lib/features/board/presentation/index.dart @@ -1,5 +1,3 @@ -import 'dart:ffi'; - import 'package:flutter/material.dart'; import 'package:status_alert/status_alert.dart'; import 'package:trelloappclone_flutter/features/carddetails/domain/card_detail_arguments.dart'; @@ -48,6 +46,7 @@ class _BoardScreenState extends State with Service { trello.setSelectedBoard(args.board); trello.setSelectedWorkspace(args.workspace); + // ignore: deprecated_member_use return WillPopScope( onWillPop: () async { Navigator.pushNamed(context, "/home"); @@ -239,7 +238,7 @@ class _BoardScreenState extends State with Service { BoardItem( onTapItem: (listIndex, itemIndex, state) { setState(() { - selectedList = listIndex!; + selectedList = listIndex; selectedCard = index; showCard = true; showtheCard[index] = true; @@ -423,6 +422,7 @@ class _BoardScreenState extends State with Service { return items; } + // ignore: non_constant_identifier_names List loadBoardView(List Listboards) { List data = generateBoardListObject(Listboards); lists = []; diff --git a/demos/supabase-trello/lib/features/carddetails/presentation/index.dart b/demos/supabase-trello/lib/features/carddetails/presentation/index.dart index 4249b07..ef820c4 100644 --- a/demos/supabase-trello/lib/features/carddetails/presentation/index.dart +++ b/demos/supabase-trello/lib/features/carddetails/presentation/index.dart @@ -35,7 +35,7 @@ class _CardDetailsState extends State with Service { trello.setSelectedCard(args.crd); descriptionController.text = args.crd.description ?? " "; - nameController.text = args.crd.name ?? " "; + nameController.text = args.crd.name; return Scaffold( appBar: (showChecklist || addCardDescription || editCardName) @@ -109,8 +109,8 @@ class _CardDetailsState extends State with Service { itemBuilder: (context) { return [ PopupMenuItem( - onTap: () => WidgetsBinding?.instance - ?.addPostFrameCallback((_) { + onTap: () => + WidgetsBinding.instance.addPostFrameCallback((_) { showDialog( context: context, builder: (BuildContext context) => AlertDialog( diff --git a/demos/supabase-trello/lib/features/editlabels/presentation/index.dart b/demos/supabase-trello/lib/features/editlabels/presentation/index.dart index caa1fa9..df6cec5 100644 --- a/demos/supabase-trello/lib/features/editlabels/presentation/index.dart +++ b/demos/supabase-trello/lib/features/editlabels/presentation/index.dart @@ -6,7 +6,7 @@ import '../../../utils/service.dart'; class EditLabels extends StatefulWidget { final String cardId; - const EditLabels({Key? key, required this.cardId}) : super(key: key); + const EditLabels({super.key, required this.cardId}); @override State createState() => _EditLabelsState(); diff --git a/demos/supabase-trello/lib/features/emptywidget/index.dart b/demos/supabase-trello/lib/features/emptywidget/index.dart index bb7739a..3bda2c3 100644 --- a/demos/supabase-trello/lib/features/emptywidget/index.dart +++ b/demos/supabase-trello/lib/features/emptywidget/index.dart @@ -1,3 +1,5 @@ +// ignore_for_file: constant_identifier_names, camel_case_extensions + import 'dart:math'; import 'package:flutter/material.dart'; @@ -25,7 +27,8 @@ import 'package:flutter/material.dart'; /// {@end-tool} class EmptyWidget extends StatefulWidget { - EmptyWidget({ + const EmptyWidget({ + super.key, this.title, this.subTitle, this.image, @@ -139,7 +142,7 @@ class _EmptyListWidgetState extends State ); }, child: Padding( - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(10), child: Image.asset( isPackageImage ? _packageImage.encode()! : widget.image!, fit: BoxFit.contain, @@ -156,7 +159,7 @@ class _EmptyListWidgetState extends State context, EmptyWidgetUtility.fullWidth(context) * .95), height: EmptyWidgetUtility.getHeightDimention( context, EmptyWidgetUtility.fullWidth(context) * .95), - decoration: BoxDecoration(boxShadow: [ + decoration: const BoxDecoration(boxShadow: [ BoxShadow( offset: Offset(0, 0), color: Color(0xffe2e5ed), @@ -174,7 +177,7 @@ class _EmptyListWidgetState extends State return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { if (constraints.maxHeight > constraints.maxWidth) { - return Container( + return SizedBox( height: constraints.maxWidth, width: constraints.maxWidth, child: child, @@ -191,13 +194,13 @@ class _EmptyListWidgetState extends State .typography .dense .headlineSmall! - .copyWith(color: Color(0xff9da9c7)); + .copyWith(color: const Color(0xff9da9c7)); _subtitleTextStyle = widget.subtitleTextStyle ?? Theme.of(context) .typography .dense .bodyMedium! - .copyWith(color: Color(0xffabb8d6)); + .copyWith(color: const Color(0xffabb8d6)); _packageImage = widget.packageImage; bool anyImageProvided = widget.image == null && _packageImage == null; @@ -212,8 +215,8 @@ class _EmptyListWidgetState extends State children: [ if (!widget.hideBackgroundAnimation!) RotationTransition( - child: _imageBackground(), turns: _backgroundController, + child: _imageBackground(), ), LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { @@ -221,18 +224,18 @@ class _EmptyListWidgetState extends State height: constraints.maxWidth, width: constraints.maxWidth - 30, alignment: Alignment.center, - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(10), child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ anyImageProvided - ? SizedBox() + ? const SizedBox() : Expanded( flex: 1, child: Container(), ), - anyImageProvided ? SizedBox() : _imageWidget(), + anyImageProvided ? const SizedBox() : _imageWidget(), Column( children: [ CustomText( @@ -242,7 +245,7 @@ class _EmptyListWidgetState extends State overflow: TextOverflow.clip, textAlign: TextAlign.center, ), - SizedBox( + const SizedBox( height: 10, ), CustomText( @@ -254,7 +257,7 @@ class _EmptyListWidgetState extends State ], ), anyImageProvided - ? SizedBox() + ? const SizedBox() : Expanded( flex: 1, child: Container(), @@ -329,14 +332,13 @@ class EmptyWidgetUtility { class CustomText extends StatefulWidget { const CustomText( - {Key? key, + {super.key, this.msg, this.style, this.textAlign, this.overflow, this.context, - this.softwrap}) - : super(key: key); + this.softwrap}); final BuildContext? context; final String? msg; @@ -345,6 +347,8 @@ class CustomText extends StatefulWidget { final TextStyle? style; final TextAlign? textAlign; + @override + // ignore: library_private_types_in_public_api _CustomTextState createState() => _CustomTextState(); } diff --git a/demos/supabase-trello/lib/features/home/presentation/index.dart b/demos/supabase-trello/lib/features/home/presentation/index.dart index ab6f613..ec0287a 100644 --- a/demos/supabase-trello/lib/features/home/presentation/index.dart +++ b/demos/supabase-trello/lib/features/home/presentation/index.dart @@ -3,11 +3,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_expandable_fab/flutter_expandable_fab.dart'; import 'package:logging/logging.dart'; -import 'package:powersync/powersync.dart' as PowerSync; +import 'package:powersync/powersync.dart' as power_sync; import 'package:trelloappclone_flutter/features/emptywidget/index.dart'; import 'package:trelloappclone_flutter/main.dart'; -import 'package:trelloappclone_flutter/models/board.dart'; -import 'package:trelloappclone_flutter/models/workspace.dart'; import 'package:trelloappclone_flutter/features/board/domain/board_arguments.dart'; import 'package:trelloappclone_flutter/features/board/presentation/index.dart'; import 'package:trelloappclone_flutter/protocol/data_client.dart'; @@ -28,8 +26,8 @@ class Home extends StatefulWidget { } class _HomeState extends State with Service { - late PowerSync.SyncStatus _connectionState; - StreamSubscription? _syncStatusSubscription; + late power_sync.SyncStatus _connectionState; + StreamSubscription? _syncStatusSubscription; @override void initState() { @@ -93,20 +91,20 @@ class _HomeState extends State with Service { Column(children: buildWorkspacesAndBoards(children))); } } - return Center( + return const Center( child: Padding( - padding: const EdgeInsets.all(20.0), + padding: EdgeInsets.all(20.0), child: EmptyWidget( image: null, packageImage: PackageImage.Image_1, title: 'No Boards', subTitle: 'Create your first Trello board', - titleTextStyle: const TextStyle( + titleTextStyle: TextStyle( fontSize: 22, color: Color(0xff9da9c7), fontWeight: FontWeight.w500, ), - subtitleTextStyle: const TextStyle( + subtitleTextStyle: TextStyle( fontSize: 14, color: Color(0xffabb8d6), ), diff --git a/demos/supabase-trello/lib/main.dart b/demos/supabase-trello/lib/main.dart index c5534a4..139e95f 100644 --- a/demos/supabase-trello/lib/main.dart +++ b/demos/supabase-trello/lib/main.dart @@ -1,10 +1,10 @@ -import 'package:flutter/foundation.dart'; +// ignore_for_file: avoid_print + import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import 'package:trelloappclone_flutter/features/generateworkspace/presentation/index.dart'; import 'package:trelloappclone_flutter/utils/trello_provider.dart'; -import 'package:trelloappclone_flutter/models/user.dart'; import 'package:trelloappclone_flutter/protocol/data_client.dart'; import 'package:logging/logging.dart'; @@ -71,7 +71,7 @@ void main() async { } class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { diff --git a/demos/supabase-trello/lib/protocol/data_client.dart b/demos/supabase-trello/lib/protocol/data_client.dart index 47acf18..5afa61f 100644 --- a/demos/supabase-trello/lib/protocol/data_client.dart +++ b/demos/supabase-trello/lib/protocol/data_client.dart @@ -1,3 +1,5 @@ +// ignore_for_file: library_private_types_in_public_api + library powersync_client; import 'package:powersync/powersync.dart'; @@ -21,45 +23,51 @@ class _Repository { } class _ActivityRepository extends _Repository { - _ActivityRepository(DataClient client) : super(client); + _ActivityRepository(super.client); Future createActivity(Activity activity) async { - final results = await client.getDBExecutor().execute('''INSERT INTO + final results = await client.getDBExecutor().execute( + '''INSERT INTO activity(id, workspaceId, boardId, userId, cardId, description, dateCreated) VALUES(?, ?, ?, ?, ?, ?, datetime()) - RETURNING *''', [ - activity.id, - activity.workspaceId, - activity.boardId, - activity.userId, - activity.cardId, - activity.description - ]); + RETURNING *''', + [ + activity.id, + activity.workspaceId, + activity.boardId, + activity.userId, + activity.cardId, + activity.description + ]); return results.isNotEmpty; } Future> getActivities(Cardlist cardlist) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM activity WHERE cardId = ? ORDER BY dateCreated DESC - ''', [cardlist.id]); + ''', + [cardlist.id]); return results.map((row) => Activity.fromRow(row)).toList(); } } class _AttachmentRepository extends _Repository { - _AttachmentRepository(DataClient client) : super(client); + _AttachmentRepository(super.client); Future addAttachment(Attachment attachment) async { - final results = await client.getDBExecutor().execute('''INSERT INTO + final results = await client.getDBExecutor().execute( + '''INSERT INTO attachment(id, workspaceId, userId, cardId, attachment) VALUES(?, ?, ?, ?, ?) - RETURNING *''', [ - attachment.id, - attachment.workspaceId, - attachment.userId, - attachment.cardId, - attachment.attachment - ]); + RETURNING *''', + [ + attachment.id, + attachment.workspaceId, + attachment.userId, + attachment.cardId, + attachment.attachment + ]); if (results.isEmpty) { throw Exception("Failed to add attachment"); } else { @@ -75,22 +83,26 @@ class _AttachmentRepository extends _Repository { } class _BoardRepository extends _Repository { - _BoardRepository(DataClient client) : super(client); + _BoardRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO board(id, userId, workspaceId, name, description, visibility, background, starred, enableCover, watch, availableOffline, label, emailAddress, commenting, memberType, pinned, selfJoin, close) VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18) '''; - String get updateQuery => ''' + String get updateQuery => + ''' UPDATE board set userId = ?1, workspaceId = ?2, name = ?3, description = ?4, visibility = ?5, background = ?6, starred = ?7, enableCover = ?8, watch = ?9, availableOffline = ?10, label = ?11, emailAddress = ?12, commenting = ?13, memberType = ?14, pinned = ?15, selfJoin = ?16, close = ?17 WHERE id = ?18 '''; Future createBoard(Board board) async { - final results = await client.getDBExecutor().execute(''' + final results = await client + .getDBExecutor() + .execute(''' $insertQuery RETURNING *''', [ board.id, board.userId, @@ -150,14 +162,18 @@ class _BoardRepository extends _Repository { } Future getWorkspaceForBoard(Board board) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM workspace WHERE id = ? - ''', [board.workspaceId]); + ''', + [board.workspaceId]); return results.map((row) => Workspace.fromRow(row)).firstOrNull; } Future> getAllBoards() async { - final results = await client.getDBExecutor().execute(''' + final results = await client + .getDBExecutor() + .execute(''' SELECT * FROM board '''); return results.map((row) => Board.fromRow(row)).toList(); @@ -165,9 +181,10 @@ class _BoardRepository extends _Repository { } class _CardlistRepository extends _Repository { - _CardlistRepository(DataClient client) : super(client); + _CardlistRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO card(id, workspaceId, listId, userId, name, description, startDate, dueDate, attachment, archived, checklist, comments, rank) VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13) @@ -197,7 +214,8 @@ class _CardlistRepository extends _Repository { } } - String get updateQuery => ''' + String get updateQuery => + ''' UPDATE card set listId = ?1, userId = ?2, name = ?3, description = ?4, startDate = ?5, dueDate = ?6, attachment = ?7, archived = ?8, checklist = ?9, comments = ?10, rank = ?11 WHERE id = ?12 @@ -229,17 +247,20 @@ class _CardlistRepository extends _Repository { } Future> getCardsforList(String listId) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM card WHERE listId = ? AND archived = 0 ORDER BY rank ASC - ''', [listId]); + ''', + [listId]); return results.map((row) => Cardlist.fromRow(row)).toList(); } } class _CheckListRepository extends _Repository { - _CheckListRepository(DataClient client) : super(client); + _CheckListRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO checklist(id, workspaceId, cardId, name, status) VALUES(?1, ?2, ?3, ?4, ?5) @@ -261,7 +282,8 @@ class _CheckListRepository extends _Repository { } } - String get updateQuery => ''' + String get updateQuery => + ''' UPDATE checklist set cardId = ?1, name = ?2, status = ?3 WHERE id = ?4 @@ -285,16 +307,20 @@ class _CheckListRepository extends _Repository { } Future> getChecklists(Cardlist crd) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM checklist WHERE cardId = ? - ''', [crd.id]); + ''', + [crd.id]); return results.map((row) => Checklist.fromRow(row)).toList(); } Future deleteChecklist(Cardlist crd) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT COUNT(*) FROM checklist WHERE cardId = ? - ''', [crd.id]); + ''', + [crd.id]); await client .getDBExecutor() .execute('DELETE FROM checklist WHERE cardId = ?', [crd.id]); @@ -303,9 +329,10 @@ class _CheckListRepository extends _Repository { } class _CommentRepository extends _Repository { - _CommentRepository(DataClient client) : super(client); + _CommentRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO comment(id, workspaceId, cardId, userId, description) VALUES(?1, ?2, ?3, ?4, ?5) @@ -327,7 +354,8 @@ class _CommentRepository extends _Repository { } } - String get updateQuery => ''' + String get updateQuery => + ''' UPDATE comment set cardId = ?1, userId = ?2, description = ?3 WHERE id = ?4 @@ -341,13 +369,15 @@ class _CommentRepository extends _Repository { } class _ListboardRepository extends _Repository { - _ListboardRepository(DataClient client) : super(client); + _ListboardRepository(super.client); Future> getListsByBoard({required String boardId}) async { //first we get the listboards - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM listboard WHERE boardId = ? - ''', [boardId]); + ''', + [boardId]); List lists = results.map((row) => Listboard.fromRow(row)).toList(); @@ -367,9 +397,11 @@ class _ListboardRepository extends _Repository { Stream> watchListsByBoard({required String boardId}) { //first we get the listboards - return client.getDBExecutor().watch(''' + return client.getDBExecutor().watch( + ''' SELECT * FROM listboard WHERE boardId = ? ORDER BY listOrder ASC - ''', parameters: [boardId]).asyncMap((event) async { + ''', + parameters: [boardId]).asyncMap((event) async { List lists = event.map((row) => Listboard.fromRow(row)).toList(); @@ -388,7 +420,8 @@ class _ListboardRepository extends _Repository { }); } - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO listboard(id, workspaceId, boardId, userId, name, archived, listOrder) VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7) @@ -412,7 +445,8 @@ class _ListboardRepository extends _Repository { } } - String get updateQuery => ''' + String get updateQuery => + ''' UPDATE listboard set listOrder = ?1 WHERE id = ?2 @@ -435,18 +469,22 @@ class _ListboardRepository extends _Repository { int numCards = cards.length; //we set each of the cards in the list to archived = true - sqlContext.executeBatch(''' + sqlContext.executeBatch( + ''' UPDATE card SET archived = 1 WHERE id = ? - ''', cards.map((card) => [card.id]).toList()); + ''', + cards.map((card) => [card.id]).toList()); //touch listboard to trigger update via stream listeners on Listboard - sqlContext.execute(''' + sqlContext.execute( + ''' UPDATE listboard SET archived = 0 WHERE id = ? - ''', [list.id]); + ''', + [list.id]); list.cards = []; return numCards; @@ -456,9 +494,10 @@ class _ListboardRepository extends _Repository { } class _MemberRepository extends _Repository { - _MemberRepository(DataClient client) : super(client); + _MemberRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO member(id, workspaceId, userId, name, role) VALUES(?1, ?2, ?3, ?4, ?5) @@ -482,9 +521,11 @@ class _MemberRepository extends _Repository { Future> getMembersByWorkspace( {required String workspaceId}) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM member WHERE workspaceId = ? - ''', [workspaceId]); + ''', + [workspaceId]); return results.map((row) => Member.fromRow(row)).toList(); } @@ -514,9 +555,10 @@ class _MemberRepository extends _Repository { } class _UserRepository extends _Repository { - _UserRepository(DataClient client) : super(client); + _UserRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO trellouser(id, name, email, password) VALUES(?1, ?2, ?3, ?4) @@ -536,30 +578,37 @@ class _UserRepository extends _Repository { /// We excpect only one record in the local trellouser table /// if somebody has logged in and not logged out again Future getUser() async { - final results = await client.getDBExecutor().execute(''' + final results = await client + .getDBExecutor() + .execute(''' SELECT * FROM trellouser'''); return results.map((row) => TrelloUser.fromRow(row)).firstOrNull; } Future getUserById({required String userId}) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM trellouser WHERE id = ? - ''', [userId]); + ''', + [userId]); return results.map((row) => TrelloUser.fromRow(row)).firstOrNull; } Future checkUserExists(String email) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM trellouser WHERE email = ? - ''', [email]); + ''', + [email]); return results.map((row) => TrelloUser.fromRow(row)).firstOrNull; } } class _WorkspaceRepository extends _Repository { - _WorkspaceRepository(DataClient client) : super(client); + _WorkspaceRepository(super.client); - String get insertQuery => ''' + String get insertQuery => + ''' INSERT INTO workspace(id, userId, name, description, visibility) VALUES(?1, ?2, ?3, ?4, ?5) @@ -579,9 +628,11 @@ class _WorkspaceRepository extends _Repository { Future> getWorkspacesByUser({required String userId}) async { //First we get the workspaces - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM workspace WHERE userId = ? - ''', [userId]); + ''', + [userId]); List workspaces = results.map((row) => Workspace.fromRow(row)).toList(); @@ -616,9 +667,11 @@ class _WorkspaceRepository extends _Repository { } Future getWorkspaceById({required String workspaceId}) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM workspace WHERE id = ? - ''', [workspaceId]); + ''', + [workspaceId]); Workspace workspace = Workspace.fromRow(results.first); List members = await client.member.getMembersByWorkspace(workspaceId: workspaceId); @@ -628,9 +681,11 @@ class _WorkspaceRepository extends _Repository { Future> getBoardsByWorkspace( {required String workspaceId}) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM board WHERE workspaceId = ? - ''', [workspaceId]); + ''', + [workspaceId]); List boards = results.map((row) => Board.fromRow(row)).toList(); @@ -643,9 +698,11 @@ class _WorkspaceRepository extends _Repository { } Stream> watchBoardsByWorkspace({required String workspaceId}) { - return client.getDBExecutor().watch(''' + return client.getDBExecutor().watch( + ''' SELECT * FROM board WHERE workspaceId = ? - ''', parameters: [workspaceId]).asyncMap((event) async { + ''', + parameters: [workspaceId]).asyncMap((event) async { List boards = event.map((row) => Board.fromRow(row)).toList(); for (Board board in boards) { @@ -658,17 +715,19 @@ class _WorkspaceRepository extends _Repository { } Future updateWorkspace(Workspace workspace) async { - await client.getDBExecutor().execute(''' + await client.getDBExecutor().execute( + ''' UPDATE workspace set userId = ?1, name = ?2, description = ?3, visibility = ?4 WHERE id = ?5 - ''', [ - workspace.userId, - workspace.name, - workspace.description, - workspace.visibility, - workspace.id - ]); + ''', + [ + workspace.userId, + workspace.name, + workspace.description, + workspace.visibility, + workspace.id + ]); return true; } @@ -681,19 +740,21 @@ class _WorkspaceRepository extends _Repository { } class _BoardLabelRepository extends _Repository { - _BoardLabelRepository(DataClient client) : super(client); + _BoardLabelRepository(super.client); Future createBoardLabel(BoardLabel boardLabel) async { - final results = await client.getDBExecutor().execute('''INSERT INTO + final results = await client.getDBExecutor().execute( + '''INSERT INTO board_label(id, boardId, workspaceId, title, color, dateCreated) VALUES(?, ?, ?, ?, ?, datetime()) - RETURNING *''', [ - boardLabel.id, - boardLabel.boardId, - boardLabel.workspaceId, - boardLabel.title, - boardLabel.color - ]); + RETURNING *''', + [ + boardLabel.id, + boardLabel.boardId, + boardLabel.workspaceId, + boardLabel.title, + boardLabel.color + ]); if (results.isEmpty) { throw Exception("Failed to add BoardLabel"); } else { @@ -702,36 +763,42 @@ class _BoardLabelRepository extends _Repository { } Future updateBoardLabel(BoardLabel boardLabel) async { - await client.getDBExecutor().execute(''' + await client.getDBExecutor().execute( + ''' UPDATE board_label set title = ?1 WHERE id = ?2 - ''', [boardLabel.title, boardLabel.id]); + ''', + [boardLabel.title, boardLabel.id]); return true; } Future> getBoardLabels(Board board) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM board_label WHERE boardId = ? ORDER BY dateCreated DESC - ''', [board.id]); + ''', + [board.id]); return results.map((row) => BoardLabel.fromRow(row)).toList(); } } class _CardLabelRepository extends _Repository { - _CardLabelRepository(DataClient client) : super(client); + _CardLabelRepository(super.client); Future createCardLabel(CardLabel cardLabel) async { - final results = await client.getDBExecutor().execute('''INSERT INTO + final results = await client.getDBExecutor().execute( + '''INSERT INTO card_label(id, cardId, boardId, workspaceId, boardLabelId, dateCreated) VALUES(?, ?, ?, ?, ?, datetime()) - RETURNING *''', [ - cardLabel.id, - cardLabel.cardId, - cardLabel.boardId, - cardLabel.workspaceId, - cardLabel.boardLabelId, - ]); + RETURNING *''', + [ + cardLabel.id, + cardLabel.cardId, + cardLabel.boardId, + cardLabel.workspaceId, + cardLabel.boardLabelId, + ]); if (results.isEmpty) { throw Exception("Failed to add CardLabel"); } else { @@ -746,9 +813,11 @@ class _CardLabelRepository extends _Repository { } Future> getCardLabels(Cardlist card) async { - final results = await client.getDBExecutor().execute(''' + final results = await client.getDBExecutor().execute( + ''' SELECT * FROM card_label WHERE cardId = ? ORDER BY dateCreated DESC - ''', [card.id]); + ''', + [card.id]); return results.map((row) => CardLabel.fromRow(row)).toList(); } } @@ -805,8 +874,9 @@ class DataClient { String? userId = _powerSyncClient.getUserId(); if (userId != null) { return user.getUserById(userId: userId); - } else + } else { return null; + } } Future logOut() async { @@ -817,13 +887,11 @@ class DataClient { String userId = await _powerSyncClient.loginWithEmail(email, password); TrelloUser? storedUser = await user.getUserById(userId: userId); - if (storedUser == null) { - storedUser = await user.createUser(TrelloUser( - id: userId, - name: email.split('@')[0], - email: email, - password: password)); - } + storedUser ??= await user.createUser(TrelloUser( + id: userId, + name: email.split('@')[0], + email: email, + password: password)); return storedUser; } @@ -831,7 +899,7 @@ class DataClient { String name, String email, String password) async { TrelloUser? storedUser = await user.checkUserExists(email); if (storedUser != null) { - throw new Exception('User for email already exists. Use Login instead.'); + throw Exception('User for email already exists. Use Login instead.'); } return _powerSyncClient.signupWithEmail(name, email, password); } diff --git a/demos/supabase-trello/lib/utils/data_generator.dart b/demos/supabase-trello/lib/utils/data_generator.dart index 9c821fb..5a7c6f3 100644 --- a/demos/supabase-trello/lib/utils/data_generator.dart +++ b/demos/supabase-trello/lib/utils/data_generator.dart @@ -1,6 +1,7 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:math'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:random_name_generator/random_name_generator.dart'; import 'package:status_alert/status_alert.dart'; @@ -114,10 +115,7 @@ class DataGenerator with Service { card: newCard.id, description: '${randomNames.name()} updated this card'); } - ; } - ; } - ; } } diff --git a/demos/supabase-trello/lib/utils/service.dart b/demos/supabase-trello/lib/utils/service.dart index d9727ab..c32fc85 100644 --- a/demos/supabase-trello/lib/utils/service.dart +++ b/demos/supabase-trello/lib/utils/service.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:convert'; import 'dart:developer'; @@ -20,11 +22,12 @@ import 'package:trelloappclone_flutter/models/board_label.dart'; import 'package:trelloappclone_flutter/models/card_label.dart'; import 'package:trelloappclone_flutter/models/attachment.dart'; +// ignore: depend_on_referenced_packages import 'package:uuid/uuid.dart'; import '../main.dart'; -var uuid = Uuid(); +var uuid = const Uuid(); mixin Service { randomUuid() { diff --git a/demos/supabase-trello/lib/widgets/thirdparty/board_item.dart b/demos/supabase-trello/lib/widgets/thirdparty/board_item.dart index da106d6..4b660d3 100644 --- a/demos/supabase-trello/lib/widgets/thirdparty/board_item.dart +++ b/demos/supabase-trello/lib/widgets/thirdparty/board_item.dart @@ -3,13 +3,14 @@ import 'package:flutter/widgets.dart'; import 'board_list.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 OnStartDragItem = void Function( int? listIndex, int? itemIndex, BoardItemState state); -typedef void OnDragItem(int oldListIndex, int oldItemIndex, int newListIndex, - int newItemIndex, BoardItemState state); +typedef OnDragItem = void Function(int oldListIndex, int oldItemIndex, + int newListIndex, int newItemIndex, BoardItemState state); class BoardItem extends StatefulWidget { final BoardListState? boardList; @@ -22,7 +23,7 @@ class BoardItem extends StatefulWidget { final bool draggable; const BoardItem( - {Key? key, + {super.key, this.boardList, this.item, this.index, @@ -30,8 +31,7 @@ class BoardItem extends StatefulWidget { this.onTapItem, this.onStartDragItem, this.draggable = true, - this.onDragItem}) - : super(key: key); + this.onDragItem}); @override State createState() { @@ -91,15 +91,14 @@ class BoardItemState extends State } void afterFirstLayout(BuildContext context) { - try { - height = context.size!.height; - width = context.size!.width; - } catch (e) {} + height = context.size!.height; + width = context.size!.width; } @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!); diff --git a/demos/supabase-trello/lib/widgets/thirdparty/board_list.dart b/demos/supabase-trello/lib/widgets/thirdparty/board_list.dart index 7e9c1d6..65a0469 100644 --- a/demos/supabase-trello/lib/widgets/thirdparty/board_list.dart +++ b/demos/supabase-trello/lib/widgets/thirdparty/board_list.dart @@ -3,9 +3,9 @@ import 'boardview.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -typedef void OnDropList(int? listIndex, int? oldListIndex); -typedef void OnTapList(int? listIndex); -typedef void OnStartDragList(int? listIndex); +typedef OnDropList = void Function(int? listIndex, int? oldListIndex); +typedef OnTapList = void Function(int? listIndex); +typedef OnStartDragList = void Function(int? listIndex); class BoardList extends StatefulWidget { final List? header; @@ -20,7 +20,7 @@ class BoardList extends StatefulWidget { final bool draggable; const BoardList({ - Key? key, + super.key, this.header, this.items, this.footer, @@ -32,7 +32,7 @@ class BoardList extends StatefulWidget { this.onDropList, this.onTapList, this.onStartDragList, - }) : super(key: key); + }); final int? index; @@ -45,7 +45,7 @@ class BoardList extends StatefulWidget { class BoardListState extends State with AutomaticKeepAliveClientMixin { List itemStates = []; - ScrollController boardListController = new ScrollController(); + ScrollController boardListController = ScrollController(); void onDropList(int? listIndex) { if (widget.onDropList != null) { @@ -80,10 +80,12 @@ class BoardListState extends State @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) { + // ignore: unused_local_variable + Color? headerBackgroundColor = const Color.fromARGB(255, 255, 255, 255); headerBackgroundColor = widget.headerBackgroundColor; } listWidgets.add(GestureDetector( @@ -184,7 +186,7 @@ class BoardListState extends State child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, - children: listWidgets as List, + children: listWidgets, )); } } diff --git a/demos/supabase-trello/lib/widgets/thirdparty/boardview.dart b/demos/supabase-trello/lib/widgets/thirdparty/boardview.dart index 73db6ef..94d90ad 100644 --- a/demos/supabase-trello/lib/widgets/thirdparty/boardview.dart +++ b/demos/supabase-trello/lib/widgets/thirdparty/boardview.dart @@ -3,10 +3,10 @@ library boardview; import 'boardview_controller.dart'; import 'vs_scrollbar.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'dart:core'; import 'board_list.dart'; +// ignore: must_be_immutable class BoardView extends StatefulWidget { final List? lists; final double width; @@ -21,7 +21,7 @@ class BoardView extends StatefulWidget { Function(bool)? itemInMiddleWidget; OnDropBottomWidget? onDropItemInMiddleWidget; BoardView( - {Key? key, + {super.key, this.itemInMiddleWidget, this.scrollbar, this.scrollbarStyle, @@ -32,8 +32,7 @@ class BoardView extends StatefulWidget { this.lists, this.width = 280, this.middleWidget, - this.bottomPadding}) - : super(key: key); + this.bottomPadding}); @override State createState() { @@ -41,10 +40,10 @@ class BoardView extends StatefulWidget { } } -typedef void OnDropBottomWidget( +typedef OnDropBottomWidget = void Function( int? listIndex, int? itemIndex, double percentX); -typedef void OnDropItem(int? listIndex, int? itemIndex); -typedef void OnDropList(int? listIndex); +typedef OnDropItem = void Function(int? listIndex, int? itemIndex); +typedef OnDropList = void Function(int? listIndex); class BoardViewState extends State with AutomaticKeepAliveClientMixin { @@ -71,7 +70,7 @@ class BoardViewState extends State bool canDrag = true; - ScrollController boardViewController = new ScrollController(); + ScrollController boardViewController = ScrollController(); List listStates = []; @@ -82,8 +81,9 @@ class BoardViewState extends State bool _isInWidget = false; - GlobalKey _middleWidgetKey = GlobalKey(); + final GlobalKey _middleWidgetKey = GlobalKey(); + // ignore: prefer_typing_uninitialized_variables var pointer; @override @@ -166,18 +166,18 @@ class BoardViewState extends State 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) + duration: const 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), () { + Future.delayed(Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); @@ -201,8 +201,7 @@ class BoardViewState extends State 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) { + if (listStates[draggedListIndex!].itemStates[i].mounted) { RenderBox box = listStates[draggedListIndex!] .itemStates[i] .context @@ -224,12 +223,12 @@ class BoardViewState extends State 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) + duration: const Duration(milliseconds: 400), curve: Curves.ease) .whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; @@ -243,7 +242,7 @@ class BoardViewState extends State Offset itemPos = box.localToGlobal(Offset.zero); topItemY = itemPos.dy; bottomItemY = itemPos.dy + box.size.height; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + Future.delayed(Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); @@ -264,11 +263,11 @@ class BoardViewState extends State 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), + duration: Duration(milliseconds: widget.dragDelay), curve: Curves.ease) .whenComplete(() { RenderBox object = @@ -276,7 +275,7 @@ class BoardViewState extends State Offset pos = object.localToGlobal(Offset.zero); leftListX = pos.dx; rightListX = pos.dx + object.size.width; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + Future.delayed(Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); @@ -300,8 +299,7 @@ class BoardViewState extends State 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) { + if (listStates[draggedListIndex!].itemStates[i].mounted) { RenderBox box = listStates[draggedListIndex!] .itemStates[i] .context @@ -323,12 +321,12 @@ class BoardViewState extends State 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) + duration: const Duration(milliseconds: 400), curve: Curves.ease) .whenComplete(() { RenderBox object = listStates[tempListIndex!].context.findRenderObject() as RenderBox; @@ -342,7 +340,7 @@ class BoardViewState extends State Offset itemPos = box.localToGlobal(Offset.zero); topItemY = itemPos.dy; bottomItemY = itemPos.dy + box.size.height; - Future.delayed(new Duration(milliseconds: widget.dragDelay), () { + Future.delayed(Duration(milliseconds: widget.dragDelay), () { canDrag = true; }); }); @@ -356,14 +354,11 @@ class BoardViewState extends State @override Widget build(BuildContext context) { - // print("dy:${dy}"); - // print("topListY:${topListY}"); - // print("bottomListY:${bottomListY}"); + super.build(context); if (boardViewController.hasClients) { - WidgetsBinding.instance!.addPostFrameCallback((Duration duration) { - try { - boardViewController.position.didUpdateScrollPositionBy(0); - } catch (e) {} + WidgetsBinding.instance.addPostFrameCallback((Duration duration) { + boardViewController.position.didUpdateScrollPositionBy(0); + // ignore: no_leading_underscores_for_local_identifiers bool _shown = boardViewController.position.maxScrollExtent != 0; if (_shown != shown) { setState(() { @@ -373,14 +368,13 @@ class BoardViewState extends State }); } Widget listWidget = ListView.builder( - physics: ClampingScrollPhysics(), + physics: const ClampingScrollPhysics(), itemCount: widget.lists!.length, scrollDirection: Axis.horizontal, controller: boardViewController, itemBuilder: (BuildContext context, int index) { // if index does not exist on lists if (widget.lists!.length <= index) { - print('Returned empty container'); return Container(); } @@ -437,9 +431,9 @@ class BoardViewState extends State controller: boardViewController, showTrackOnHover: true, // default false isAlwaysShown: shown && widget.lists!.length > 1, // default false - scrollbarFadeDuration: Duration( + scrollbarFadeDuration: const Duration( milliseconds: 500), // default : Duration(milliseconds: 300) - scrollbarTimeToFade: Duration( + scrollbarTimeToFade: const Duration( milliseconds: 800), // default : Duration(milliseconds: 600) style: widget.scrollbarStyle != null ? VsScrollbarStyle( @@ -447,7 +441,7 @@ class BoardViewState extends State radius: widget.scrollbarStyle!.radius, thickness: widget.scrollbarStyle!.thickness, color: widget.scrollbarStyle!.color) - : VsScrollbarStyle(), + : const VsScrollbarStyle(), child: listWidget); } List stackWidgets = [listWidget]; @@ -467,8 +461,7 @@ class BoardViewState extends State offsetY != null && dx != null && dy != null && - height != null && - widget.width != null) { + height != null) { if (canDrag && dxInit != null && dyInit != null && !isInBottomWidget) { if (draggedItemIndex != null && draggedItem != null && @@ -477,10 +470,10 @@ class BoardViewState extends State //dragging item if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { //scroll left - if (boardViewController != null && boardViewController.hasClients) { + if (boardViewController.hasClients) { boardViewController.animateTo( boardViewController.position.pixels - 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease); if (listStates[draggedListIndex!].mounted) { RenderBox object = listStates[draggedListIndex!] @@ -495,10 +488,10 @@ class BoardViewState extends State if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { //scroll right - if (boardViewController != null && boardViewController.hasClients) { + if (boardViewController.hasClients) { boardViewController.animateTo( boardViewController.position.pixels + 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease); if (listStates[draggedListIndex!].mounted) { RenderBox object = listStates[draggedListIndex!] @@ -521,8 +514,7 @@ class BoardViewState extends State } if (dy! < topListY! + 70) { //scroll up - if (listStates[draggedListIndex!].boardListController != null && - listStates[draggedListIndex!].boardListController.hasClients && + if (listStates[draggedListIndex!].boardListController.hasClients && !isScrolling) { isScrolling = true; double pos = listStates[draggedListIndex!] @@ -537,14 +529,14 @@ class BoardViewState extends State .position .pixels - 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease) .whenComplete(() { pos -= listStates[draggedListIndex!] .boardListController .position .pixels; - if (initialY == null) initialY = 0; + initialY ??= 0; // if(widget.boardViewController != null) { // initialY -= pos; // } @@ -574,17 +566,16 @@ class BoardViewState extends State double? tempBottom = bottomListY; if (widget.middleWidget != null) { if (_middleWidgetKey.currentContext != null) { + // ignore: no_leading_underscores_for_local_identifiers RenderBox _box = _middleWidgetKey.currentContext! .findRenderObject() as RenderBox; tempBottom = _box.size.height; - print("tempBottom:${tempBottom}"); } } if (dy! > tempBottom! - 70) { //scroll down if (listStates.length < draggedListIndex! && - listStates[draggedListIndex!].boardListController != null && listStates[draggedListIndex!].boardListController.hasClients) { isScrolling = true; double pos = listStates[draggedListIndex!] @@ -599,7 +590,7 @@ class BoardViewState extends State .position .pixels + 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease) .whenComplete(() { pos -= listStates[draggedListIndex!] @@ -607,9 +598,6 @@ class BoardViewState extends State .position .pixels; initialY ??= 0; -// if(widget.boardViewController != null) { -// initialY -= pos; -// } isScrolling = false; if (topItemY != null) { topItemY = topItemY! + pos; @@ -638,10 +626,10 @@ class BoardViewState extends State //dragging list if (0 <= draggedListIndex! - 1 && dx! < leftListX! + 45) { //scroll left - if (boardViewController != null && boardViewController.hasClients) { + if (boardViewController.hasClients) { boardViewController.animateTo( boardViewController.position.pixels - 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease); if (leftListX != null) { leftListX = leftListX! + 5; @@ -655,10 +643,10 @@ class BoardViewState extends State if (widget.lists!.length > draggedListIndex! + 1 && dx! > rightListX! - 45) { //scroll right - if (boardViewController != null && boardViewController.hasClients) { + if (boardViewController.hasClients) { boardViewController.animateTo( boardViewController.position.pixels + 5, - duration: new Duration(milliseconds: 10), + duration: const Duration(milliseconds: 10), curve: Curves.ease); if (leftListX != null) { leftListX = leftListX! - 5; @@ -683,7 +671,7 @@ class BoardViewState extends State stackWidgets .add(Container(key: _middleWidgetKey, child: widget.middleWidget)); } - WidgetsBinding.instance!.addPostFrameCallback((timeStamp) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { if (mounted) { setState(() {}); } @@ -691,94 +679,89 @@ class BoardViewState extends State stackWidgets.add(Positioned( width: widget.width, height: height, - child: Opacity(opacity: .7, child: draggedItem), left: (dx! - offsetX!) + initialX!, top: (dy! - offsetY!) + initialY!, + child: Opacity(opacity: .7, child: draggedItem), )); } - return Container( - child: Listener( - onPointerMove: (opm) { - if (draggedItem != null) { - if (dxInit == null) { - dxInit = opm.position.dx; - } - if (dyInit == null) { - dyInit = opm.position.dy; - } - dx = opm.position.dx; - dy = opm.position.dy; - if (mounted) { - setState(() {}); - } - } - }, - onPointerDown: (opd) { - RenderBox box = context.findRenderObject() as RenderBox; - Offset pos = box.localToGlobal(opd.position); - offsetX = pos.dx; - offsetY = pos.dy; - pointer = opd; - if (mounted) { - setState(() {}); - } - }, - onPointerUp: (opu) { - if (onDropItem != null) { - int? tempDraggedItemIndex = draggedItemIndex; - int? tempDraggedListIndex = draggedListIndex; - int? startDraggedItemIndex = startItemIndex; - int? startDraggedListIndex = startListIndex; - - if (_isInWidget && widget.onDropItemInMiddleWidget != null) { - onDropItem!(startDraggedListIndex, startDraggedItemIndex); - 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) { - onDropList!(tempDraggedListIndex); - widget.onDropItemInMiddleWidget!(tempDraggedListIndex, null, - opu.position.dx / MediaQuery.of(context).size.width); - } else { - onDropList!(tempDraggedListIndex); - } - } - draggedItem = null; - offsetX = null; - offsetY = null; - initialX = null; - initialY = null; - dx = null; - dy = null; - draggedItemIndex = null; - draggedListIndex = null; - onDropItem = null; - onDropList = null; - dxInit = null; - dyInit = null; - leftListX = null; - rightListX = null; - topListY = null; - bottomListY = null; - topItemY = null; - bottomItemY = null; - startListIndex = null; - startItemIndex = null; - if (mounted) { - setState(() {}); - } - }, - child: new Stack( - children: stackWidgets, - ))); + return Listener( + onPointerMove: (opm) { + if (draggedItem != null) { + dxInit ??= opm.position.dx; + dyInit ??= opm.position.dy; + dx = opm.position.dx; + dy = opm.position.dy; + if (mounted) { + setState(() {}); + } + } + }, + onPointerDown: (opd) { + RenderBox box = context.findRenderObject() as RenderBox; + Offset pos = box.localToGlobal(opd.position); + offsetX = pos.dx; + offsetY = pos.dy; + pointer = opd; + if (mounted) { + setState(() {}); + } + }, + onPointerUp: (opu) { + if (onDropItem != null) { + int? tempDraggedItemIndex = draggedItemIndex; + int? tempDraggedListIndex = draggedListIndex; + int? startDraggedItemIndex = startItemIndex; + int? startDraggedListIndex = startListIndex; + + if (_isInWidget && widget.onDropItemInMiddleWidget != null) { + onDropItem!(startDraggedListIndex, startDraggedItemIndex); + 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) { + onDropList!(tempDraggedListIndex); + widget.onDropItemInMiddleWidget!(tempDraggedListIndex, null, + opu.position.dx / MediaQuery.of(context).size.width); + } else { + onDropList!(tempDraggedListIndex); + } + } + draggedItem = null; + offsetX = null; + offsetY = null; + initialX = null; + initialY = null; + dx = null; + dy = null; + draggedItemIndex = null; + draggedListIndex = null; + onDropItem = null; + onDropList = null; + dxInit = null; + dyInit = null; + leftListX = null; + rightListX = null; + topListY = null; + bottomListY = null; + topItemY = null; + bottomItemY = null; + startListIndex = null; + startItemIndex = null; + if (mounted) { + setState(() {}); + } + }, + child: Stack( + children: stackWidgets, + )); } void run() { diff --git a/demos/supabase-trello/lib/widgets/thirdparty/boardview_controller.dart b/demos/supabase-trello/lib/widgets/thirdparty/boardview_controller.dart index 72457e1..8c93bd7 100644 --- a/demos/supabase-trello/lib/widgets/thirdparty/boardview_controller.dart +++ b/demos/supabase-trello/lib/widgets/thirdparty/boardview_controller.dart @@ -9,8 +9,7 @@ class BoardViewController { Future animateTo(int index, {Duration? duration, Curve? curve}) async { double offset = index * state.widget.width; - if (state.boardViewController != null && - state.boardViewController.hasClients) { + if (state.boardViewController.hasClients) { await state.boardViewController .animateTo(offset, duration: duration!, curve: curve!); } diff --git a/demos/supabase-trello/lib/widgets/thirdparty/vs_scrollbar.dart b/demos/supabase-trello/lib/widgets/thirdparty/vs_scrollbar.dart index 85aa58b..db59496 100644 --- a/demos/supabase-trello/lib/widgets/thirdparty/vs_scrollbar.dart +++ b/demos/supabase-trello/lib/widgets/thirdparty/vs_scrollbar.dart @@ -1,9 +1,7 @@ library vs_scrollbar; -import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; class VsScrollbarStyle { /// The hoverThickness of the VsScrollbar thumb. @@ -28,7 +26,7 @@ class VsScrollbarStyle { this.color}); } -const VsScrollbarStyle _kScrollbarStyle = const VsScrollbarStyle(); +const VsScrollbarStyle _kScrollbarStyle = VsScrollbarStyle(); const double _kScrollbarThickness = 8.0; const double _kScrollbarThicknessWithTrack = 12.0; const double _kScrollbarMargin = 2.0; @@ -64,7 +62,7 @@ class VsScrollbar extends StatefulWidget { /// enable VsScrollbar dragging using the [PrimaryScrollController]. /// const VsScrollbar({ - Key? key, + super.key, required this.child, this.controller, this.style = _kScrollbarStyle, @@ -73,7 +71,7 @@ class VsScrollbar extends StatefulWidget { this.isAlwaysShown, this.showTrackOnHover, this.notificationPredicate, - }) : super(key: key); + }); /// {@macro flutter.widgets.VsScrollbar.child} final Widget child; @@ -102,6 +100,7 @@ class VsScrollbar extends StatefulWidget { final Duration? scrollbarFadeDuration; @override + // ignore: library_private_types_in_public_api _ScrollbarState createState() => _ScrollbarState(); } @@ -109,7 +108,6 @@ class _ScrollbarState extends State { @override Widget build(BuildContext context) { return _MaterialScrollbar( - child: widget.child, controller: widget.controller, isAlwaysShown: widget.isAlwaysShown, showTrackOnHover: widget.showTrackOnHover, @@ -118,31 +116,26 @@ class _ScrollbarState extends State { radius: widget.style.radius, color: widget.style.color, notificationPredicate: widget.notificationPredicate, + child: widget.child, ); } } class _MaterialScrollbar extends RawScrollbar { const _MaterialScrollbar({ - Key? key, - required Widget child, - ScrollController? controller, + required super.child, + super.controller, bool? isAlwaysShown, this.showTrackOnHover, this.hoverThickness, this.color, this.scrollbarFadeDuration, this.scrollbarTimeToFade, - double? thickness, - Radius? radius, + super.thickness, + super.radius, ScrollNotificationPredicate? notificationPredicate, }) : super( - key: key, - child: child, - controller: controller, thumbVisibility: isAlwaysShown, - thickness: thickness, - radius: radius, fadeDuration: scrollbarFadeDuration ?? _kScrollbarFadeDuration, timeToFade: scrollbarTimeToFade ?? _kScrollbarTimeToFade, pressDuration: Duration.zero, @@ -172,18 +165,17 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { @override bool get showScrollbar => widget.thumbVisibility ?? - _scrollbarTheme.thumbVisibility - ?.resolve(Set.of([MaterialState.disabled])) ?? + _scrollbarTheme.thumbVisibility?.resolve({WidgetState.disabled}) ?? false; bool get _showTrackOnHover => widget.showTrackOnHover ?? false; - Set get _states => { - if (_dragIsActive) MaterialState.dragged, - if (_hoverIsActive) MaterialState.hovered, + Set get _states => { + if (_dragIsActive) WidgetState.dragged, + if (_hoverIsActive) WidgetState.hovered, }; - MaterialStateProperty get _thumbColor { + WidgetStateProperty get _thumbColor { final Color onSurface = widget.color ?? _colorScheme.onSurface; late Color dragColor; late Color hoverColor; @@ -192,14 +184,16 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { hoverColor = onSurface.withOpacity(0.75); idleColor = onSurface.withOpacity(0.5); - return MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.dragged)) + return WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.dragged)) { return _scrollbarTheme.thumbColor?.resolve(states) ?? dragColor; + } // If the track is visible, the thumb color hover animation is ignored and // changes immediately. - if (states.contains(MaterialState.hovered) && _showTrackOnHover) + if (states.contains(WidgetState.hovered) && _showTrackOnHover) { return _scrollbarTheme.thumbColor?.resolve(states) ?? hoverColor; + } return Color.lerp( _scrollbarTheme.thumbColor?.resolve(states) ?? idleColor, @@ -209,11 +203,11 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { }); } - MaterialStateProperty get _trackColor { + WidgetStateProperty get _trackColor { final Color onSurface = widget.color ?? _colorScheme.onSurface; - return MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered) && _showTrackOnHover) { + return WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.hovered) && _showTrackOnHover) { return _scrollbarTheme.trackColor?.resolve(states) ?? onSurface.withOpacity(0.05); } @@ -221,11 +215,11 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { }); } - MaterialStateProperty get _trackBorderColor { + WidgetStateProperty get _trackBorderColor { final Color onSurface = widget.color ?? _colorScheme.onSurface; - return MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered) && _showTrackOnHover) { + return WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.hovered) && _showTrackOnHover) { return _scrollbarTheme.trackBorderColor?.resolve(states) ?? onSurface.withOpacity(0.1); } @@ -233,12 +227,13 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { }); } - MaterialStateProperty get _thickness { - return MaterialStateProperty.resolveWith((Set states) { - if (states.contains(MaterialState.hovered) && _showTrackOnHover) + WidgetStateProperty get _thickness { + return WidgetStateProperty.resolveWith((Set states) { + if (states.contains(WidgetState.hovered) && _showTrackOnHover) { return widget.hoverThickness ?? _scrollbarTheme.thickness?.resolve(states) ?? _kScrollbarThicknessWithTrack; + } // The default VsScrollbar thickness is smaller on mobile. return widget.thickness ?? _scrollbarTheme.thickness?.resolve(states) ?? @@ -293,7 +288,7 @@ class _MaterialScrollbarState extends RawScrollbarState<_MaterialScrollbar> { (_useAndroidScrollbar ? 0.0 : _kScrollbarMargin) ..mainAxisMargin = _scrollbarTheme.mainAxisMargin ?? 0.0 ..minLength = _scrollbarTheme.minThumbLength ?? _kScrollbarMinLength - ..padding = EdgeInsets.all(0); + ..padding = const EdgeInsets.all(0); } @override