64 lines
1.8 KiB
Dart
64 lines
1.8 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import './screens/home.dart';
|
||
|
import './screens/welcome.dart';
|
||
|
import './screens/room.dart';
|
||
|
import 'package:routemaster/routemaster.dart';
|
||
|
|
||
|
// routes when user is logged in
|
||
|
final routesLoggedIn = RouteMap(routes: {
|
||
|
'/': (_) => const MaterialPage(child: HomePage()),
|
||
|
'/r/:server/:tag/:page': (info) => MaterialPage(
|
||
|
child: RoomPage(info.pathParameters['server'] ?? "",
|
||
|
info.pathParameters['tag'] ?? "",
|
||
|
page: info.pathParameters['page'] ?? ""),
|
||
|
)
|
||
|
});
|
||
|
// routes when user is not logged in
|
||
|
final routesUnauthorized = RouteMap(
|
||
|
routes: {
|
||
|
'/welcome/': (_) => const MaterialPage(child: WelcomePage()),
|
||
|
'/signin': (_) => const MaterialPage(child: HomePage()),
|
||
|
'/signup': (_) => const MaterialPage(child: HomePage()),
|
||
|
},
|
||
|
onUnknownRoute: (_) => const Redirect('/welcome')
|
||
|
);
|
||
|
|
||
|
void main() {
|
||
|
runApp(const OutbagApp());
|
||
|
}
|
||
|
|
||
|
class OutbagApp extends StatefulWidget {
|
||
|
const OutbagApp({super.key});
|
||
|
|
||
|
@override
|
||
|
State<StatefulWidget> createState() => _OutbagAppState();
|
||
|
}
|
||
|
|
||
|
class _OutbagAppState extends State {
|
||
|
bool isAuthorized = false;
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
// TODO: try to login user,
|
||
|
// with existing details
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return MaterialApp.router(
|
||
|
title: "Outbag",
|
||
|
// TODO: change back to system (or load from disk)
|
||
|
//themeMode: ThemeMode.system,
|
||
|
themeMode: ThemeMode.dark,
|
||
|
theme: ThemeData(useMaterial3: true, brightness: Brightness.light),
|
||
|
darkTheme: ThemeData(useMaterial3: true, brightness: Brightness.dark),
|
||
|
routerDelegate: RoutemasterDelegate(
|
||
|
routesBuilder: (context) =>
|
||
|
isAuthorized ? routesLoggedIn : routesUnauthorized),
|
||
|
routeInformationParser: const RoutemasterParser(),
|
||
|
);
|
||
|
}
|
||
|
}
|