120 lines
3.4 KiB
Dart
120 lines
3.4 KiB
Dart
import 'dart:io';
|
|
|
|
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';
|
|
|
|
import 'data_provider/local_data_provider.dart';
|
|
import 'data_provider/ssh_data_provider.dart';
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
final String title;
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
enum Page { local, remote, settings }
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
Page page = Page.local;
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
@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,
|
|
),
|
|
child: const Text('Gallery'),
|
|
),
|
|
ListTile(
|
|
title: const Text('Local'),
|
|
onTap: () {
|
|
setState(() {
|
|
page = Page.local;
|
|
});
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
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);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// floatingActionButton: FloatingActionButton(
|
|
// onPressed: () {
|
|
// // _controller.animateTo(.0,
|
|
// // duration: const Duration(milliseconds: 400),
|
|
// // curve: Curves.easeInOutQuad);
|
|
// },
|
|
// tooltip: 'Increment',
|
|
// child: const Icon(Icons.arrow_upward),
|
|
// ),
|
|
);
|
|
}
|
|
}
|