Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
🐛 D&D プラグイン乗り換え
Browse files Browse the repository at this point in the history
- `drag_and_drop_windows` → `desktop_drop`
  • Loading branch information
wappon28dev committed Oct 14, 2023
1 parent 0492ed0 commit d333ee3
Show file tree
Hide file tree
Showing 23 changed files with 208 additions and 212 deletions.
8 changes: 0 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:drag_and_drop_windows/drag_and_drop_windows.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand All @@ -7,7 +6,6 @@ import 'package:logger/logger.dart';
import 'package:window_manager/window_manager.dart';

import 'view/root.dart';
import 'vm/contents.dart';
import 'vm/theme.dart';

void main() async {
Expand Down Expand Up @@ -39,14 +37,8 @@ class Staplver extends ConsumerWidget with WindowListener {
final themeState = ref.watch(appThemePod);

// notifier
final contentsNotifier = ref.read(contentsPod.notifier);
final themeNotifier = ref.watch(appThemePod.notifier);

// local
dropEventStream.listen(
(paths) async => contentsNotifier.handleDragAndDrop(paths),
);

// view
return DynamicColorBuilder(
builder: (ColorScheme? lightColorScheme, ColorScheme? darkColorScheme) {
Expand Down
2 changes: 1 addition & 1 deletion lib/model/error/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ final class PjConfigExceptions extends ConfigExceptions {
(ref) => ref
.read(appThemePod.notifier)
.updateThemeMode(ThemeMode.system),
)
),
],
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/model/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AppThemeState with _$AppThemeState {
class ContentsState with _$ContentsState {
const factory ContentsState({
Directory? defaultBackupDir,
void Function(Directory)? dragAndDropCallback,
}) = _ContentsState;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/view/components/create_pj/set_pj_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CompSetPjDetails extends ConsumerWidget {
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
)
),
],
),
),
Expand Down
30 changes: 20 additions & 10 deletions lib/view/components/create_pj/set_working_dir.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:staplver/vm/contents.dart';

import '../../../model/constant.dart';
import '../../routes/fab/create_pj.dart';
Expand Down Expand Up @@ -33,15 +35,22 @@ class CompSetWorkingDir extends HookConsumerWidget {
(_) => isValidContentsNotifier.state = isValidContents(),
);

Future<void> selectDir() async {
final selectedDirectory = await FilePicker.platform.getDirectoryPath();
if (selectedDirectory == null) return;
final dir = Directory(selectedDirectory);
void updateDir(Directory dir) {
workingDirNotifier.state = dir;
textController.text = dir.path;
pjNameNotifier.state = dir.name;
}

Future<void> selectDir() async {
final selectedDirectory = await FilePicker.platform.getDirectoryPath();
if (selectedDirectory == null) return;
updateDir(Directory(selectedDirectory));
}

Future<void> onDragDone(List<XFile> files) async {
updateDir(await Contents.getSingleDirectory(files));
}

String? validator(String? newVal) {
if (newVal == null || newVal.isEmpty) {
return '作業フォルダーのパスを入力してください';
Expand Down Expand Up @@ -106,12 +115,13 @@ class CompSetWorkingDir extends HookConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 20),
dragAndDropSquare(
selectDir,
Theme.of(context).colorScheme,
'バージョン管理をするフォルダーを\nドラッグ & ドロップ',
'または, クリックしてフォルダーを選択',
Icons.create_new_folder,
DragAndDropSquare(
onClick: selectDir,
onDragDone: onDragDone,
colorScheme: Theme.of(context).colorScheme,
aboveText: 'バージョン管理をするフォルダーを\nドラッグ & ドロップ',
belowText: 'または, クリックしてフォルダーを選択',
icon: Icons.create_new_folder,
),
const SizedBox(height: 30),
workingDirField,
Expand Down
96 changes: 60 additions & 36 deletions lib/view/components/drag_and_drop.dart
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
import 'package:cross_file/cross_file.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

Widget dragAndDropSquare(
VoidCallback onClick,
ColorScheme colorScheme,
String aboveText,
String belowText,
IconData icon,
) {
return GestureDetector(
onTap: onClick,
child: DottedBorder(
color: colorScheme.tertiary,
dashPattern: const [15, 6],
strokeWidth: 3,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
height: 350,
width: 350,
color: colorScheme.tertiaryContainer,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
aboveText,
style:
const TextStyle(fontWeight: FontWeight.w500, fontSize: 18),
textAlign: TextAlign.center,
),
Icon(icon, size: 100),
Text(
belowText,
style:
const TextStyle(fontWeight: FontWeight.w500, fontSize: 18),
class DragAndDropSquare extends ConsumerWidget {
const DragAndDropSquare({
required this.onClick,
required this.onDragDone,
required this.colorScheme,
required this.aboveText,
required this.belowText,
required this.icon,
super.key,
});

final VoidCallback onClick;
final void Function(List<XFile> files) onDragDone;
final ColorScheme colorScheme;
final String aboveText;
final String belowText;
final IconData icon;

@override
Widget build(BuildContext context, WidgetRef ref) {
return GestureDetector(
onTap: onClick,
child: DropTarget(
onDragDone: (details) => onDragDone(details.files),
child: DottedBorder(
color: colorScheme.tertiary,
dashPattern: const [15, 6],
strokeWidth: 3,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Container(
height: 350,
width: 350,
color: colorScheme.tertiaryContainer,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
aboveText,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 18,
),
textAlign: TextAlign.center,
),
Icon(icon, size: 100),
Text(
belowText,
style: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 18,
),
),
],
),
],
),
),
),
),
),
);
);
}
}
28 changes: 19 additions & 9 deletions lib/view/components/import_pj/set_working_dir.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:io';

import 'package:cross_file/cross_file.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:staplver/vm/contents.dart';

import '../../../model/error/exception.dart';
import '../../../model/error/handler.dart';
Expand Down Expand Up @@ -67,12 +69,19 @@ class CompSetWorkingDir extends ConsumerWidget {
}
});

void updateDir(Directory dir) {
workingDirNotifier.state = dir;
textController.text = dir.path;
}

Future<void> selectDir() async {
final selectedDirectory = await FilePicker.platform.getDirectoryPath();
if (selectedDirectory == null) return;
final dir = Directory(selectedDirectory);
workingDirNotifier.state = dir;
textController.text = dir.path;
updateDir(Directory(selectedDirectory));
}

Future<void> onDragDone(List<XFile> files) async {
updateDir(await Contents.getSingleDirectory(files));
}

String? validator(String? newVal) {
Expand Down Expand Up @@ -139,12 +148,13 @@ class CompSetWorkingDir extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 20),
dragAndDropSquare(
selectDir,
Theme.of(context).colorScheme,
'作業フォルダーをドラッグ & ドロップ',
'または, クリックしてフォルダーを選択',
Icons.create_new_folder,
DragAndDropSquare(
onClick: selectDir,
onDragDone: onDragDone,
colorScheme: Theme.of(context).colorScheme,
aboveText: '作業フォルダーをドラッグ & ドロップ',
belowText: 'または, クリックしてフォルダーを選択',
icon: Icons.create_new_folder,
),
const SizedBox(height: 40),
workingDirField,
Expand Down
11 changes: 3 additions & 8 deletions lib/view/components/navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';

import '../../model/class/app.dart';
import '../../vm/contents.dart';
import '../../vm/page.dart';
import '../routes/fab/checkout.dart';
import '../routes/fab/create_pj.dart';
Expand All @@ -20,28 +19,24 @@ class NavBar {
Orientation orientation;

List<Destination> getDest() {
final contentsNotifier = ref.read(contentsPod.notifier);

return <Destination>[
Destination(
icon: const Icon(Icons.rocket_launch_outlined),
selectedIcon: const Icon(Icons.rocket_launch),
label: 'プロジェクト',
runInit: () => contentsNotifier.updateDragAndDropCallback(null),
runInit: () {},
),
Destination(
icon: const Icon(Icons.settings_outlined),
selectedIcon: const Icon(Icons.settings),
label: '設定',
runInit: () => contentsNotifier.updateDragAndDropCallback(
contentsNotifier.updateDefaultBackupDir,
),
runInit: () {},
),
Destination(
icon: const Icon(Icons.bug_report_outlined),
selectedIcon: const Icon(Icons.bug_report),
label: 'デバッグ',
runInit: () => contentsNotifier.updateDragAndDropCallback(null),
runInit: () {},
),
];
}
Expand Down
2 changes: 0 additions & 2 deletions lib/view/components/projects/save_point.dart/diff.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:io';

import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:staplver/model/class/svn.dart';
import 'package:staplver/model/constant.dart';
import 'package:staplver/view/components/projects/save_point.dart/history.dart';
import 'package:staplver/view/routes/projects/details.dart';
import 'package:staplver/vm/page.dart';
import 'package:staplver/vm/svn.dart';
Expand Down
3 changes: 1 addition & 2 deletions lib/view/root.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '../vm/now.dart';
import '../vm/page.dart';
import 'components/navbar.dart';
import 'routes/debug.dart';
import 'routes/home.dart';
import 'routes/projects/projects.dart';
import 'routes/settings.dart';
import 'util/route.dart';
Expand Down Expand Up @@ -87,7 +86,7 @@ class _AppRootState extends ConsumerState<AppRoot> with WindowListener {
Text(
' / ${dest[pageState.navbarIndex].label}',
style: const TextStyle(fontSize: 18),
)
),
],
),
leading: const SizedBox(),
Expand Down
2 changes: 1 addition & 1 deletion lib/view/routes/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class PageDebug extends HookConsumerWidget {
Text('log => ${logState.logs.join('\n')}'),
],
),
)
),
],
),
),
Expand Down
Loading

0 comments on commit d333ee3

Please sign in to comment.