Gallery/lib/home_page.dart

120 lines
3.4 KiB
Dart
Raw Normal View History

2022-09-28 09:56:51 +00:00
import 'dart:io';
2022-09-25 22:12:57 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:gallery/image_grid.dart';
import 'package:gallery/settings_page.dart';
import 'package:path_provider/path_provider.dart';
2022-09-25 22:12:57 +00:00
import 'data_provider/local_data_provider.dart';
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();
}
enum Page { local, remote, settings }
2022-09-25 22:12:57 +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;
}
Widget _buildPage() {
switch (page) {
case Page.local:
return ImageGrid(dProvider: LocalDataProvider(_getLocalDir()));
case Page.remote:
// todo do not generate a new provider on each tab switch
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-25 22:12:57 +00:00
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
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
),
child: const Text('Gallery'),
),
ListTile(
title: const Text('Local'),
onTap: () {
setState(() {
page = Page.local;
});
Navigator.pop(context);
2022-09-25 22:12:57 +00:00
},
),
ListTile(
title: const Text('Remote'),
onTap: () {
setState(() {
page = Page.remote;
});
Navigator.pop(context);
},
),
ListTile(
title: const Text('Settings'),
onTap: () {
setState(() {
page = Page.settings;
});
Navigator.pop(context);
},
),
],
),
2022-09-25 22:12:57 +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
);
}
}