mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-04-30 01:00:04 -05:00
[client] Basic directory navigation
This commit is contained in:
+37
-11
@@ -2,13 +2,27 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_state_notifier/flutter_state_notifier.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/folder_view.dart';
|
||||
import 'package:phylum/home_page.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final _router = GoRouter(routes: [
|
||||
GoRoute(name: 'home', path: '/', builder: (context, state) => const HomePage()),
|
||||
]);
|
||||
final _router = GoRouter(
|
||||
routes: [
|
||||
ShellRoute(
|
||||
builder: (context, state, child) => NavScaffold(child: child),
|
||||
routes: [
|
||||
GoRoute(name: 'home', path: '/', builder: (context, state) => const HomePage()),
|
||||
GoRoute(
|
||||
name: 'dir',
|
||||
path: '/dir/:id',
|
||||
builder: (context, state) {
|
||||
return FolderView(id: state.pathParameters['id']!);
|
||||
}),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
class PhylumApp extends StatelessWidget {
|
||||
final String accountId;
|
||||
@@ -24,19 +38,14 @@ class PhylumApp extends StatelessWidget {
|
||||
Provider.value(value: account),
|
||||
StateNotifierProvider<ApiActionQueue, ApiActionQueueState>.value(value: account.actionQueue),
|
||||
],
|
||||
child: const _WelcomeAppContent(),
|
||||
child: const _AppContent(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WelcomeAppContent extends StatefulWidget {
|
||||
const _WelcomeAppContent();
|
||||
class _AppContent extends StatelessWidget {
|
||||
const _AppContent();
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _PhylumAppState();
|
||||
}
|
||||
|
||||
class _PhylumAppState extends State<_WelcomeAppContent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
@@ -48,3 +57,20 @@ class _PhylumAppState extends State<_WelcomeAppContent> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class NavScaffold extends StatelessWidget {
|
||||
final Widget child;
|
||||
const NavScaffold({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final router = GoRouter.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Phylum'),
|
||||
leading: router.canPop() ? BackButton(onPressed: router.pop) : null,
|
||||
),
|
||||
body: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/requests/resource_detail_request.dart';
|
||||
@@ -42,6 +43,7 @@ class _FolderViewState extends State<FolderView> {
|
||||
leading: r.getIcon(),
|
||||
title: Text(r.name),
|
||||
trailing: r.dir ? null : Text(r.getSizeString()),
|
||||
onTap: () => context.go('/dir/${r.id}'),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/folder_view.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final account = context.read<PhylumAccount>();
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Phylum'),
|
||||
),
|
||||
body: FolderView(id: account.userHome));
|
||||
class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final account = context.read<PhylumAccount>();
|
||||
WidgetsBinding.instance.addPostFrameCallback((t) {
|
||||
context.replace('/dir/${account.userHome}');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user