mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 03:05:14 +00:00
feat: Show progress bar and sync status
This commit is contained in:
parent
a6a88c75ba
commit
777a27c60e
4 changed files with 36 additions and 20 deletions
|
@ -1114,6 +1114,11 @@
|
|||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"synchronizingPleaseWait": "Synchronizing… Please wait.",
|
||||
"@synchronizingPleaseWait": {
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"loadMore": "Load more…",
|
||||
"@loadMore": {
|
||||
"type": "text",
|
||||
|
|
|
@ -19,7 +19,7 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|||
_lastSyncReceived.millisecondsSinceEpoch <
|
||||
1000 * 30;
|
||||
static DateTime _lastSyncReceived = DateTime(0);
|
||||
SdkError _error;
|
||||
SyncStatusUpdate _status = SyncStatusUpdate(SyncStatus.waitingForResponse);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
|
@ -30,25 +30,19 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
|
||||
(_) => setState(
|
||||
_onSyncSub ??= Matrix.of(context).client.onSyncStatus.stream.listen(
|
||||
(status) => setState(
|
||||
() {
|
||||
_lastSyncReceived = DateTime.now();
|
||||
_error = null;
|
||||
},
|
||||
),
|
||||
);
|
||||
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
|
||||
(error) => setState(
|
||||
() {
|
||||
_lastSyncReceived = DateTime(0);
|
||||
_error = error;
|
||||
if (status.status == SyncStatus.finished) {
|
||||
_lastSyncReceived = DateTime.now();
|
||||
}
|
||||
_status = status;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: Duration(milliseconds: 250),
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.bounceInOut,
|
||||
height: _connected ? 0 : 36,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
|
@ -60,13 +54,14 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|||
SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
value: _status.progress,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Text(
|
||||
_error != null
|
||||
? (_error.exception as Object).toLocalizedString(context)
|
||||
: L10n.of(context).loadingPleaseWait,
|
||||
_status.toLocalizedString(context),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
@ -75,3 +70,19 @@ class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension on SyncStatusUpdate {
|
||||
String toLocalizedString(BuildContext context) {
|
||||
switch (status) {
|
||||
case SyncStatus.waitingForResponse:
|
||||
return L10n.of(context).loadingPleaseWait;
|
||||
case SyncStatus.error:
|
||||
return (error.exception as Object).toLocalizedString(context);
|
||||
case SyncStatus.processing:
|
||||
case SyncStatus.cleaningUp:
|
||||
case SyncStatus.finished:
|
||||
default:
|
||||
return L10n.of(context).synchronizingPleaseWait;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -589,7 +589,7 @@ packages:
|
|||
name: matrix
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.3"
|
||||
version: "0.1.4"
|
||||
matrix_api_lite:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -41,7 +41,7 @@ dependencies:
|
|||
image_picker: ^0.7.4
|
||||
intl: any
|
||||
localstorage: ^4.0.0+1
|
||||
matrix: ^0.1.3
|
||||
matrix: ^0.1.4
|
||||
mime_type: ^1.0.0
|
||||
moor: ^4.2.1
|
||||
native_imaging:
|
||||
|
|
Loading…
Reference in a new issue