selfprivacy.org.app/lib/ui/pages/root_route.dart

58 lines
1.9 KiB
Dart
Raw Normal View History

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';
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';
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
@RoutePage()
class RootPage extends StatefulWidget implements AutoRouteWrapper {
const RootPage({super.key});
2020-11-29 20:07:46 +00:00
@override
State<RootPage> createState() => _RootPageState();
@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 {
@override
void didChangeDependencies() {
if (InheritedAppController.of(context).shouldShowOnboarding) {
context.router.replace(const OnboardingRoute());
}
2020-11-29 20:07:46 +00:00
super.didChangeDependencies();
}
2022-05-30 13:49:42 +00:00
2020-11-29 20:07:46 +00:00
@override
Widget build(final BuildContext context) {
final bool isReady = context.watch<ServerInstallationCubit>().state
is ServerInstallationFinished;
return AutoRouter(
builder: (final context, final child) {
final currentDestinationIndex = rootDestinations.indexWhere(
(final destination) =>
context.router.isRouteActive(destination.route.routeName),
);
final isOtherRouterActive =
context.router.root.current.name != RootRoute.name;
final routeName = getRouteTitle(context.router.current.name).tr();
return RootScaffoldWithNavigation(
title: routeName,
destinations: rootDestinations,
showBottomBar:
!(currentDestinationIndex == -1 && !isOtherRouterActive),
showFab: isReady,
child: child,
);
},
);
2020-11-29 20:07:46 +00:00
}
}