appbar now stay same, also rework, no more pushing and popping, manual animations
This commit is contained in:
parent
ae32866d46
commit
23cd60701c
1 changed files with 157 additions and 127 deletions
|
@ -7,10 +7,9 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:fluxcloud/sftp_worker.dart';
|
import 'package:fluxcloud/sftp_worker.dart';
|
||||||
|
|
||||||
class SftpExplorer extends StatefulWidget {
|
class SftpExplorer extends StatefulWidget {
|
||||||
const SftpExplorer({super.key, required this.sftpWorker, this.path = '/'});
|
const SftpExplorer({super.key, required this.sftpWorker});
|
||||||
|
|
||||||
final SftpWorker sftpWorker;
|
final SftpWorker sftpWorker;
|
||||||
final String path;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SftpExplorer> createState() => _SftpExplorerState();
|
State<SftpExplorer> createState() => _SftpExplorerState();
|
||||||
|
@ -18,6 +17,8 @@ class SftpExplorer extends StatefulWidget {
|
||||||
|
|
||||||
class _SftpExplorerState extends State<SftpExplorer> {
|
class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
|
|
||||||
|
String path = '/';
|
||||||
|
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
late List<SftpName> _dirContents;
|
late List<SftpName> _dirContents;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
Future<void> _listDir() async {
|
Future<void> _listDir() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
try {
|
try {
|
||||||
_dirContents = await widget.sftpWorker.listdir(widget.path);
|
_dirContents = await widget.sftpWorker.listdir(path);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
@ -46,12 +47,25 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
// TODO: make appbar same for all directories
|
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
toolbarHeight: 75,
|
toolbarHeight: 75,
|
||||||
title: Text('Explorer'),
|
title: Text('Explorer'),
|
||||||
elevation: 2,
|
elevation: 2,
|
||||||
actionsPadding: EdgeInsets.only(right: 20),
|
actionsPadding: EdgeInsets.only(right: 20),
|
||||||
|
leading: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
if (path == '/') {
|
||||||
|
// TODO: figure this out
|
||||||
|
// Navigator.pop(context);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = path.substring(0, path.length - 1);
|
||||||
|
path = path.substring(0, path.lastIndexOf('/')+1);
|
||||||
|
_listDir();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: Icon(Icons.arrow_back)
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
if (_progress != null)
|
if (_progress != null)
|
||||||
Stack(
|
Stack(
|
||||||
|
@ -73,7 +87,26 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
floatingActionButton: _buildFABs(context),
|
floatingActionButton: _buildFABs(context),
|
||||||
body: _isLoading ? Center(child: CircularProgressIndicator()) : ListView.builder(
|
body: AnimatedSwitcher(
|
||||||
|
duration: Duration(milliseconds: 300),
|
||||||
|
transitionBuilder: (child, animation) {
|
||||||
|
final curved = CurvedAnimation(
|
||||||
|
parent: animation,
|
||||||
|
curve: Curves.fastOutSlowIn
|
||||||
|
);
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: ScaleTransition(
|
||||||
|
scale: Tween<double>(
|
||||||
|
begin: 0.92,
|
||||||
|
end: 1
|
||||||
|
).animate(curved),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: _isLoading ? Center(child: CircularProgressIndicator()) : ListView.builder(
|
||||||
|
key: ValueKey(path),
|
||||||
itemCount: _dirContents.length,
|
itemCount: _dirContents.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final dirEntry = _dirContents[index];
|
final dirEntry = _dirContents[index];
|
||||||
|
@ -114,7 +147,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// try {
|
// try {
|
||||||
// await widget.sftpWorker.rename('${widget.path}${dirEntry.filename}', '${widget.path}${newNameController.text}');
|
// await widget.sftpWorker.rename('${path}${dirEntry.filename}', '${widget.path}${newNameController.text}');
|
||||||
// _listDir();
|
// _listDir();
|
||||||
// }
|
// }
|
||||||
// on SftpStatusError catch (e) {
|
// on SftpStatusError catch (e) {
|
||||||
|
@ -162,10 +195,10 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
// }
|
// }
|
||||||
// await widget.sftpWorker.rmdir(path);
|
// await widget.sftpWorker.rmdir(path);
|
||||||
// }
|
// }
|
||||||
// await removeRecursively('${widget.path}${dirEntry.filename}/');
|
// await removeRecursively('${path}${dirEntry.filename}/');
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
// await widget.sftpWorker.remove('${widget.path}${dirEntry.filename}');
|
// await widget.sftpWorker.remove('${path}${dirEntry.filename}');
|
||||||
// }
|
// }
|
||||||
// _listDir();
|
// _listDir();
|
||||||
// if (context.mounted) {
|
// if (context.mounted) {
|
||||||
|
@ -184,17 +217,14 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (dirEntry.attr.isDirectory) {
|
if (dirEntry.attr.isDirectory) {
|
||||||
Navigator.push(context, MaterialPageRoute(
|
path = '$path${dirEntry.filename}/';
|
||||||
builder: (context) => SftpExplorer(
|
_listDir();
|
||||||
sftpWorker: widget.sftpWorker,
|
|
||||||
path: '${widget.path}${dirEntry.filename}/',
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +252,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
try {
|
||||||
await widget.sftpWorker.mkdir('${widget.path}${nameController.text}');
|
await widget.sftpWorker.mkdir('${path}${nameController.text}');
|
||||||
_listDir();
|
_listDir();
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
@ -255,7 +285,7 @@ class _SftpExplorerState extends State<SftpExplorer> {
|
||||||
filePaths = files.map((file) => file.path).toList();
|
filePaths = files.map((file) => file.path).toList();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await for (final progress in widget.sftpWorker.uploadFiles(widget.path, filePaths)) {
|
await for (final progress in widget.sftpWorker.uploadFiles(path, filePaths)) {
|
||||||
setState(() => _progress = progress);
|
setState(() => _progress = progress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue