handleAccountReplayState function

Widget? handleAccountReplayState(
  1. BuildContext context,
  2. AccountReplayBlocState accountState
)

Implementation

Widget? handleAccountReplayState(
  BuildContext context,
  AccountReplayBlocState accountState,
) {
  Widget? errorWidget;
  final inScaffold = Scaffold.maybeOf(context) != null;

  final l10n = HyttaHubLocalizations.of(context)!;

  if (!accountState.hasState()) {
    errorWidget = const Center(child: CircularProgressIndicator());
  }

  switch (accountState.state) {
    case CommonReplayStateEnum.listening:
      errorWidget = null;
      break;
    case CommonReplayStateEnum.hydrating:
      errorWidget = const Center(child: CircularProgressIndicator());
      break;
    case CommonReplayStateEnum.uninitializedListening:
      errorWidget = AccountInitializingWidget(
        email: context.read<AuthBloc>().state.email,
      );
      break;
    case CommonReplayStateEnum.networkError:
      errorWidget = Center(child: Text(l10n.unexpectedError));
      break;
    case CommonReplayStateEnum.permissionDenied:
      errorWidget = Center(child: Text(l10n.permissionDenied));
      break;
    default:
      errorWidget = Center(child: Text(l10n.unexpectedError));
      break;
  }

  if (errorWidget != null) {
    if (!inScaffold) {
      return Scaffold(
        body: Center(child: errorWidget),
        appBar: AppBar(
          leading: context.canPop()
              ? BackButton(onPressed: () => Navigator.of(context).pop())
              : null,
        ),
      );
    } else {
      return errorWidget;
    }
  }
  return null;
}