automatic updating of last timestamp for bloc cache
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user