mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-03 05:02:37 +01:00
feat: More stable connection status header
This commit is contained in:
parent
cff284c2d1
commit
2eec7bf6d0
@ -212,7 +212,6 @@ class ChatView extends StatelessWidget {
|
|||||||
SafeArea(
|
SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
ConnectionStatusHeader(),
|
|
||||||
if (controller.room.getState(EventTypes.RoomTombstone) !=
|
if (controller.room.getState(EventTypes.RoomTombstone) !=
|
||||||
null)
|
null)
|
||||||
Container(
|
Container(
|
||||||
@ -420,6 +419,7 @@ class ChatView extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
ConnectionStatusHeader(),
|
||||||
if (!controller.showEmojiPicker)
|
if (!controller.showEmojiPicker)
|
||||||
AnimatedContainer(
|
AnimatedContainer(
|
||||||
duration: Duration(milliseconds: 300),
|
duration: Duration(milliseconds: 300),
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import '../utils/localized_exception_extension.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
import 'matrix.dart';
|
import 'matrix.dart';
|
||||||
|
|
||||||
@ -11,13 +14,12 @@ class ConnectionStatusHeader extends StatefulWidget {
|
|||||||
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
||||||
StreamSubscription _onSyncSub;
|
StreamSubscription _onSyncSub;
|
||||||
StreamSubscription _onSyncErrorSub;
|
StreamSubscription _onSyncErrorSub;
|
||||||
static bool _connected = true;
|
bool get _connected =>
|
||||||
|
DateTime.now().millisecondsSinceEpoch -
|
||||||
set connected(bool connected) {
|
_lastSyncReceived.millisecondsSinceEpoch <
|
||||||
if (mounted) {
|
1000 * 30;
|
||||||
setState(() => _connected = connected);
|
static DateTime _lastSyncReceived = DateTime(0);
|
||||||
}
|
SdkError _error;
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -29,16 +31,46 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
|
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
|
||||||
(_) => connected = true,
|
(_) => setState(
|
||||||
|
() {
|
||||||
|
_lastSyncReceived = DateTime.now();
|
||||||
|
_error = null;
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
|
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
|
||||||
(_) => connected = false,
|
(error) => setState(
|
||||||
|
() {
|
||||||
|
_lastSyncReceived = DateTime(0);
|
||||||
|
_error = error;
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return AnimatedContainer(
|
return AnimatedContainer(
|
||||||
duration: Duration(milliseconds: 300),
|
duration: Duration(milliseconds: 300),
|
||||||
height: _connected ? 0 : 5,
|
height: _connected ? 0 : 36,
|
||||||
child: LinearProgressIndicator(),
|
clipBehavior: Clip.hardEdge,
|
||||||
|
decoration: BoxDecoration(),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
SizedBox(width: 12),
|
||||||
|
Text(
|
||||||
|
_error != null
|
||||||
|
? (_error.exception as Object).toLocalizedString(context)
|
||||||
|
: L10n.of(context).loadingPleaseWait,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user