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';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.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';
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2023-02-23 14:49:14 +00:00
|
|
|
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 {
|
2023-02-23 14:49:14 +00:00
|
|
|
bool shouldUseSplitView() => false;
|
2020-11-29 20:07:46 +00:00
|
|
|
|
2023-02-23 14:49:14 +00:00
|
|
|
final destinations = rootDestinations;
|
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;
|
|
|
|
|
|
|
|
if (context.read<AppSettingsCubit>().state.isOnboardingShowing) {
|
|
|
|
context.router.replace(const OnboardingRoute());
|
|
|
|
}
|
|
|
|
|
|
|
|
return AutoRouter(
|
|
|
|
builder: (final context, final child) {
|
|
|
|
final currentDestinationIndex = destinations.indexWhere(
|
|
|
|
(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;
|
2023-02-23 14:49:14 +00:00
|
|
|
final routeName = getRouteTitle(context.router.current.name).tr();
|
|
|
|
return RootScaffoldWithNavigation(
|
|
|
|
title: routeName,
|
|
|
|
destinations: destinations,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
class MainScreenNavigationRail extends StatelessWidget {
|
|
|
|
const MainScreenNavigationRail({
|
|
|
|
required this.destinations,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final List<RouteDestination> destinations;
|
2020-11-29 20:07:46 +00:00
|
|
|
|
|
|
|
@override
|
2023-02-23 14:49:14 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
int? activeIndex = destinations.indexWhere(
|
|
|
|
(final destination) =>
|
|
|
|
context.router.isRouteActive(destination.route.routeName),
|
|
|
|
);
|
|
|
|
if (activeIndex == -1) {
|
|
|
|
activeIndex = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height,
|
|
|
|
width: 72,
|
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (final context, final constraints) => SingleChildScrollView(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: NavigationRail(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
labelType: NavigationRailLabelType.all,
|
|
|
|
destinations: destinations
|
|
|
|
.map(
|
|
|
|
(final destination) => NavigationRailDestination(
|
|
|
|
icon: Icon(destination.icon),
|
|
|
|
label: Text(destination.label),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
selectedIndex: activeIndex,
|
|
|
|
onDestinationSelected: (final index) {
|
|
|
|
context.router.replaceAll([destinations[index].route]);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-11-29 20:07:46 +00:00
|
|
|
}
|
2023-02-23 14:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MainScreenNavigationDrawer extends StatelessWidget {
|
|
|
|
const MainScreenNavigationDrawer({
|
|
|
|
required this.destinations,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final List<RouteDestination> destinations;
|
2020-11-29 20:07:46 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
2023-02-23 14:49:14 +00:00
|
|
|
int? activeIndex = destinations.indexWhere(
|
|
|
|
(final destination) =>
|
|
|
|
context.router.isRouteActive(destination.route.routeName),
|
|
|
|
);
|
|
|
|
if (activeIndex == -1) {
|
|
|
|
activeIndex = null;
|
|
|
|
}
|
2022-05-30 23:06:08 +00:00
|
|
|
|
2023-02-23 14:49:14 +00:00
|
|
|
return SizedBox(
|
|
|
|
height: MediaQuery.of(context).size.height,
|
|
|
|
width: 296,
|
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (final context, final constraints) => NavigationDrawer(
|
|
|
|
key: const Key('PrimaryNavigationDrawer'),
|
|
|
|
selectedIndex: activeIndex,
|
|
|
|
onDestinationSelected: (final index) {
|
|
|
|
context.router.replaceAll([destinations[index].route]);
|
|
|
|
},
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 18),
|
|
|
|
...destinations.map(
|
|
|
|
(final destination) => NavigationDrawerDestination(
|
|
|
|
icon: Icon(destination.icon),
|
|
|
|
label: Text(destination.label),
|
|
|
|
),
|
|
|
|
),
|
2023-01-31 22:40:42 +00:00
|
|
|
],
|
2020-11-29 20:07:46 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-03-18 00:55:38 +00:00
|
|
|
|
|
|
|
class ChangeTab {
|
|
|
|
ChangeTab(this.onPress);
|
2022-06-05 19:36:32 +00:00
|
|
|
final ValueChanged<int> onPress;
|
2021-03-18 00:55:38 +00:00
|
|
|
}
|