refactor: Migrate routes to go router
This commit is contained in:
parent
739edde729
commit
ee957ab1f6
52 changed files with 584 additions and 612 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -12,17 +11,14 @@ import '../config/app_config.dart';
|
|||
import '../utils/custom_scroll_behaviour.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class FluffyChatApp extends StatefulWidget {
|
||||
class FluffyChatApp extends StatelessWidget {
|
||||
final Widget? testWidget;
|
||||
final List<Client> clients;
|
||||
final Map<String, String>? queryParameters;
|
||||
static GlobalKey<VRouterState> routerKey = GlobalKey<VRouterState>();
|
||||
static GlobalKey<MatrixState> matrixKey = GlobalKey<MatrixState>();
|
||||
|
||||
const FluffyChatApp({
|
||||
Key? key,
|
||||
this.testWidget,
|
||||
required this.clients,
|
||||
this.queryParameters,
|
||||
}) : super(key: key);
|
||||
|
||||
/// getInitialLink may rereturn the value multiple times if this view is
|
||||
|
|
@ -30,59 +26,23 @@ class FluffyChatApp extends StatefulWidget {
|
|||
/// in with qr code or magic link.
|
||||
static bool gotInitialLink = false;
|
||||
|
||||
@override
|
||||
FluffyChatAppState createState() => FluffyChatAppState();
|
||||
}
|
||||
|
||||
class FluffyChatAppState extends State<FluffyChatApp> {
|
||||
bool? columnMode;
|
||||
String? _initialUrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initialUrl =
|
||||
widget.clients.any((client) => client.isLogged()) ? '/rooms' : '/home';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ThemeBuilder(
|
||||
builder: (context, themeMode, primaryColor) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isColumnMode =
|
||||
FluffyThemes.isColumnModeByWidth(constraints.maxWidth);
|
||||
if (isColumnMode != columnMode) {
|
||||
Logs().v('Set Column Mode = $isColumnMode');
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setState(() {
|
||||
_initialUrl = FluffyChatApp.routerKey.currentState?.url;
|
||||
columnMode = isColumnMode;
|
||||
FluffyChatApp.routerKey = GlobalKey<VRouterState>();
|
||||
});
|
||||
});
|
||||
}
|
||||
return VRouter(
|
||||
key: FluffyChatApp.routerKey,
|
||||
title: AppConfig.applicationName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
themeMode: themeMode,
|
||||
theme: FluffyThemes.buildTheme(Brightness.light, primaryColor),
|
||||
darkTheme: FluffyThemes.buildTheme(Brightness.dark, primaryColor),
|
||||
scrollBehavior: CustomScrollBehavior(),
|
||||
logs: kReleaseMode ? VLogs.none : VLogs.info,
|
||||
localizationsDelegates: L10n.localizationsDelegates,
|
||||
supportedLocales: L10n.supportedLocales,
|
||||
initialUrl: _initialUrl ?? '/',
|
||||
routes: AppRoutes(columnMode ?? false).routes,
|
||||
builder: (context, child) => Matrix(
|
||||
key: FluffyChatApp.matrixKey,
|
||||
context: context,
|
||||
clients: widget.clients,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
builder: (context, themeMode, primaryColor) => MaterialApp.router(
|
||||
title: AppConfig.applicationName,
|
||||
themeMode: themeMode,
|
||||
theme: FluffyThemes.buildTheme(Brightness.light, primaryColor),
|
||||
darkTheme: FluffyThemes.buildTheme(Brightness.dark, primaryColor),
|
||||
scrollBehavior: CustomScrollBehavior(),
|
||||
localizationsDelegates: L10n.localizationsDelegates,
|
||||
supportedLocales: L10n.supportedLocales,
|
||||
routerConfig: GoRouter(routes: AppRoutes(clients).routes),
|
||||
builder: (context, child) => Matrix(
|
||||
context: context,
|
||||
clients: clients,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue