2023-02-23 14:49:14 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2020-11-29 20:07:46 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-15 15:36:00 +00:00
|
|
|
import 'package:selfprivacy/config/app_controller/inherited_app_controller.dart';
|
2022-05-30 23:06:08 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/root_scaffold_with_navigation.dart';
|
|
|
|
import 'package:selfprivacy/ui/router/root_destinations.dart';
|
|
|
|
import 'package:selfprivacy/ui/router/router.dart';
|
2022-05-16 22:41:00 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2023-02-23 14:49:14 +00:00
|
|
|
class RootPage extends StatefulWidget implements AutoRouteWrapper {
|
2022-10-26 16:26:09 +00:00
|
|
|
const RootPage({super.key});
|
2020-11-29 20:07:46 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<RootPage> createState() => _RootPageState();
|
2023-02-23 14:49:14 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget wrappedRoute(final BuildContext context) => this;
|
2020-11-29 20:07:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-30 13:49:42 +00:00
|
|
|
class _RootPageState extends State<RootPage> with TickerProviderStateMixin {
|
2024-05-15 15:36:00 +00:00
|
|
|
@override
|
|
|
|
void didChangeDependencies() {
|
|
|
|
if (InheritedAppController.of(context).shouldShowOnboarding) {
|
|
|
|
context.router.replace(const OnboardingRoute());
|
|
|
|
}
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2024-05-15 15:36:00 +00:00
|
|
|
super.didChangeDependencies();
|
|
|
|
}
|
2022-05-30 13:49:42 +00:00
|
|
|
|
2020-11-29 20:07:46 +00:00
|
|
|
@override
|
2023-02-23 14:49:14 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
|
|
|
is ServerInstallationFinished;
|
|
|
|
|
|
|
|
return AutoRouter(
|
|
|
|
builder: (final context, final child) {
|
2024-05-15 15:36:00 +00:00
|
|
|
final currentDestinationIndex = rootDestinations.indexWhere(
|
2023-02-23 14:49:14 +00:00
|
|
|
(final destination) =>
|
|
|
|
context.router.isRouteActive(destination.route.routeName),
|
|
|
|
);
|
2023-02-24 12:13:17 +00:00
|
|
|
final isOtherRouterActive =
|
|
|
|
context.router.root.current.name != RootRoute.name;
|
2024-05-15 15:36:00 +00:00
|
|
|
|
2023-02-23 14:49:14 +00:00
|
|
|
final routeName = getRouteTitle(context.router.current.name).tr();
|
|
|
|
return RootScaffoldWithNavigation(
|
|
|
|
title: routeName,
|
2024-05-15 15:36:00 +00:00
|
|
|
destinations: rootDestinations,
|
2023-02-24 12:13:17 +00:00
|
|
|
showBottomBar:
|
|
|
|
!(currentDestinationIndex == -1 && !isOtherRouterActive),
|
2023-02-23 14:49:14 +00:00
|
|
|
showFab: isReady,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2020-11-29 20:07:46 +00:00
|
|
|
}
|
2023-02-23 14:49:14 +00:00
|
|
|
}
|