From a94a391f79b055416eb6297f45fe5b851711b8ce Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Tue, 23 Nov 2021 00:19:51 +0530 Subject: [PATCH 1/4] added drag and drop to selected files container --- lib/screens/dashboard/dashboard.dart | 173 ++++++++++--------- linux/flutter/generated_plugin_registrant.cc | 6 + linux/flutter/generated_plugin_registrant.h | 2 + linux/flutter/generated_plugins.cmake | 1 + pubspec.lock | 7 + pubspec.yaml | 1 + 6 files changed, 110 insertions(+), 80 deletions(-) diff --git a/lib/screens/dashboard/dashboard.dart b/lib/screens/dashboard/dashboard.dart index 2f2411a..322313e 100644 --- a/lib/screens/dashboard/dashboard.dart +++ b/lib/screens/dashboard/dashboard.dart @@ -1,3 +1,5 @@ +import 'package:desktop_drop/desktop_drop.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -136,91 +138,102 @@ class ClearFilesButton extends StatelessWidget { class SelectedFilesContainer extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( - color: kBgLightColor, - ), - height: MediaQuery.of(context).size.height / 2, - child: BlocConsumer( - listener: (context, state) { - if (state.alreadyPresent) { - CustomSnackBarMessage.show( - context, 'Already selected files were ignored'); - } - }, - builder: (context, state) { - return Column( - mainAxisSize: MainAxisSize.max, - children: [ - Container( - color: kBgDarkColor, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Selected files', - style: TextStyle( - fontSize: 20, + return DropTarget( + onDragDone: (detail) { + List files = detail.urls.map((e) => XFile(e.path)).toList(); + context.read().add( + NewFileAdded(files), + ); + context.read().add( + ProcessFilesSubmitted(files), + ); + }, + child: Container( + decoration: BoxDecoration( + color: kBgLightColor, + ), + height: MediaQuery.of(context).size.height / 2, + child: BlocConsumer( + listener: (context, state) { + if (state.alreadyPresent) { + CustomSnackBarMessage.show( + context, 'Already selected files were ignored'); + } + }, + builder: (context, state) { + return Column( + mainAxisSize: MainAxisSize.max, + children: [ + Container( + color: kBgDarkColor, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Selected files', + style: TextStyle( + fontSize: 20, + ), ), - ), - Row( - children: [ - ClearFilesButton(), - StartStopButton(), - ], - ), - ], + Row( + children: [ + ClearFilesButton(), + StartStopButton(), + ], + ), + ], + ), ), - ), - BlocBuilder( - builder: (context, settingsState) { - if (settingsState is CurrentSettingsState) { - return Expanded( - child: state.files.isNotEmpty - ? Scrollbar( - child: ListView.builder( - shrinkWrap: true, - physics: ClampingScrollPhysics(), - itemCount: - settingsState.settingsModel.splitMode && - state.files.length > 1 - ? 1 - : state.files.length, - itemBuilder: (context, index) { - return Container( - color: kBgLightColor, - child: settingsState - .settingsModel.splitMode && - state.files.length > 1 - ? MultiProcessTile(files: state.files) - : ProcessTile(file: state.files[index]), - ); - }, - ), - ) - : Center( - child: Text( - 'No files selected', - style: TextStyle( - fontSize: 15, + BlocBuilder( + builder: (context, settingsState) { + if (settingsState is CurrentSettingsState) { + return Expanded( + child: state.files.isNotEmpty + ? Scrollbar( + child: ListView.builder( + shrinkWrap: true, + physics: ClampingScrollPhysics(), + itemCount: + settingsState.settingsModel.splitMode && + state.files.length > 1 + ? 1 + : state.files.length, + itemBuilder: (context, index) { + return Container( + color: kBgLightColor, + child: settingsState + .settingsModel.splitMode && + state.files.length > 1 + ? MultiProcessTile(files: state.files) + : ProcessTile(file: state.files[index]), + ); + }, + ), + ) + : Center( + child: Text( + 'No files selected', + style: TextStyle( + fontSize: 15, + ), ), ), - ), - ); - } - return Center( - child: Text( - 'Loading settings, this should be super fast so if this is stuck something is broken, please open a issue on github', - style: TextStyle( - fontSize: 15, + ); + } + return Center( + child: Text( + 'Loading settings, this should be super fast so if this is stuck something is broken, please open a issue on github', + style: TextStyle( + fontSize: 15, + ), ), - ), - ); - }, - ), - ], - ); - }, + ); + }, + ), + ], + ); + }, + ), ), ); } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 215e094..4ed69d7 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -2,13 +2,19 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" +#include #include #include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) desktop_drop_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin"); + desktop_drop_plugin_register_with_registrar(desktop_drop_registrar); g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); file_selector_plugin_register_with_registrar(file_selector_linux_registrar); diff --git a/linux/flutter/generated_plugin_registrant.h b/linux/flutter/generated_plugin_registrant.h index 9bf7478..e0f0a47 100644 --- a/linux/flutter/generated_plugin_registrant.h +++ b/linux/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 73c8db3..a52b3b0 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + desktop_drop file_selector_linux url_launcher_linux window_size diff --git a/pubspec.lock b/pubspec.lock index 1b45cb4..e611aa9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -197,6 +197,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + desktop_drop: + dependency: "direct main" + description: + name: desktop_drop + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" equatable: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 26b0ab2..46ead23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: bloc: ^7.0.0 bloc_test: ^8.1.0 cupertino_icons: ^1.0.2 + desktop_drop: ^0.1.2 equatable: ^2.0.3 expandable: ^5.0.1 file_selector: ^0.8.2 From 16758f7c42d426f7e65c1e12fffae4a3e2d4c822 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Tue, 23 Nov 2021 13:34:30 +0530 Subject: [PATCH 2/4] formatting fixes --- lib/bloc_observer.dart | 19 ++++++------------- lib/screens/dashboard/dashboard.dart | 3 ++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/bloc_observer.dart b/lib/bloc_observer.dart index 418b519..1095b0e 100644 --- a/lib/bloc_observer.dart +++ b/lib/bloc_observer.dart @@ -14,21 +14,14 @@ class SimpleBlocObserver extends BlocObserver { // @override // void onEvent(Bloc bloc, Object? event) { // super.onEvent(bloc, event); - - // if ({ProcessFileExtractorOutput, ProcessFileExtractorProgress} - // .contains(event)) print('onEvent -- ${bloc.runtimeType}, $event'); + // print('onEvent -- ${bloc.runtimeType}, $event'); // } - // @override - // void onTransition(Bloc bloc, Transition transition) { - // // CurrentSettingsState and ProcessState have a lot of spam - // if ({transition.nextState, transition.nextState} - // .contains(CurrentSettingsState) || - // {transition.nextState, transition.nextState}.contains(ProcessState)) { - // print(transition); - // } - // super.onTransition(bloc, transition); - // } + @override + void onTransition(Bloc bloc, Transition transition) { + print(transition); + super.onTransition(bloc, transition); + } @override void onError(BlocBase bloc, Object error, StackTrace stackTrace) { diff --git a/lib/screens/dashboard/dashboard.dart b/lib/screens/dashboard/dashboard.dart index 322313e..bf780db 100644 --- a/lib/screens/dashboard/dashboard.dart +++ b/lib/screens/dashboard/dashboard.dart @@ -205,7 +205,8 @@ class SelectedFilesContainer extends StatelessWidget { .settingsModel.splitMode && state.files.length > 1 ? MultiProcessTile(files: state.files) - : ProcessTile(file: state.files[index]), + : ProcessTile( + file: state.files[index]), ); }, ), From a103fbf4590e3d6238394c99d6270e4c88efefe2 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Tue, 23 Nov 2021 23:50:40 +0530 Subject: [PATCH 3/4] revert bloc observer changes --- lib/bloc_observer.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/bloc_observer.dart b/lib/bloc_observer.dart index 1095b0e..418b519 100644 --- a/lib/bloc_observer.dart +++ b/lib/bloc_observer.dart @@ -14,14 +14,21 @@ class SimpleBlocObserver extends BlocObserver { // @override // void onEvent(Bloc bloc, Object? event) { // super.onEvent(bloc, event); - // print('onEvent -- ${bloc.runtimeType}, $event'); + + // if ({ProcessFileExtractorOutput, ProcessFileExtractorProgress} + // .contains(event)) print('onEvent -- ${bloc.runtimeType}, $event'); // } - @override - void onTransition(Bloc bloc, Transition transition) { - print(transition); - super.onTransition(bloc, transition); - } + // @override + // void onTransition(Bloc bloc, Transition transition) { + // // CurrentSettingsState and ProcessState have a lot of spam + // if ({transition.nextState, transition.nextState} + // .contains(CurrentSettingsState) || + // {transition.nextState, transition.nextState}.contains(ProcessState)) { + // print(transition); + // } + // super.onTransition(bloc, transition); + // } @override void onError(BlocBase bloc, Object error, StackTrace stackTrace) { From 1bfbcc1ccbc9b0a6ce8b449b554c750cf5764672 Mon Sep 17 00:00:00 2001 From: Ashish Singh Date: Wed, 24 Nov 2021 19:20:33 +0530 Subject: [PATCH 4/4] sorted imports --- lib/screens/dashboard/dashboard.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/screens/dashboard/dashboard.dart b/lib/screens/dashboard/dashboard.dart index bf780db..658dd51 100644 --- a/lib/screens/dashboard/dashboard.dart +++ b/lib/screens/dashboard/dashboard.dart @@ -1,7 +1,7 @@ -import 'package:desktop_drop/desktop_drop.dart'; -import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; +import 'package:desktop_drop/desktop_drop.dart'; +import 'package:file_selector/file_selector.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ccxgui/bloc/dashboard_bloc/dashboard_bloc.dart';