pop menu when selecting drawer item
default to documents folder
This commit is contained in:
parent
195898009c
commit
a80b547656
@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:gallery/data_provider/data_provider.dart';
|
import 'package:gallery/data_provider/data_provider.dart';
|
||||||
|
|
||||||
class LocalDataProvider extends DataProvider {
|
class LocalDataProvider extends DataProvider {
|
||||||
final String initialPath;
|
final Future<Directory> initialPath;
|
||||||
|
|
||||||
LocalDataProvider(this.initialPath);
|
LocalDataProvider(this.initialPath);
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ class LocalDataProvider extends DataProvider {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Folder> listOfFiles({Uri? uri}) async {
|
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 = dir.listSync();
|
||||||
final List<Item> res = [];
|
final List<Item> res = [];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gallery/data_provider/data_provider.dart';
|
import 'package:gallery/data_provider/data_provider.dart';
|
||||||
import 'package:gallery/image_grid.dart';
|
import 'package:gallery/image_grid.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import 'data_provider/local_data_provider.dart';
|
import 'data_provider/local_data_provider.dart';
|
||||||
import 'data_provider/ssh_data_provider.dart';
|
import 'data_provider/ssh_data_provider.dart';
|
||||||
@ -19,17 +20,23 @@ enum Page { local, remote }
|
|||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
Page page = Page.local;
|
Page page = Page.local;
|
||||||
|
|
||||||
|
final DataProvider localProvider = LocalDataProvider(getApplicationDocumentsDirectory());
|
||||||
|
|
||||||
Widget _buildPage() {
|
Widget _buildPage() {
|
||||||
DataProvider provider;
|
DataProvider provider;
|
||||||
|
|
||||||
switch (page) {
|
switch (page) {
|
||||||
case Page.local:
|
case Page.local:
|
||||||
provider = LocalDataProvider("/home");
|
provider = localProvider;
|
||||||
break;
|
break;
|
||||||
case Page.remote:
|
case Page.remote:
|
||||||
// todo do not generate a new provider on each tab switch
|
// todo do not generate a new provider on each tab switch
|
||||||
provider = SSHDataProvider(
|
provider = SSHDataProvider(
|
||||||
initialPath: "/", host: "", password: "", port: 0, username: "");
|
initialPath: "/",
|
||||||
|
host: "",
|
||||||
|
password: "",
|
||||||
|
port: 0,
|
||||||
|
username: "");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ImageGrid(dProvider: provider);
|
return ImageGrid(dProvider: provider);
|
||||||
@ -58,6 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
page = Page.local;
|
page = Page.local;
|
||||||
});
|
});
|
||||||
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@ -66,6 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
page = Page.remote;
|
page = Page.remote;
|
||||||
});
|
});
|
||||||
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -30,10 +30,7 @@ class _ImageGridState extends State<ImageGrid> {
|
|||||||
final width = MediaQuery.of(context).size.width;
|
final width = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: (() async {
|
future: folder,
|
||||||
await widget.dProvider.connect();
|
|
||||||
return folder;
|
|
||||||
}).call(),
|
|
||||||
builder: (context, AsyncSnapshot<Folder> snapshot) {
|
builder: (context, AsyncSnapshot<Folder> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
if (snapshot.hasData && snapshot.data != null) {
|
if (snapshot.hasData && snapshot.data != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user