2022-09-28 09:56:51 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-09-25 22:12:57 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-28 13:31:24 +00:00
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2022-09-27 12:43:34 +00:00
|
|
|
import 'package:gallery/image_grid.dart';
|
2022-09-28 13:31:24 +00:00
|
|
|
import 'package:gallery/settings_page.dart';
|
2022-09-27 15:17:15 +00:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-09-25 22:12:57 +00:00
|
|
|
|
2022-09-27 09:53:58 +00:00
|
|
|
import 'data_provider/local_data_provider.dart';
|
2022-09-27 12:43:34 +00:00
|
|
|
import 'data_provider/ssh_data_provider.dart';
|
2022-09-25 22:12:57 +00:00
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
2022-09-28 13:31:24 +00:00
|
|
|
enum Page { local, remote, settings }
|
2022-09-25 22:12:57 +00:00
|
|
|
|
2022-09-27 12:43:34 +00:00
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
Page page = Page.local;
|
2022-09-25 22:12:57 +00:00
|
|
|
|
2022-09-28 09:56:51 +00:00
|
|
|
Future<Directory> _getLocalDir() async {
|
|
|
|
Directory dir;
|
|
|
|
if (Theme.of(context).platform == TargetPlatform.android) {
|
|
|
|
dir = Directory("/storage/emulated/0/DCIM/");
|
|
|
|
} else {
|
|
|
|
dir = (await getDownloadsDirectory())?.parent ??
|
|
|
|
await getApplicationDocumentsDirectory();
|
|
|
|
}
|
|
|
|
return dir;
|
|
|
|
}
|
2022-09-27 15:17:15 +00:00
|
|
|
|
2022-09-27 12:43:34 +00:00
|
|
|
Widget _buildPage() {
|
|
|
|
switch (page) {
|
|
|
|
case Page.local:
|
2022-09-28 13:31:24 +00:00
|
|
|
return ImageGrid(dProvider: LocalDataProvider(_getLocalDir()));
|
2022-09-27 12:43:34 +00:00
|
|
|
case Page.remote:
|
|
|
|
// todo do not generate a new provider on each tab switch
|
2022-09-28 13:31:24 +00:00
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
|
|
|
|
return ImageGrid(
|
|
|
|
dProvider: SSHDataProvider(
|
|
|
|
initialPath:
|
|
|
|
Future.value("/media/3TBRaid/3TBRaid/Bilder/2022/"),
|
|
|
|
host: (() async => (await storage.read(key: "host")) ?? "")
|
|
|
|
.call(),
|
|
|
|
password:
|
|
|
|
(() async => (await storage.read(key: "pwd")) ?? "").call(),
|
|
|
|
port: Future.value(22),
|
|
|
|
username: (() async => (await storage.read(key: "user")) ?? "")
|
|
|
|
.call()));
|
|
|
|
case Page.settings:
|
|
|
|
return const SettingsPage();
|
2022-09-27 12:43:34 +00:00
|
|
|
}
|
2022-09-25 22:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(widget.title),
|
|
|
|
),
|
2022-09-27 12:43:34 +00:00
|
|
|
body: _buildPage(),
|
|
|
|
drawer: Drawer(
|
|
|
|
child: ListView(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children: [
|
|
|
|
DrawerHeader(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).primaryColor,
|
2022-09-25 22:12:57 +00:00
|
|
|
),
|
2022-09-27 12:43:34 +00:00
|
|
|
child: const Text('Gallery'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Local'),
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
page = Page.local;
|
|
|
|
});
|
2022-09-27 15:17:15 +00:00
|
|
|
Navigator.pop(context);
|
2022-09-25 22:12:57 +00:00
|
|
|
},
|
2022-09-27 12:43:34 +00:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Remote'),
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
page = Page.remote;
|
|
|
|
});
|
2022-09-27 15:17:15 +00:00
|
|
|
Navigator.pop(context);
|
2022-09-27 12:43:34 +00:00
|
|
|
},
|
|
|
|
),
|
2022-09-28 13:31:24 +00:00
|
|
|
ListTile(
|
|
|
|
title: const Text('Settings'),
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
page = Page.settings;
|
|
|
|
});
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
),
|
2022-09-27 12:43:34 +00:00
|
|
|
],
|
|
|
|
),
|
2022-09-25 22:12:57 +00:00
|
|
|
),
|
2022-09-27 12:43:34 +00:00
|
|
|
// floatingActionButton: FloatingActionButton(
|
|
|
|
// onPressed: () {
|
|
|
|
// // _controller.animateTo(.0,
|
|
|
|
// // duration: const Duration(milliseconds: 400),
|
|
|
|
// // curve: Curves.easeInOutQuad);
|
|
|
|
// },
|
|
|
|
// tooltip: 'Increment',
|
|
|
|
// child: const Icon(Icons.arrow_upward),
|
|
|
|
// ),
|
2022-09-25 22:12:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|