handleServiceReplayState function
Implementation
Widget? handleServiceReplayState(
BuildContext context,
ServiceReplayBlocState serviceState,
) {
Widget? errorWidget;
final inScaffold = Scaffold.maybeOf(context) != null;
final l10n = HyttaHubLocalizations.of(context)!;
if (!serviceState.hasState()) {
errorWidget = const Center(child: CircularProgressIndicator());
}
switch (serviceState.state) {
case CommonReplayStateEnum.listening:
errorWidget = null;
break;
case CommonReplayStateEnum.hydrating:
errorWidget = const Center(child: CircularProgressIndicator());
break;
case CommonReplayStateEnum.uninitializedListening:
// Return null so that the shell route can handle this state
// (e.g. by showing the ServiceUninitializedPage)
errorWidget = null;
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));
} else {
return errorWidget;
}
}
return null;
}