From e1571bd6728d09d4dfed2fe811d430bd6d6a2740 Mon Sep 17 00:00:00 2001 From: MCredbear <2363764471@qq.com> Date: Mon, 19 Feb 2024 15:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/file_manager_page/file_manager_page.dart | 242 +++++++++++++++--- lib/file_manager_page/file_manager_store.dart | 11 + .../file_manager_store.g.dart | 15 +- pubspec.lock | 16 +- pubspec.yaml | 2 +- 5 files changed, 227 insertions(+), 59 deletions(-) diff --git a/lib/file_manager_page/file_manager_page.dart b/lib/file_manager_page/file_manager_page.dart index c423d22..b742d04 100644 --- a/lib/file_manager_page/file_manager_page.dart +++ b/lib/file_manager_page/file_manager_page.dart @@ -16,22 +16,20 @@ class FileManagerPage extends StatefulWidget { } class FileManagerPageState extends State { - FileManagerStore fileManagerStore = FileManagerStore(); - - List pathsQueue = []; + final List _pathsQueue = []; @override void initState() { if (Platform.isAndroid) { getExternalStorageDirectories().then((value) { - pathsQueue + _pathsQueue .add('${value!.first.parent.parent.parent.parent.path}/Music'); - fileManagerStore.readDir(pathsQueue.last); + fileManagerStore.readDir(_pathsQueue.last); }); } else { getApplicationDocumentsDirectory().then((value) { - pathsQueue.add(value.parent.path); - fileManagerStore.readDir(pathsQueue.last); + _pathsQueue.add(value.parent.path); + fileManagerStore.readDir(_pathsQueue.last); }); } super.initState(); @@ -42,20 +40,55 @@ class FileManagerPageState extends State { return PopScope( canPop: false, onPopInvoked: (value) { - if (pathsQueue.length > 1) { - pathsQueue.removeLast(); - fileManagerStore.readDir(pathsQueue.last); + if (_pathsQueue.length > 1) { + _pathsQueue.removeLast(); + fileManagerStore.readDir(_pathsQueue.last); } else { exit(0); } }, child: Scaffold( - appBar: AppBar( - title: const Text("Music tools Flutter"), - actions: [ - PopupMenuButton( + floatingActionButton: Column(mainAxisSize: MainAxisSize.min, children: [ + FloatingActionButton( + onPressed: () { + if (_pathsQueue.length > 1) { + _pathsQueue.removeLast(); + fileManagerStore.readDir(_pathsQueue.last); + } + }, + child: const Icon(Icons.keyboard_arrow_left)), + const SizedBox( + height: 5, + ), + FloatingActionButton( + onPressed: (() { + _pathsQueue.add(dirname(_pathsQueue.last)); + fileManagerStore.readDir(_pathsQueue.last); + }), + child: const Icon(Icons.keyboard_arrow_up)), + const SizedBox( + height: 5, + ), + FloatingActionButton( + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return SearchDialog( + pathsQueue: _pathsQueue, + ); + }); + }, + child: const Icon(Icons.search)), + const SizedBox( + height: 5, + ), + FloatingActionButton( + onPressed: () {}, + child: PopupMenuButton( + tooltip: '', icon: const Icon(Icons.sort), - splashRadius: 24, + splashRadius: 28, itemBuilder: (BuildContext context) => [ PopupMenuItem( padding: EdgeInsets.zero, @@ -101,29 +134,18 @@ class FileManagerPageState extends State { ); })), ]), - IconButton( - splashRadius: 24, - onPressed: () { - if (pathsQueue.length > 1) { - pathsQueue.removeLast(); - fileManagerStore.readDir(pathsQueue.last); - } - }, - icon: const Icon(Icons.keyboard_arrow_left_sharp)), - IconButton( - splashRadius: 24, - onPressed: (() { - fileManagerStore.readDir(pathsQueue.last); - }), - icon: const Icon(Icons.refresh)), - IconButton( - splashRadius: 24, - onPressed: (() { - pathsQueue.add(dirname(pathsQueue.last)); - fileManagerStore.readDir(pathsQueue.last); - }), - icon: const Icon(Icons.arrow_upward)) - ], + ), + const SizedBox( + height: 5, + ), + FloatingActionButton( + onPressed: () { + fileManagerStore.readDir(_pathsQueue.last); + }, + child: const Icon(Icons.refresh)) + ]), + appBar: AppBar( + title: const Text("Music tools Flutter"), ), body: Center( child: Observer( @@ -135,10 +157,10 @@ class FileManagerPageState extends State { onTap: (() { if (fileManagerStore.elements.elementAt(index) is Directory) { - pathsQueue.add(fileManagerStore.elements + _pathsQueue.add(fileManagerStore.elements .elementAt(index) .path); - fileManagerStore.readDir(pathsQueue.last); + fileManagerStore.readDir(_pathsQueue.last); } else { Navigator.push( context, @@ -177,3 +199,143 @@ class FileManagerPageState extends State { ); } } + +class SearchDialog extends StatefulWidget { + const SearchDialog({super.key, required List pathsQueue}) + : _pathsQueue = pathsQueue; + + final List _pathsQueue; + + @override + State createState() => _SearchDialogState(); +} + +class _SearchDialogState extends State { + final _searchController = TextEditingController(); + + List _filtedElements = []; + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: const Text('搜索', textScaler: TextScaler.linear(2)), + content: SizedBox( + width: 400, + height: 800, + child: Column( + children: [ + TextField( + controller: _searchController, + onChanged: (value) { + List filtedElements = []; + for (final element in fileManagerStore.elements) { + if (basename(element.path).contains( + RegExp(value, caseSensitive: false))) { + filtedElements.add(element); + } + } + setState(() { + _filtedElements = filtedElements; + }); + }, + ), + Expanded( + child: ListView.builder( + itemCount: _filtedElements.length, + itemBuilder: (context, index) => SizedBox( + height: 60, + child: ListTile( + onTap: (() { + if (_filtedElements.elementAt(index) + is Directory) { + Navigator.pop(context); + widget._pathsQueue + .add(_filtedElements.elementAt(index).path); + fileManagerStore + .readDir(widget._pathsQueue.last); + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => EditorPage( + _filtedElements + .elementAt(index) + .path))); + } + }), + leading: + (_filtedElements.elementAt(index) is Directory) + ? const Icon( + Icons.folder, + size: 30, + ) + : const Icon( + Icons.audio_file, + size: 30, + ), + title: Text( + basename(_filtedElements.elementAt(index).path), + overflow: TextOverflow.ellipsis, + ), + subtitle: Text(_filtedElements + .elementAt(index) + .statSync() + .modified + .toString()), + ), + )), + ) + ], + ), + )); + } +} + +class FileTile extends StatelessWidget { + const FileTile( + {super.key, required List pathsQueue, required int index}) + : _pathsQueue = pathsQueue, + _index = index; + + final List _pathsQueue; + final int _index; + + @override + Widget build(BuildContext context) { + return SizedBox( + height: 60, + child: ListTile( + onTap: (() { + if (fileManagerStore.elements.elementAt(_index) is Directory) { + _pathsQueue.add(fileManagerStore.elements.elementAt(_index).path); + fileManagerStore.readDir(_pathsQueue.last); + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => EditorPage( + fileManagerStore.elements.elementAt(_index).path))); + } + }), + leading: (fileManagerStore.elements.elementAt(_index) is Directory) + ? const Icon( + Icons.folder, + size: 30, + ) + : const Icon( + Icons.audio_file, + size: 30, + ), + title: Text( + basename(fileManagerStore.elements.elementAt(_index).path), + overflow: TextOverflow.ellipsis, + ), + subtitle: Text(fileManagerStore.elements + .elementAt(_index) + .statSync() + .modified + .toString()), + ), + ); + } +} diff --git a/lib/file_manager_page/file_manager_store.dart b/lib/file_manager_page/file_manager_store.dart index 5357712..58c8b84 100644 --- a/lib/file_manager_page/file_manager_store.dart +++ b/lib/file_manager_page/file_manager_store.dart @@ -73,6 +73,15 @@ abstract class FileManagerStoreBase with Store { } } + // @action + // void search(String keyword){ + // ObservableList newElements = ObservableList(); + // for (final element in elements){ + // if (basename(element.path).contains(RegExp(keyword,caseSensitive: false))) newElements.add(element); + // } + // elements = newElements; + // } + void sortByName() { ObservableList dirs = ObservableList(); ObservableList files = ObservableList(); @@ -123,3 +132,5 @@ abstract class FileManagerStoreBase with Store { elements.addAll(files); } } + +final FileManagerStore fileManagerStore = FileManagerStore(); \ No newline at end of file diff --git a/lib/file_manager_page/file_manager_store.g.dart b/lib/file_manager_page/file_manager_store.g.dart index b219b2a..0a3aa36 100644 --- a/lib/file_manager_page/file_manager_store.g.dart +++ b/lib/file_manager_page/file_manager_store.g.dart @@ -9,7 +9,8 @@ part of 'file_manager_store.dart'; // ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers mixin _$FileManagerStore on FileManagerStoreBase, Store { - late final _$elementsAtom = Atom(name: 'FileManagerStoreBase.elements'); + late final _$elementsAtom = + Atom(name: 'FileManagerStoreBase.elements'); @override ObservableList get elements { @@ -24,7 +25,8 @@ mixin _$FileManagerStore on FileManagerStoreBase, Store { }); } - late final _$sortOrderAtom = Atom(name: 'FileManagerStoreBase.sortOrder'); + late final _$sortOrderAtom = + Atom(name: 'FileManagerStoreBase.sortOrder'); @override SortOrder get sortOrder { @@ -39,17 +41,18 @@ mixin _$FileManagerStore on FileManagerStoreBase, Store { }); } - late final _$reservedAtom = Atom(name: 'FileManagerStoreBase.reserved'); + late final _$descendingOrderAtom = + Atom(name: 'FileManagerStoreBase.descendingOrder'); @override bool get descendingOrder { - _$reservedAtom.reportRead(); + _$descendingOrderAtom.reportRead(); return super.descendingOrder; } @override set descendingOrder(bool value) { - _$reservedAtom.reportWrite(value, super.descendingOrder, () { + _$descendingOrderAtom.reportWrite(value, super.descendingOrder, () { super.descendingOrder = value; }); } @@ -95,7 +98,7 @@ mixin _$FileManagerStore on FileManagerStoreBase, Store { return ''' elements: ${elements}, sortOrder: ${sortOrder}, -reserved: ${descendingOrder} +descendingOrder: ${descendingOrder} '''; } } diff --git a/pubspec.lock b/pubspec.lock index 7df714c..49d5707 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -288,14 +288,6 @@ packages: url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted version: "4.0.2" - intl: - dependency: transitive - description: - name: intl - sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" - url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" - source: hosted - version: "0.18.1" io: dependency: transitive description: @@ -324,10 +316,10 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "2c30f27ada446b4d36307aade893faaaeb6d8f55b2362b7f424a9668fcc43f4d" + sha256: "04be76c4a4bb50f14904e64749237e541e7c7bcf7ec0b196907322ab5d2fc739" url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted - version: "9.0.14" + version: "9.0.16" leak_tracker_testing: dependency: transitive description: @@ -705,10 +697,10 @@ packages: dependency: transitive description: name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/" source: hosted - version: "0.3.0" + version: "0.4.0" web_socket_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1c411e7..bcb7213 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: music_tools_flutter -description: A new Flutter project. +description: A tool to edit tag of audio files, based on flutter. publish_to: 'none' version: 1.0.0+1