2024-01-26 21:02:11 -05:00
|
|
|
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-01-29 22:38:19 -05:00
|
|
|
import 'package:provider/provider.dart';
|
2024-01-26 21:02:11 -05:00
|
|
|
import 'package:veilid_support/veilid_support.dart';
|
|
|
|
|
|
|
|
import '../../account_manager/account_manager.dart';
|
|
|
|
import '../../theme/theme.dart';
|
|
|
|
import '../../tools/tools.dart';
|
|
|
|
import 'home_account_invalid.dart';
|
|
|
|
import 'home_account_locked.dart';
|
|
|
|
import 'home_account_missing.dart';
|
|
|
|
import 'home_account_ready/home_account_ready.dart';
|
2024-01-27 20:10:30 -05:00
|
|
|
import 'home_no_active.dart';
|
2024-01-26 21:02:11 -05:00
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
const HomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
HomePageState createState() => HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|
|
|
final _unfocusNode = FocusNode();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
await changeWindowSetup(
|
|
|
|
TitleBarStyle.normal, OrientationCapability.normal);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_unfocusNode.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildWithLogin(BuildContext context, IList<LocalAccount> localAccounts,
|
|
|
|
Typed<FixedEncodedString43>? activeUserLogin) {
|
2024-01-27 20:10:30 -05:00
|
|
|
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
|
|
|
|
2024-01-26 21:02:11 -05:00
|
|
|
if (activeUserLogin == null) {
|
|
|
|
// If no logged in user is active, show the loading panel
|
2024-01-27 20:10:30 -05:00
|
|
|
return const HomeNoActive();
|
2024-01-26 21:02:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
final accountInfo = AccountRepository.instance
|
|
|
|
.getAccountInfo(accountMasterRecordKey: activeUserLogin)!;
|
|
|
|
|
|
|
|
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-01-29 22:38:19 -05:00
|
|
|
return Provider.value(
|
|
|
|
value: accountInfo.activeAccountInfo,
|
|
|
|
child: BlocProvider(
|
|
|
|
create: (context) => AccountRecordCubit(
|
|
|
|
record: accountInfo.activeAccountInfo!.accountRecord),
|
|
|
|
child: HomeAccountReady()));
|
2024-01-26 21:02:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
final scale = theme.extension<ScaleScheme>()!;
|
|
|
|
|
|
|
|
return SafeArea(
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => FocusScope.of(context).requestFocus(_unfocusNode),
|
|
|
|
child: DecoratedBox(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: scale.primaryScale.activeElementBackground),
|
2024-01-27 20:10:30 -05:00
|
|
|
child: buildWithLogin(context))));
|
2024-01-26 21:02:11 -05:00
|
|
|
}
|
|
|
|
}
|