refactor: Make router static
This commit is contained in:
parent
d2247018e6
commit
d6b48091c4
3 changed files with 308 additions and 298 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
|
||||||
|
|
||||||
import 'package:fluffychat/config/themes.dart';
|
import 'package:fluffychat/config/themes.dart';
|
||||||
import 'package:fluffychat/pages/add_story/add_story.dart';
|
import 'package:fluffychat/pages/add_story/add_story.dart';
|
||||||
|
|
@ -33,235 +34,236 @@ import 'package:fluffychat/widgets/layouts/empty_page.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/side_view_layout.dart';
|
import 'package:fluffychat/widgets/layouts/side_view_layout.dart';
|
||||||
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
import 'package:fluffychat/widgets/layouts/two_column_layout.dart';
|
||||||
import 'package:fluffychat/widgets/log_view.dart';
|
import 'package:fluffychat/widgets/log_view.dart';
|
||||||
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
|
|
||||||
class AppRoutes {
|
abstract class AppRoutes {
|
||||||
final List<Client> clients;
|
static FutureOr<String?> loggedInRedirect(
|
||||||
|
BuildContext context,
|
||||||
|
GoRouterState state,
|
||||||
|
) =>
|
||||||
|
Matrix.of(context).client.isLogged() ? '/rooms' : null;
|
||||||
|
|
||||||
bool get isLoggedIn => clients.any((client) => client.isLogged());
|
static FutureOr<String?> loggedOutRedirect(
|
||||||
|
BuildContext context,
|
||||||
|
GoRouterState state,
|
||||||
|
) =>
|
||||||
|
Matrix.of(context).client.isLogged() ? null : '/home';
|
||||||
|
|
||||||
AppRoutes(this.clients);
|
AppRoutes();
|
||||||
|
|
||||||
List<RouteBase> get routes => [
|
static final List<RouteBase> routes = [
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
redirect: (context, state) =>
|
||||||
|
Matrix.of(context).client.isLogged() ? '/rooms' : '/home',
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/home',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const HomeserverPicker(),
|
||||||
|
),
|
||||||
|
redirect: loggedInRedirect,
|
||||||
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/',
|
path: 'login',
|
||||||
redirect: (context, state) => isLoggedIn ? '/rooms' : '/home',
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/home',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const HomeserverPicker(),
|
const Login(),
|
||||||
|
),
|
||||||
|
redirect: loggedInRedirect,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/logs',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const LogViewer(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ShellRoute(
|
||||||
|
pageBuilder: (context, state, child) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
FluffyThemes.isColumnMode(context) &&
|
||||||
|
state.fullPath?.startsWith('/rooms/settings') == false
|
||||||
|
? TwoColumnLayout(
|
||||||
|
displayNavigationRail:
|
||||||
|
state.path?.startsWith('/rooms/settings') != true,
|
||||||
|
mainView: ChatList(
|
||||||
|
activeChat: state.pathParameters['roomid'],
|
||||||
|
displayNavigationRail:
|
||||||
|
state.path?.startsWith('/rooms/settings') != true,
|
||||||
|
),
|
||||||
|
sideView: child,
|
||||||
|
)
|
||||||
|
: child,
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/rooms',
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
FluffyThemes.isColumnMode(context)
|
||||||
|
? const EmptyPage()
|
||||||
|
: ChatList(
|
||||||
|
activeChat: state.pathParameters['roomid'],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => isLoggedIn ? '/rooms' : null,
|
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'login',
|
path: 'stories/create',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const Login(),
|
const AddStoryPage(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => isLoggedIn ? '/rooms' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/logs',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const LogViewer(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ShellRoute(
|
|
||||||
pageBuilder: (context, state, child) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
FluffyThemes.isColumnMode(context) &&
|
|
||||||
state.fullPath?.startsWith('/rooms/settings') == false
|
|
||||||
? TwoColumnLayout(
|
|
||||||
displayNavigationRail:
|
|
||||||
state.path?.startsWith('/rooms/settings') != true,
|
|
||||||
mainView: ChatList(
|
|
||||||
activeChat: state.pathParameters['roomid'],
|
|
||||||
displayNavigationRail:
|
|
||||||
state.path?.startsWith('/rooms/settings') != true,
|
|
||||||
),
|
|
||||||
sideView: child,
|
|
||||||
)
|
|
||||||
: child,
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/rooms',
|
path: 'stories/:roomid',
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
FluffyThemes.isColumnMode(context)
|
const StoryPage(),
|
||||||
? const EmptyPage()
|
|
||||||
: ChatList(
|
|
||||||
activeChat: state.pathParameters['roomid'],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'stories/create',
|
path: 'share',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const AddStoryPage(),
|
const AddStoryPage(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'spaces/:roomid',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
ChatDetails(
|
||||||
|
roomId: state.pathParameters['roomid']!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
routes: _chatDetailsRoutes,
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'archive',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const Archive(),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'stories/:roomid',
|
path: ':roomid',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const StoryPage(),
|
ChatPage(
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'share',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const AddStoryPage(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'spaces/:roomid',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
ChatDetails(
|
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
routes: _chatDetailsRoutes,
|
redirect: loggedOutRedirect,
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'newprivatechat',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const NewPrivateChat(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'newgroup',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const NewGroup(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'newspace',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const NewSpace(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
ShellRoute(
|
||||||
|
pageBuilder: (context, state, child) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
FluffyThemes.isColumnMode(context)
|
||||||
|
? TwoColumnLayout(
|
||||||
|
mainView: const Settings(),
|
||||||
|
sideView: child,
|
||||||
|
displayNavigationRail: false,
|
||||||
|
)
|
||||||
|
: child,
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'archive',
|
path: 'settings',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const Archive(),
|
FluffyThemes.isColumnMode(context)
|
||||||
|
? const EmptyPage()
|
||||||
|
: const Settings(),
|
||||||
),
|
),
|
||||||
|
routes: _settingsRoutes,
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
ShellRoute(
|
||||||
|
pageBuilder: (context, state, child) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
SideViewLayout(
|
||||||
|
mainView: ChatPage(
|
||||||
|
roomId: state.pathParameters['roomid']!,
|
||||||
|
),
|
||||||
|
sideView: child,
|
||||||
|
hideSideView: state.fullPath == '/rooms/:roomid',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: ':roomid',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SizedBox.shrink(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: ':roomid',
|
path: 'encryption',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
ChatPage(
|
const ChatEncryptionSettings(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'invite',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const InvitationSelection(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'details',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
ChatDetails(
|
||||||
roomId: state.pathParameters['roomid']!,
|
roomId: state.pathParameters['roomid']!,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
redirect: (context, state) =>
|
routes: _chatDetailsRoutes,
|
||||||
!isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
|
||||||
],
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'newprivatechat',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const NewPrivateChat(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'newgroup',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const NewGroup(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'newspace',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const NewSpace(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
ShellRoute(
|
|
||||||
pageBuilder: (context, state, child) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
FluffyThemes.isColumnMode(context)
|
|
||||||
? TwoColumnLayout(
|
|
||||||
mainView: const Settings(),
|
|
||||||
sideView: child,
|
|
||||||
displayNavigationRail: false,
|
|
||||||
)
|
|
||||||
: child,
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'settings',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
FluffyThemes.isColumnMode(context)
|
|
||||||
? const EmptyPage()
|
|
||||||
: const Settings(),
|
|
||||||
),
|
|
||||||
routes: _settingsRoutes,
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
ShellRoute(
|
|
||||||
pageBuilder: (context, state, child) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
SideViewLayout(
|
|
||||||
mainView: ChatPage(
|
|
||||||
roomId: state.pathParameters['roomid']!,
|
|
||||||
),
|
|
||||||
sideView:
|
|
||||||
state.fullPath == '/rooms/:roomid' ? null : child,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: ':roomid',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const EmptyPage(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'encryption',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const ChatEncryptionSettings(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'invite',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const InvitationSelection(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'details',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
ChatDetails(
|
|
||||||
roomId: state.pathParameters['roomid']!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
routes: _chatDetailsRoutes,
|
|
||||||
redirect: (context, state) =>
|
|
||||||
!isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -269,148 +271,150 @@ class AppRoutes {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
];
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
List<RouteBase> get _chatDetailsRoutes => [
|
static final List<RouteBase> _chatDetailsRoutes = [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'permissions',
|
path: 'permissions',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const ChatPermissionsSettings(),
|
const ChatPermissionsSettings(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'invite',
|
path: 'invite',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const InvitationSelection(),
|
const InvitationSelection(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'multiple_emotes',
|
path: 'multiple_emotes',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const MultipleEmotesSettings(),
|
const MultipleEmotesSettings(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'emotes',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const EmotesSettings(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'emotes/:state_key',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const EmotesSettings(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
static final List<RouteBase> _settingsRoutes = [
|
||||||
|
GoRoute(
|
||||||
|
path: 'notifications',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsNotifications(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'style',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsStyle(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'devices',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const DevicesSettings(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'chat',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsChat(),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'emotes',
|
path: 'emotes',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const EmotesSettings(),
|
const EmotesSettings(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'addaccount',
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const HomeserverPicker(),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: 'emotes/:state_key',
|
path: 'login',
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
context,
|
context,
|
||||||
const EmotesSettings(),
|
const Login(),
|
||||||
),
|
),
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
redirect: loggedOutRedirect,
|
||||||
),
|
),
|
||||||
];
|
],
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'security',
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsSecurity(),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: 'stories',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsStories(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'ignorelist',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const SettingsIgnoreList(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '3pid',
|
||||||
|
pageBuilder: (context, state) => defaultPageBuilder(
|
||||||
|
context,
|
||||||
|
const Settings3Pid(),
|
||||||
|
),
|
||||||
|
redirect: loggedOutRedirect,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
List<RouteBase> get _settingsRoutes => [
|
static Page defaultPageBuilder(BuildContext context, Widget child) =>
|
||||||
GoRoute(
|
|
||||||
path: 'notifications',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsNotifications(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'style',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsStyle(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'devices',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const DevicesSettings(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'chat',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsChat(),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'emotes',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const EmotesSettings(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'addaccount',
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const HomeserverPicker(),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'login',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const Login(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'security',
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsSecurity(),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: 'stories',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsStories(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: 'ignorelist',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const SettingsIgnoreList(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '3pid',
|
|
||||||
pageBuilder: (context, state) => defaultPageBuilder(
|
|
||||||
context,
|
|
||||||
const Settings3Pid(),
|
|
||||||
),
|
|
||||||
redirect: (context, state) => !isLoggedIn ? '/home' : null,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
Page defaultPageBuilder(BuildContext context, Widget child) =>
|
|
||||||
CustomTransitionPage(
|
CustomTransitionPage(
|
||||||
child: child,
|
child: child,
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ class FluffyChatApp extends StatelessWidget {
|
||||||
/// in with qr code or magic link.
|
/// in with qr code or magic link.
|
||||||
static bool gotInitialLink = false;
|
static bool gotInitialLink = false;
|
||||||
|
|
||||||
|
// Router must be outside of build method so that hot reload does not reset
|
||||||
|
// the current path.
|
||||||
|
static final GoRouter router = GoRouter(routes: AppRoutes.routes);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ThemeBuilder(
|
return ThemeBuilder(
|
||||||
|
|
@ -37,11 +41,11 @@ class FluffyChatApp extends StatelessWidget {
|
||||||
scrollBehavior: CustomScrollBehavior(),
|
scrollBehavior: CustomScrollBehavior(),
|
||||||
localizationsDelegates: L10n.localizationsDelegates,
|
localizationsDelegates: L10n.localizationsDelegates,
|
||||||
supportedLocales: L10n.supportedLocales,
|
supportedLocales: L10n.supportedLocales,
|
||||||
routerConfig: GoRouter(routes: AppRoutes(clients).routes),
|
routerConfig: router,
|
||||||
builder: (context, child) => Matrix(
|
builder: (context, child) => Matrix(
|
||||||
context: context,
|
context: context,
|
||||||
clients: clients,
|
clients: clients,
|
||||||
child: child,
|
child: testWidget ?? child,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,20 @@ import 'package:fluffychat/config/themes.dart';
|
||||||
|
|
||||||
class SideViewLayout extends StatelessWidget {
|
class SideViewLayout extends StatelessWidget {
|
||||||
final Widget mainView;
|
final Widget mainView;
|
||||||
final Widget? sideView;
|
final Widget sideView;
|
||||||
|
final bool hideSideView;
|
||||||
|
|
||||||
const SideViewLayout({Key? key, required this.mainView, this.sideView})
|
const SideViewLayout({
|
||||||
: super(key: key);
|
Key? key,
|
||||||
|
required this.mainView,
|
||||||
|
required this.sideView,
|
||||||
|
required this.hideSideView,
|
||||||
|
}) : super(key: key);
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sideView = this.sideView;
|
final sideView = this.sideView;
|
||||||
final hideSideView =
|
|
||||||
!FluffyThemes.isThreeColumnMode(context) || sideView == null;
|
|
||||||
const sideViewWidth = 360.0;
|
const sideViewWidth = 360.0;
|
||||||
|
final threeColumnMode = FluffyThemes.isThreeColumnMode(context);
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
AnimatedPositioned(
|
AnimatedPositioned(
|
||||||
|
|
@ -22,7 +26,7 @@ class SideViewLayout extends StatelessWidget {
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
right: hideSideView ? 0 : sideViewWidth,
|
right: !threeColumnMode || hideSideView ? 0 : sideViewWidth,
|
||||||
child: ClipRRect(child: mainView),
|
child: ClipRRect(child: mainView),
|
||||||
),
|
),
|
||||||
AnimatedPositioned(
|
AnimatedPositioned(
|
||||||
|
|
@ -31,12 +35,10 @@ class SideViewLayout extends StatelessWidget {
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
left: !FluffyThemes.isThreeColumnMode(context) && sideView != null
|
left: !threeColumnMode && !hideSideView ? 0 : null,
|
||||||
|
width: hideSideView
|
||||||
? 0
|
? 0
|
||||||
: null,
|
: !threeColumnMode
|
||||||
width: sideView == null
|
|
||||||
? 0
|
|
||||||
: !FluffyThemes.isThreeColumnMode(context)
|
|
||||||
? null
|
? null
|
||||||
: sideViewWidth,
|
: sideViewWidth,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue