pop menu when selecting drawer item

default to documents folder
This commit is contained in:
lukas-heiligenbrunner 2022-09-27 17:17:15 +02:00
parent 195898009c
commit a80b547656
3 changed files with 14 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart';
import 'package:gallery/data_provider/data_provider.dart';
class LocalDataProvider extends DataProvider {
final String initialPath;
final Future<Directory> initialPath;
LocalDataProvider(this.initialPath);
@ -13,7 +13,7 @@ class LocalDataProvider extends DataProvider {
@override
Future<Folder> listOfFiles({Uri? uri}) async {
final dir = uri != null ? Directory.fromUri(uri) : Directory(initialPath);
final dir = uri != null ? Directory.fromUri(uri) : await initialPath;
final list = dir.listSync();
final List<Item> res = [];

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gallery/data_provider/data_provider.dart';
import 'package:gallery/image_grid.dart';
import 'package:path_provider/path_provider.dart';
import 'data_provider/local_data_provider.dart';
import 'data_provider/ssh_data_provider.dart';
@ -19,17 +20,23 @@ enum Page { local, remote }
class _MyHomePageState extends State<MyHomePage> {
Page page = Page.local;
final DataProvider localProvider = LocalDataProvider(getApplicationDocumentsDirectory());
Widget _buildPage() {
DataProvider provider;
switch (page) {
case Page.local:
provider = LocalDataProvider("/home");
provider = localProvider;
break;
case Page.remote:
// todo do not generate a new provider on each tab switch
provider = SSHDataProvider(
initialPath: "/", host: "", password: "", port: 0, username: "");
initialPath: "/",
host: "",
password: "",
port: 0,
username: "");
break;
}
return ImageGrid(dProvider: provider);
@ -58,6 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() {
page = Page.local;
});
Navigator.pop(context);
},
),
ListTile(
@ -66,6 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() {
page = Page.remote;
});
Navigator.pop(context);
},
),
],

View File

@ -30,10 +30,7 @@ class _ImageGridState extends State<ImageGrid> {
final width = MediaQuery.of(context).size.width;
return FutureBuilder(
future: (() async {
await widget.dProvider.connect();
return folder;
}).call(),
future: folder,
builder: (context, AsyncSnapshot<Folder> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData && snapshot.data != null) {