added timestamp to bloc cache, showing age in offline mode

This commit is contained in:
2024-05-12 02:39:35 +02:00
parent 3281b134e0
commit ebbb70dc96
13 changed files with 302 additions and 40 deletions

View File

@ -53,13 +53,13 @@ class LoadableStateConsumer<TController extends Bloc<LoadableHydratedBlocEvent<T
bloc.reFetch = loadableState.reFetch;
return Column(
children: [
LoadableStateErrorBar(visible: loadableState.showErrorBar()),
LoadableStateErrorBar(visible: loadableState.showErrorBar(), message: loadableState.error?.message, lastUpdated: loadableState.lastFetch),
Expanded(
child: Stack(
children: [
LoadableStatePrimaryLoading(visible: loadableState.showPrimaryLoading()),
LoadableStateBackgroundLoading(visible: loadableState.showBackgroundLoading()),
LoadableStateErrorScreen(visible: loadableState.showError()),
LoadableStateErrorScreen(visible: loadableState.showError(), message: loadableState.error?.message),
AnimatedOpacity(
opacity: loadableState.showContent() ? 1.0 : 0.0,

View File

@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../../widget/infoDialog.dart';
import '../bloc/loadable_state_bloc.dart';
class LoadableStateErrorBar extends StatelessWidget {
final bool visible;
const LoadableStateErrorBar({required this.visible, super.key});
final String? message;
final int? lastUpdated;
const LoadableStateErrorBar({required this.visible, this.message, this.lastUpdated, super.key});
final Duration animationDuration = const Duration(milliseconds: 200);
@ -29,25 +32,31 @@ class LoadableStateErrorBar extends StatelessWidget {
builder: (context) {
var bloc = context.watch<LoadableStateBloc>();
var status = (
icon: bloc.connectionIcon(),
text: bloc.connectionText(),
color: bloc.connectivityStatusKnown() && !bloc.isConnected()
icon: bloc.connectionIcon(),
text: bloc.connectionText(lastUpdated: lastUpdated),
color: bloc.connectivityStatusKnown() && !bloc.isConnected()
? Colors.grey.shade600
: Theme.of(context).primaryColor
);
return Container(
height: 20,
decoration: BoxDecoration(
color: status.color,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(status.icon, size: 14),
const SizedBox(width: 10),
Text(status.text, style: const TextStyle(fontSize: 12))
],
return InkWell(
onTap: () {
if(!bloc.isConnected()) return;
InfoDialog.show(context, 'Exception: ${message.toString()}');
},
child: Container(
height: 20,
decoration: BoxDecoration(
color: status.color,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(status.icon, size: 14),
const SizedBox(width: 10),
Text(status.text, style: const TextStyle(fontSize: 12))
],
),
),
);
},

View File

@ -6,7 +6,8 @@ import 'loadable_state_consumer.dart';
class LoadableStateErrorScreen extends StatelessWidget {
final bool visible;
const LoadableStateErrorScreen({required this.visible, super.key});
final String? message;
const LoadableStateErrorScreen({required this.visible, this.message, super.key});
@override
@ -28,11 +29,19 @@ class LoadableStateErrorScreen extends StatelessWidget {
if(bloc.allowRetry()) ...[
const SizedBox(height: 10),
TextButton(onPressed: () => bloc.reFetch!(), child: const Text('Erneut versuschen')),
],
if(bloc.showErrorMessage()) ...[
const SizedBox(height: 40),
Text("bloc.loadingError!.message", style: TextStyle(color: Theme.of(context).hintColor, fontSize: 12))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
message ?? 'Task failed successfully :)',
style: TextStyle(
color: Theme.of(context).hintColor,
fontSize: 12
),
maxLines: 10,
overflow: TextOverflow.ellipsis,
),
),
],
],
),