automatic updating of last timestamp for bloc cache
This commit is contained in:
parent
76a1f65083
commit
69fc98ad45
lib
@ -96,6 +96,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
controller: App.bottomNavigator,
|
||||
navBarOverlap: const NavBarOverlap.none(),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
handleAndroidBackButtonPress: false,
|
||||
|
||||
screenTransitionAnimation: const ScreenTransitionAnimation(curve: Curves.easeOutQuad, duration: Duration(milliseconds: 200)),
|
||||
tabs: [
|
||||
|
@ -37,6 +37,10 @@ class LoadableStateBloc extends Bloc<LoadableStateEvent, LoadableStateState> {
|
||||
: Icons.signal_wifi_connected_no_internet_4
|
||||
: Icons.device_unknown;
|
||||
|
||||
Color connectionColor(BuildContext context) => connectivityStatusKnown() && !isConnected()
|
||||
? Colors.grey.shade600
|
||||
: Theme.of(context).primaryColor;
|
||||
|
||||
String connectionText({int? lastUpdated}) => connectivityStatusKnown()
|
||||
? isConnected()
|
||||
? 'Verbindung fehlgeschlagen'
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@ -31,14 +33,6 @@ class LoadableStateErrorBar extends StatelessWidget {
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
var bloc = context.watch<LoadableStateBloc>();
|
||||
var status = (
|
||||
icon: bloc.connectionIcon(),
|
||||
text: bloc.connectionText(lastUpdated: lastUpdated),
|
||||
color: bloc.connectivityStatusKnown() && !bloc.isConnected()
|
||||
? Colors.grey.shade600
|
||||
: Theme.of(context).primaryColor
|
||||
);
|
||||
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if(!bloc.isConnected()) return;
|
||||
@ -47,16 +41,9 @@ class LoadableStateErrorBar extends StatelessWidget {
|
||||
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))
|
||||
],
|
||||
color: bloc.connectionColor(context),
|
||||
),
|
||||
child: LoadableStateErrorBarText(lastUpdated: lastUpdated),
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -65,3 +52,41 @@ class LoadableStateErrorBar extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class LoadableStateErrorBarText extends StatefulWidget {
|
||||
final int? lastUpdated;
|
||||
const LoadableStateErrorBarText({required this.lastUpdated, super.key});
|
||||
|
||||
@override
|
||||
State<LoadableStateErrorBarText> createState() => _LoadableStateErrorBarTextState();
|
||||
}
|
||||
|
||||
class _LoadableStateErrorBarTextState extends State<LoadableStateErrorBarText> {
|
||||
late Timer _rebuildTimer;
|
||||
@override
|
||||
void initState() {
|
||||
_rebuildTimer = Timer.periodic(const Duration(seconds: 10), (timer) => setState(() {}));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var bloc = context.watch<LoadableStateBloc>();
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(bloc.connectionIcon(), size: 14),
|
||||
const SizedBox(width: 10),
|
||||
Text(bloc.connectionText(lastUpdated: widget.lastUpdated), style: const TextStyle(fontSize: 12))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_rebuildTimer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,6 @@ sealed class MarianumMessageEvent extends LoadableHydratedBlocEvent<MarianumMess
|
||||
class MessageEvent extends MarianumMessageEvent {}
|
||||
|
||||
class MarianumMessageBloc extends LoadableHydratedBloc<MarianumMessageEvent, MarianumMessageState, MarianumMessageRepository> {
|
||||
MarianumMessageBloc() {
|
||||
on<MessageEvent>((event, emit) {
|
||||
add(Emit((state) => state.copyWith.messageList(messages: [])));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> gatherData() async {
|
||||
var messages = await repo.getMessages();
|
||||
|
Loading…
x
Reference in New Issue
Block a user