Skip to content

Added Drag And Drop Support For The Desktop Application #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 16, 2023
Merged
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
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main() async {

class MyApp extends StatelessWidget {
final ThemeData theme = ThemeData(
backgroundColor: kBgDarkColor,
colorScheme: ColorScheme.dark(background: kBgDarkColor),
canvasColor: kBgDarkColor,
brightness: Brightness.dark,
visualDensity: VisualDensity.adaptivePlatformDensity,
Expand Down
101 changes: 75 additions & 26 deletions lib/screens/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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';
Expand All @@ -14,39 +16,85 @@ import 'package:ccxgui/screens/dashboard/components/udp_button.dart';
import 'package:ccxgui/utils/constants.dart';
import 'components/start_stop_button.dart';

class Dashboard extends StatelessWidget {
bool dragFile = false;

class Dashboard extends StatefulWidget {
@override
State<Dashboard> createState() => _DashboardState();
}

class _DashboardState extends State<Dashboard> {
final ScrollController controller = ScrollController();

@override
Widget build(BuildContext context) {
return Material(
child: ListView(
controller: controller,
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: AddFilesButton(),
),
Expanded(
child: ListenOnUDPButton(),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 8,
),
child: SelectedFilesContainer(),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 8,
DropTarget(
onDragEntered: (data) {
setState(() {
dragFile = true;
});
},
onDragExited: (data) {
setState(() {
dragFile = false;
});
},
onDragDone: (data) {
dragFile = false;
final List<XFile> fileData = data.files;
List<XFile> validFiles = [];
RegExp validExtensions = RegExp(
r'(\.dvr-ms|\.m2v|\.mpg|\.ts|\.wtv|\.mp4|\.mpg2|\.vob|\.mkv)$');
print(validExtensions.hasMatch(fileData[0].path));
for (XFile file in fileData) {
if (validExtensions.hasMatch(file.path)) {
validFiles.add(file);
} else {
CustomSnackBarMessage.show(
context, 'Invalid file type: ${file.path}');
}
}
context.read<DashboardBloc>().add(
NewFileAdded(validFiles),
);
context.read<ProcessBloc>().add(
ProcessFilesSubmitted(validFiles),
);
},
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: AddFilesButton(),
),
Expanded(
child: ListenOnUDPButton(),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 8,
),
child: SelectedFilesContainer(),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 8,
),
child: LogsContainer(),
)
],
),
child: LogsContainer(),
),
)
],
),
);
Expand Down Expand Up @@ -74,6 +122,7 @@ class ClearFilesButton extends StatelessWidget {
builder: (context, dashboardState) {
return MaterialButton(
onPressed: () {
dragFile = false;
dashboardState.files.isEmpty
? null
: showDialog(
Expand Down Expand Up @@ -202,7 +251,7 @@ class SelectedFilesContainer extends StatelessWidget {
)
: Center(
child: Text(
'No files selected',
dragFile ? 'Drop to Add' : 'No files selected',
style: TextStyle(
fontSize: 15,
),
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

#include "generated_plugin_registrant.h"

#include <desktop_drop/desktop_drop_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_size/window_size_plugin.h>

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);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
file_selector_linux
url_launcher_linux
window_size
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import FlutterMacOS
import Foundation

import desktop_drop
import file_selector_macos
import path_provider_macos
import url_launcher_macos
import window_size

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
Expand Down
Loading