update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
190
.config/Code/User/History/52c1244e/2NEQ.dart
Normal file
190
.config/Code/User/History/52c1244e/2NEQ.dart
Normal file
|
@ -0,0 +1,190 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.length == 0){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/35F9.dart
Normal file
196
.config/Code/User/History/52c1244e/35F9.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/3Tju.dart
Normal file
196
.config/Code/User/History/52c1244e/3Tju.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/63g1.dart
Normal file
196
.config/Code/User/History/52c1244e/63g1.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/6Ymb.dart
Normal file
196
.config/Code/User/History/52c1244e/6Ymb.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
199
.config/Code/User/History/52c1244e/8MDF.dart
Normal file
199
.config/Code/User/History/52c1244e/8MDF.dart
Normal file
|
@ -0,0 +1,199 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
else{
|
||||
menu = const FileOptionsMenu(selected: []);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
190
.config/Code/User/History/52c1244e/8N27.dart
Normal file
190
.config/Code/User/History/52c1244e/8N27.dart
Normal file
|
@ -0,0 +1,190 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
182
.config/Code/User/History/52c1244e/8zp3.dart
Normal file
182
.config/Code/User/History/52c1244e/8zp3.dart
Normal file
|
@ -0,0 +1,182 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, string option){
|
||||
setState((){
|
||||
_selected.add(selected);
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
168
.config/Code/User/History/52c1244e/9TyQ.dart
Normal file
168
.config/Code/User/History/52c1244e/9TyQ.dart
Normal file
|
@ -0,0 +1,168 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: getDirButtons,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/A16D.dart
Normal file
196
.config/Code/User/History/52c1244e/A16D.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu? menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
187
.config/Code/User/History/52c1244e/EeYu.dart
Normal file
187
.config/Code/User/History/52c1244e/EeYu.dart
Normal file
|
@ -0,0 +1,187 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
175
.config/Code/User/History/52c1244e/H3nL.dart
Normal file
175
.config/Code/User/History/52c1244e/H3nL.dart
Normal file
|
@ -0,0 +1,175 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
174
.config/Code/User/History/52c1244e/IHP0.dart
Normal file
174
.config/Code/User/History/52c1244e/IHP0.dart
Normal file
|
@ -0,0 +1,174 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
199
.config/Code/User/History/52c1244e/KWk2.dart
Normal file
199
.config/Code/User/History/52c1244e/KWk2.dart
Normal file
|
@ -0,0 +1,199 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
else{
|
||||
menu = FileOptionsMenu(selected: []);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
179
.config/Code/User/History/52c1244e/LJGA.dart
Normal file
179
.config/Code/User/History/52c1244e/LJGA.dart
Normal file
|
@ -0,0 +1,179 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(Widget selected){
|
||||
_selected.add(selected);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
182
.config/Code/User/History/52c1244e/LhTK.dart
Normal file
182
.config/Code/User/History/52c1244e/LhTK.dart
Normal file
|
@ -0,0 +1,182 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(FileButton selected){
|
||||
setState((){
|
||||
_selected.add(selected);
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
190
.config/Code/User/History/52c1244e/LsOo.dart
Normal file
190
.config/Code/User/History/52c1244e/LsOo.dart
Normal file
|
@ -0,0 +1,190 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
190
.config/Code/User/History/52c1244e/MJRn.dart
Normal file
190
.config/Code/User/History/52c1244e/MJRn.dart
Normal file
|
@ -0,0 +1,190 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
172
.config/Code/User/History/52c1244e/MQHv.dart
Normal file
172
.config/Code/User/History/52c1244e/MQHv.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
refresh();
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
192
.config/Code/User/History/52c1244e/NjGL.dart
Normal file
192
.config/Code/User/History/52c1244e/NjGL.dart
Normal file
|
@ -0,0 +1,192 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [FileOptionsMenu(selected: _selected)],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
174
.config/Code/User/History/52c1244e/P5zV.dart
Normal file
174
.config/Code/User/History/52c1244e/P5zV.dart
Normal file
|
@ -0,0 +1,174 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
187
.config/Code/User/History/52c1244e/PFFX.dart
Normal file
187
.config/Code/User/History/52c1244e/PFFX.dart
Normal file
|
@ -0,0 +1,187 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: ,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
172
.config/Code/User/History/52c1244e/PT56.dart
Normal file
172
.config/Code/User/History/52c1244e/PT56.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/PgDk.dart
Normal file
196
.config/Code/User/History/52c1244e/PgDk.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu? menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [FileOptionsMenu(selected: _selected)],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
191
.config/Code/User/History/52c1244e/QGmG.dart
Normal file
191
.config/Code/User/History/52c1244e/QGmG.dart
Normal file
|
@ -0,0 +1,191 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/Qdwz.dart
Normal file
196
.config/Code/User/History/52c1244e/Qdwz.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
192
.config/Code/User/History/52c1244e/S17k.dart
Normal file
192
.config/Code/User/History/52c1244e/S17k.dart
Normal file
|
@ -0,0 +1,192 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [FileOptionsMenu(selected: [])],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
199
.config/Code/User/History/52c1244e/Uu63.dart
Normal file
199
.config/Code/User/History/52c1244e/Uu63.dart
Normal file
|
@ -0,0 +1,199 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actions_buttons;
|
||||
if(_mode == FMMode.selection){
|
||||
actions_buttons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
187
.config/Code/User/History/52c1244e/YpD3.dart
Normal file
187
.config/Code/User/History/52c1244e/YpD3.dart
Normal file
|
@ -0,0 +1,187 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/ZTv4.dart
Normal file
196
.config/Code/User/History/52c1244e/ZTv4.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
183
.config/Code/User/History/52c1244e/aBnn.dart
Normal file
183
.config/Code/User/History/52c1244e/aBnn.dart
Normal file
|
@ -0,0 +1,183 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(FileButton selected){
|
||||
|
||||
setState((){
|
||||
_selected.add(selected);
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/bg0h.dart
Normal file
196
.config/Code/User/History/52c1244e/bg0h.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actions_buttons;
|
||||
if(_mode == FMMode.selection){
|
||||
actions_buttons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actions_buttons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
175
.config/Code/User/History/52c1244e/eBdW.dart
Normal file
175
.config/Code/User/History/52c1244e/eBdW.dart
Normal file
|
@ -0,0 +1,175 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
1
.config/Code/User/History/52c1244e/entries.json
Normal file
1
.config/Code/User/History/52c1244e/entries.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"resource":"file:///home/rafayahmad/Stuff/Coding/Flutter/filemanager/lib/main.dart","entries":[{"id":"t0bj.dart","timestamp":1724561029127},{"id":"nxzx.dart","timestamp":1724561080891},{"id":"9TyQ.dart","timestamp":1724561091451},{"id":"h9gg.dart","timestamp":1724561139694},{"id":"MQHv.dart","timestamp":1724561424254},{"id":"PT56.dart","timestamp":1724561441531},{"id":"gkfn.dart","timestamp":1724561460884},{"id":"IHP0.dart","timestamp":1724561707921},{"id":"eBdW.dart","timestamp":1724666685025},{"id":"P5zV.dart","timestamp":1724819847570},{"id":"H3nL.dart","timestamp":1724820142125},{"id":"LJGA.dart","timestamp":1724820382614},{"id":"lAuM.dart","timestamp":1724820724684},{"id":"g0JB.dart","timestamp":1724820760197},{"id":"LhTK.dart","timestamp":1724820867456},{"id":"aBnn.dart","timestamp":1724820897473},{"id":"xg5q.dart","timestamp":1724821099026},{"id":"8zp3.dart","timestamp":1724821172924},{"id":"EeYu.dart","timestamp":1724821201404},{"id":"PFFX.dart","timestamp":1724821217621},{"id":"hsPt.dart","timestamp":1724821229484},{"id":"YpD3.dart","timestamp":1724821305908},{"id":"hNrK.dart","timestamp":1724821334669},{"id":"2NEQ.dart","timestamp":1724821434030},{"id":"MJRn.dart","source":"Replace with 'isEmpty'","timestamp":1724821438174},{"id":"8N27.dart","source":"Make final","timestamp":1724821676589},{"id":"LsOo.dart","timestamp":1724997413207},{"id":"QGmG.dart","source":"Import library 'package:filemanager/file_options_menu.dart'","timestamp":1724997420921},{"id":"S17k.dart","timestamp":1725076885363},{"id":"NjGL.dart","timestamp":1725076904890},{"id":"A16D.dart","timestamp":1725077036795},{"id":"PgDk.dart","timestamp":1725077054284},{"id":"m2Iz.dart","timestamp":1725077065284},{"id":"KWk2.dart","timestamp":1725077095104},{"id":"8MDF.dart","source":"Add 'const' modifier","timestamp":1725077102584},{"id":"y4oC.dart","timestamp":1725077169829},{"id":"Uu63.dart","timestamp":1725077256158},{"id":"bg0h.dart","timestamp":1725077271085},{"id":"6Ymb.dart","source":"Rename to 'actionsButtons'","timestamp":1725077279358},{"id":"fjJR.dart","timestamp":1725770655669},{"id":"63g1.dart","timestamp":1725771707740},{"id":"fQbo.dart","timestamp":1725771721670},{"id":"35F9.dart","timestamp":1725771875268},{"id":"lIhX.dart","timestamp":1725771909654},{"id":"ZTv4.dart","timestamp":1725772049085},{"id":"3Tju.dart","timestamp":1725772340604},{"id":"nRRP.dart","timestamp":1725772430165},{"id":"ogoq.dart","timestamp":1725773408675},{"id":"Qdwz.dart","timestamp":1725774190140},{"id":"qnwU.dart","timestamp":1725774233864}]}
|
196
.config/Code/User/History/52c1244e/fQbo.dart
Normal file
196
.config/Code/User/History/52c1244e/fQbo.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
197
.config/Code/User/History/52c1244e/fjJR.dart
Normal file
197
.config/Code/User/History/52c1244e/fjJR.dart
Normal file
|
@ -0,0 +1,197 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
globalKey: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
180
.config/Code/User/History/52c1244e/g0JB.dart
Normal file
180
.config/Code/User/History/52c1244e/g0JB.dart
Normal file
|
@ -0,0 +1,180 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(FileButton selected){
|
||||
_selected.add(selected);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
172
.config/Code/User/History/52c1244e/gkfn.dart
Normal file
172
.config/Code/User/History/52c1244e/gkfn.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
172
.config/Code/User/History/52c1244e/h9gg.dart
Normal file
172
.config/Code/User/History/52c1244e/h9gg.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
refresh();
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
188
.config/Code/User/History/52c1244e/hNrK.dart
Normal file
188
.config/Code/User/History/52c1244e/hNrK.dart
Normal file
|
@ -0,0 +1,188 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
print(_selected.length);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
187
.config/Code/User/History/52c1244e/hsPt.dart
Normal file
187
.config/Code/User/History/52c1244e/hsPt.dart
Normal file
|
@ -0,0 +1,187 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
179
.config/Code/User/History/52c1244e/lAuM.dart
Normal file
179
.config/Code/User/History/52c1244e/lAuM.dart
Normal file
|
@ -0,0 +1,179 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(FileButton selected){
|
||||
_selected.add(selected);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/lIhX.dart
Normal file
196
.config/Code/User/History/52c1244e/lIhX.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/m2Iz.dart
Normal file
196
.config/Code/User/History/52c1244e/m2Iz.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/nRRP.dart
Normal file
196
.config/Code/User/History/52c1244e/nRRP.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
168
.config/Code/User/History/52c1244e/nxzx.dart
Normal file
168
.config/Code/User/History/52c1244e/nxzx.dart
Normal file
|
@ -0,0 +1,168 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/ogoq.dart
Normal file
196
.config/Code/User/History/52c1244e/ogoq.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
globalKey: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
196
.config/Code/User/History/52c1244e/qnwU.dart
Normal file
196
.config/Code/User/History/52c1244e/qnwU.dart
Normal file
|
@ -0,0 +1,196 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
globalKey: GlobalKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
List<Widget>? actionsButtons;
|
||||
if(_mode == FMMode.selection){
|
||||
actionsButtons = List.of([FileOptionsMenu(selected: _selected)]);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: actionsButtons,
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
172
.config/Code/User/History/52c1244e/t0bj.dart
Normal file
172
.config/Code/User/History/52c1244e/t0bj.dart
Normal file
|
@ -0,0 +1,172 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
print('build');
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
182
.config/Code/User/History/52c1244e/xg5q.dart
Normal file
182
.config/Code/User/History/52c1244e/xg5q.dart
Normal file
|
@ -0,0 +1,182 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
List<Widget> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void addToSelectionList(FileButton selected){
|
||||
setState((){
|
||||
_selected.add(selected);
|
||||
});
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
addToSelectionList: addToSelectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
198
.config/Code/User/History/52c1244e/y4oC.dart
Normal file
198
.config/Code/User/History/52c1244e/y4oC.dart
Normal file
|
@ -0,0 +1,198 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:filemanager/file_options_menu.dart';
|
||||
import 'package:io/io.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:filemanager/file_button.dart';
|
||||
|
||||
void main(){
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget{
|
||||
const MyApp({super.key});
|
||||
|
||||
void askPermission() async{
|
||||
var status = await Permission.manageExternalStorage.request();
|
||||
if(!status.isGranted) throw Exception('Permssion Denied');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
askPermission();
|
||||
return MaterialApp(
|
||||
title: 'File Manager',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData.dark(useMaterial3: true),
|
||||
home: const MyHomePage(title: 'File Manager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum FMMode{normal, selection}
|
||||
|
||||
class MyHomePage extends StatefulWidget{
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage>{
|
||||
|
||||
//TODO: add popupmenubutton for selected items
|
||||
|
||||
String _currentDir = '/storage/emulated/0';
|
||||
List<Widget> _list = List.empty(growable: true);
|
||||
FloatingActionButton? _faButton;
|
||||
FMMode _mode = FMMode.normal;
|
||||
final List<FileButton> _selected = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
void initState(){
|
||||
super.initState();
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void refresh(){
|
||||
setState((){});
|
||||
}
|
||||
|
||||
void selectionList(FileButton selected, bool option){
|
||||
setState((){
|
||||
if(option){
|
||||
_selected.add(selected);
|
||||
}
|
||||
else{
|
||||
_selected.remove(selected);
|
||||
}
|
||||
});
|
||||
if(_selected.isEmpty){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
}
|
||||
|
||||
FMMode getMode(){
|
||||
return _mode;
|
||||
}
|
||||
|
||||
void setMode(FMMode mode){
|
||||
setState((){
|
||||
_mode = mode;
|
||||
});
|
||||
}
|
||||
|
||||
void copyFile(FileSystemEntity fsEntity, FileOptions fileOption){
|
||||
setState((){
|
||||
_faButton = FloatingActionButton.extended(
|
||||
onPressed: (){
|
||||
if(fsEntity is File){
|
||||
fsEntity.copySync('$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
else{
|
||||
copyPathSync(fsEntity.path, '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}');
|
||||
}
|
||||
if(fileOption == FileOptions.cut && fsEntity.path != '$_currentDir/${fsEntity.path.split(Platform.pathSeparator).last}'){
|
||||
fsEntity.deleteSync(recursive: true);
|
||||
}
|
||||
_faButton = null;
|
||||
getDirButtons(_currentDir);
|
||||
},
|
||||
label: const Row(
|
||||
children: [
|
||||
Icon(Icons.paste),
|
||||
SizedBox(width: 10,),
|
||||
Text('Paste'),
|
||||
],
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void openFile(FileSystemEntity fsEntity, String name){
|
||||
setState((){
|
||||
if(fsEntity is Directory){
|
||||
_currentDir = '$_currentDir${Platform.pathSeparator}$name';
|
||||
}
|
||||
else if(fsEntity is File){
|
||||
//TODO: opening file logic
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void backButtonPressed(){
|
||||
setState((){
|
||||
if(_mode == FMMode.normal){
|
||||
if(_currentDir != '/storage/emulated/0'){
|
||||
_currentDir = _currentDir.substring(0, _currentDir.lastIndexOf(Platform.pathSeparator));
|
||||
}
|
||||
}
|
||||
else if(_mode == FMMode.selection){
|
||||
_mode = FMMode.normal;
|
||||
}
|
||||
});
|
||||
getDirButtons(_currentDir);
|
||||
}
|
||||
|
||||
void getDirButtons(String dir){
|
||||
setState((){
|
||||
_list = List.empty(growable: true);
|
||||
Directory directory = Directory(dir);
|
||||
try{
|
||||
directory.listSync().forEach((element) => _list.add(FileButton(
|
||||
key: UniqueKey(),
|
||||
fsEntity: element,
|
||||
openFile: openFile,
|
||||
refresh: refresh,
|
||||
copyFile: copyFile,
|
||||
setMode: setMode,
|
||||
getMode: getMode,
|
||||
selectionList: selectionList,
|
||||
)));
|
||||
}
|
||||
on PathAccessException{
|
||||
_list = List.empty(growable: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
var alignment = Alignment.topCenter;
|
||||
if(_list.isEmpty){
|
||||
alignment = Alignment.center;
|
||||
_list.add(const Center(
|
||||
child: Text('nothing in this directory'),
|
||||
));
|
||||
}
|
||||
FileOptionsMenu menu;
|
||||
if(_mode == FMMode.selection){
|
||||
menu = FileOptionsMenu(selected: _selected);
|
||||
}
|
||||
else{
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
leading: IconButton(onPressed: backButtonPressed, icon: const Icon(Icons.arrow_back)),
|
||||
actions: [menu],
|
||||
),
|
||||
body: Align(
|
||||
alignment: alignment,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: _list,
|
||||
),
|
||||
),
|
||||
floatingActionButton: _faButton
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue