veilidchat/lib/layout/home/home_shell.dart

75 lines
2.2 KiB
Dart
Raw Normal View History

2024-02-11 23:18:20 -05:00
import 'package:flutter/material.dart';
2024-02-13 22:03:26 -05:00
import 'package:flutter_bloc/flutter_bloc.dart';
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-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 {
const HomeShell({required this.accountReadyBuilder, super.key});
2024-02-11 23:18:20 -05:00
@override
HomeShellState createState() => HomeShellState();
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();
}
Widget buildWithLogin(BuildContext context) {
2024-02-13 22:03:26 -05:00
final activeLocalAccount = context.watch<ActiveLocalAccountCubit>().state;
if (activeLocalAccount == null) {
// If no logged in user is active, show the loading panel
return const HomeNoActive();
}
final accountInfo =
AccountRepository.instance.getAccountInfo(activeLocalAccount);
switch (accountInfo.status) {
case AccountInfoStatus.noAccount:
return const HomeAccountMissing();
case AccountInfoStatus.accountInvalid:
return const HomeAccountInvalid();
case AccountInfoStatus.accountLocked:
return const HomeAccountLocked();
case AccountInfoStatus.accountReady:
return Provider<ActiveAccountInfo>.value(
value: accountInfo.activeAccountInfo!,
child: BlocProvider(
create: (context) => AccountRecordCubit(
2024-04-01 09:04:54 -04:00
open: () async => AccountRepository.instance
.openAccountRecord(
accountInfo.activeAccountInfo!.userLogin)),
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>()!;
// XXX: eventually write account switcher here
return SafeArea(
2024-04-10 16:13:08 -04:00
child: DecoratedBox(
decoration: BoxDecoration(
color: scale.primaryScale.activeElementBackground),
child: buildWithLogin(context)));
2024-02-11 23:18:20 -05:00
}
}