2024-06-11 21:27:20 -04:00
|
|
|
import 'dart:math';
|
|
|
|
|
2024-02-11 23:18:20 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2024-06-11 21:27:20 -04:00
|
|
|
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';
|
2024-02-13 22:03:26 -05:00
|
|
|
import 'package:provider/provider.dart';
|
2024-02-11 23:18:20 -05:00
|
|
|
|
2024-02-13 22:03:26 -05:00
|
|
|
import '../../account_manager/account_manager.dart';
|
2024-02-11 23:18:20 -05:00
|
|
|
import '../../theme/theme.dart';
|
2024-06-11 21:27:20 -04:00
|
|
|
import 'drawer_menu/drawer_menu.dart';
|
2024-02-13 22:03:26 -05:00
|
|
|
import 'home_account_invalid.dart';
|
|
|
|
import 'home_account_locked.dart';
|
|
|
|
import 'home_account_missing.dart';
|
|
|
|
import 'home_no_active.dart';
|
2024-02-11 23:18:20 -05:00
|
|
|
|
|
|
|
class HomeShell extends StatefulWidget {
|
2024-02-24 22:27:59 -05:00
|
|
|
const HomeShell({required this.accountReadyBuilder, super.key});
|
2024-02-11 23:18:20 -05:00
|
|
|
|
|
|
|
@override
|
|
|
|
HomeShellState createState() => HomeShellState();
|
|
|
|
|
2024-02-24 22:27:59 -05:00
|
|
|
final Builder accountReadyBuilder;
|
2024-02-11 23:18:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
class HomeShellState extends State<HomeShell> {
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2024-02-24 22:27:59 -05:00
|
|
|
Widget buildWithLogin(BuildContext context) {
|
2024-06-13 14:52:34 -04:00
|
|
|
final accountInfo = context.watch<ActiveAccountInfoCubit>().state;
|
2024-06-11 21:27:20 -04:00
|
|
|
final accountRecordsCubit = context.watch<AccountRecordsBlocMapCubit>();
|
2024-06-13 14:52:34 -04:00
|
|
|
if (!accountInfo.active) {
|
2024-02-13 22:03:26 -05:00
|
|
|
// If no logged in user is active, show the loading panel
|
|
|
|
return const HomeNoActive();
|
|
|
|
}
|
|
|
|
|
2024-06-13 14:52:34 -04:00
|
|
|
final superIdentityRecordKey =
|
|
|
|
accountInfo.unlockedAccountInfo?.superIdentityRecordKey;
|
|
|
|
final activeCubit = superIdentityRecordKey == null
|
|
|
|
? null
|
|
|
|
: accountRecordsCubit.tryOperate(superIdentityRecordKey,
|
|
|
|
closure: (c) => c);
|
2024-06-11 21:27:20 -04:00
|
|
|
if (activeCubit == null) {
|
|
|
|
return waitingPage();
|
|
|
|
}
|
2024-02-13 22:03:26 -05:00
|
|
|
|
|
|
|
switch (accountInfo.status) {
|
|
|
|
case AccountInfoStatus.noAccount:
|
|
|
|
return const HomeAccountMissing();
|
|
|
|
case AccountInfoStatus.accountInvalid:
|
|
|
|
return const HomeAccountInvalid();
|
|
|
|
case AccountInfoStatus.accountLocked:
|
|
|
|
return const HomeAccountLocked();
|
|
|
|
case AccountInfoStatus.accountReady:
|
2024-06-11 21:27:20 -04:00
|
|
|
return MultiProvider(providers: [
|
2024-06-13 14:52:34 -04:00
|
|
|
Provider<UnlockedAccountInfo>.value(
|
|
|
|
value: accountInfo.unlockedAccountInfo!,
|
2024-06-11 21:27:20 -04:00
|
|
|
),
|
|
|
|
Provider<AccountRecordCubit>.value(value: activeCubit),
|
|
|
|
Provider<ZoomDrawerController>.value(value: _zoomDrawerController),
|
|
|
|
], child: widget.accountReadyBuilder);
|
2024-02-13 22:03:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-11 23:18:20 -05:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
final scale = theme.extension<ScaleScheme>()!;
|
|
|
|
|
2024-06-11 21:27:20 -04:00
|
|
|
final gradient = LinearGradient(
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
colors: [
|
|
|
|
scale.tertiaryScale.subtleBackground,
|
|
|
|
scale.tertiaryScale.appBackground,
|
|
|
|
]);
|
|
|
|
|
2024-02-11 23:18:20 -05:00
|
|
|
return SafeArea(
|
2024-04-10 16:13:08 -04:00
|
|
|
child: DecoratedBox(
|
2024-06-11 21:27:20 -04:00
|
|
|
decoration: BoxDecoration(gradient: gradient),
|
|
|
|
child: ZoomDrawer(
|
|
|
|
controller: _zoomDrawerController,
|
|
|
|
//menuBackgroundColor: Colors.transparent,
|
|
|
|
menuScreen: const DrawerMenu(),
|
|
|
|
mainScreen: DecoratedBox(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: scale.primaryScale.activeElementBackground),
|
|
|
|
child: buildWithLogin(context)),
|
|
|
|
borderRadius: 24,
|
|
|
|
showShadow: true,
|
|
|
|
angle: 0,
|
|
|
|
drawerShadowsBackgroundColor: theme.shadowColor,
|
|
|
|
mainScreenOverlayColor: theme.shadowColor.withAlpha(0x3F),
|
|
|
|
openCurve: Curves.fastEaseInToSlowEaseOut,
|
|
|
|
// duration: const Duration(milliseconds: 250),
|
|
|
|
// reverseDuration: const Duration(milliseconds: 250),
|
|
|
|
menuScreenTapClose: true,
|
2024-06-13 14:52:34 -04:00
|
|
|
mainScreenTapClose: true,
|
2024-06-11 21:27:20 -04:00
|
|
|
mainScreenScale: .25,
|
|
|
|
slideWidth: min(360, MediaQuery.of(context).size.width * 0.9),
|
|
|
|
)));
|
2024-02-11 23:18:20 -05:00
|
|
|
}
|
2024-06-11 21:27:20 -04:00
|
|
|
|
|
|
|
final ZoomDrawerController _zoomDrawerController = ZoomDrawerController();
|
2024-02-11 23:18:20 -05:00
|
|
|
}
|