Skip to content

Commit 3b1f2b3

Browse files
authored
feat: drag and drop support
* added drag and drop feature for AddFilesButton * added desktop_drop packages and updated some packages * added drag and drop feature to dashboard * removed dnd feature for AddFilesButton * added dnd feature for dashboard * Update dashboard.dart * Update dashboard.dart * Added Drop To Add on hovering the files over the container * sorted packages * sorted packages * converted double quoted text to single quoted text * fixed deprecated_member_use * updated packages * made changes regarding the file package upgraded file to newer version and added it in yaml file
1 parent 9e2d4c7 commit 3b1f2b3

File tree

9 files changed

+362
-183
lines changed

9 files changed

+362
-183
lines changed

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void main() async {
2929

3030
class MyApp extends StatelessWidget {
3131
final ThemeData theme = ThemeData(
32-
backgroundColor: kBgDarkColor,
32+
colorScheme: ColorScheme.dark(background: kBgDarkColor),
3333
canvasColor: kBgDarkColor,
3434
brightness: Brightness.dark,
3535
visualDensity: VisualDensity.adaptivePlatformDensity,

lib/screens/dashboard/dashboard.dart

Lines changed: 75 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/material.dart';
22

3+
import 'package:desktop_drop/desktop_drop.dart';
4+
import 'package:file_selector/file_selector.dart';
35
import 'package:flutter_bloc/flutter_bloc.dart';
46

57
import 'package:ccxgui/bloc/dashboard_bloc/dashboard_bloc.dart';
@@ -14,39 +16,85 @@ import 'package:ccxgui/screens/dashboard/components/udp_button.dart';
1416
import 'package:ccxgui/utils/constants.dart';
1517
import 'components/start_stop_button.dart';
1618

17-
class Dashboard extends StatelessWidget {
19+
bool dragFile = false;
20+
21+
class Dashboard extends StatefulWidget {
22+
@override
23+
State<Dashboard> createState() => _DashboardState();
24+
}
25+
26+
class _DashboardState extends State<Dashboard> {
1827
final ScrollController controller = ScrollController();
28+
1929
@override
2030
Widget build(BuildContext context) {
2131
return Material(
2232
child: ListView(
2333
controller: controller,
2434
children: [
25-
Row(
26-
mainAxisSize: MainAxisSize.max,
27-
children: [
28-
Expanded(
29-
child: AddFilesButton(),
30-
),
31-
Expanded(
32-
child: ListenOnUDPButton(),
33-
),
34-
],
35-
),
36-
Padding(
37-
padding: const EdgeInsets.symmetric(
38-
horizontal: 20,
39-
vertical: 8,
40-
),
41-
child: SelectedFilesContainer(),
42-
),
43-
Padding(
44-
padding: const EdgeInsets.symmetric(
45-
horizontal: 20.0,
46-
vertical: 8,
35+
DropTarget(
36+
onDragEntered: (data) {
37+
setState(() {
38+
dragFile = true;
39+
});
40+
},
41+
onDragExited: (data) {
42+
setState(() {
43+
dragFile = false;
44+
});
45+
},
46+
onDragDone: (data) {
47+
dragFile = false;
48+
final List<XFile> fileData = data.files;
49+
List<XFile> validFiles = [];
50+
RegExp validExtensions = RegExp(
51+
r'(\.dvr-ms|\.m2v|\.mpg|\.ts|\.wtv|\.mp4|\.mpg2|\.vob|\.mkv)$');
52+
print(validExtensions.hasMatch(fileData[0].path));
53+
for (XFile file in fileData) {
54+
if (validExtensions.hasMatch(file.path)) {
55+
validFiles.add(file);
56+
} else {
57+
CustomSnackBarMessage.show(
58+
context, 'Invalid file type: ${file.path}');
59+
}
60+
}
61+
context.read<DashboardBloc>().add(
62+
NewFileAdded(validFiles),
63+
);
64+
context.read<ProcessBloc>().add(
65+
ProcessFilesSubmitted(validFiles),
66+
);
67+
},
68+
child: Column(
69+
children: [
70+
Row(
71+
mainAxisSize: MainAxisSize.max,
72+
children: [
73+
Expanded(
74+
child: AddFilesButton(),
75+
),
76+
Expanded(
77+
child: ListenOnUDPButton(),
78+
),
79+
],
80+
),
81+
Padding(
82+
padding: const EdgeInsets.symmetric(
83+
horizontal: 20,
84+
vertical: 8,
85+
),
86+
child: SelectedFilesContainer(),
87+
),
88+
Padding(
89+
padding: const EdgeInsets.symmetric(
90+
horizontal: 20.0,
91+
vertical: 8,
92+
),
93+
child: LogsContainer(),
94+
)
95+
],
4796
),
48-
child: LogsContainer(),
49-
),
97+
)
5098
],
5199
),
52100
);
@@ -74,6 +122,7 @@ class ClearFilesButton extends StatelessWidget {
74122
builder: (context, dashboardState) {
75123
return MaterialButton(
76124
onPressed: () {
125+
dragFile = false;
77126
dashboardState.files.isEmpty
78127
? null
79128
: showDialog(
@@ -202,7 +251,7 @@ class SelectedFilesContainer extends StatelessWidget {
202251
)
203252
: Center(
204253
child: Text(
205-
'No files selected',
254+
dragFile ? 'Drop to Add' : 'No files selected',
206255
style: TextStyle(
207256
fontSize: 15,
208257
),

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <desktop_drop/desktop_drop_plugin.h>
910
#include <file_selector_linux/file_selector_plugin.h>
1011
#include <url_launcher_linux/url_launcher_plugin.h>
1112
#include <window_size/window_size_plugin.h>
1213

1314
void fl_register_plugins(FlPluginRegistry* registry) {
15+
g_autoptr(FlPluginRegistrar) desktop_drop_registrar =
16+
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin");
17+
desktop_drop_plugin_register_with_registrar(desktop_drop_registrar);
1418
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
1519
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
1620
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
desktop_drop
67
file_selector_linux
78
url_launcher_linux
89
window_size

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import FlutterMacOS
66
import Foundation
77

8+
import desktop_drop
89
import file_selector_macos
910
import path_provider_macos
1011
import url_launcher_macos
1112
import window_size
1213

1314
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
15+
DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin"))
1416
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
1517
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
1618
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))

0 commit comments

Comments
 (0)