2020-07-04 08:22:51 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'matrix.dart';
|
|
|
|
|
|
|
|
class ConnectionStatusHeader extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ConnectionStatusHeaderState createState() => _ConnectionStatusHeaderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConnectionStatusHeaderState extends State<ConnectionStatusHeader> {
|
|
|
|
StreamSubscription _onSyncSub;
|
|
|
|
StreamSubscription _onSyncErrorSub;
|
2020-10-03 13:53:08 +00:00
|
|
|
static bool _connected = true;
|
2020-07-04 08:22:51 +00:00
|
|
|
|
|
|
|
set connected(bool connected) {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() => _connected = connected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_onSyncSub?.cancel();
|
|
|
|
_onSyncErrorSub?.cancel();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
_onSyncSub ??= Matrix.of(context).client.onSync.stream.listen(
|
|
|
|
(_) => connected = true,
|
|
|
|
);
|
|
|
|
_onSyncErrorSub ??= Matrix.of(context).client.onSyncError.stream.listen(
|
|
|
|
(_) => connected = false,
|
|
|
|
);
|
|
|
|
|
|
|
|
return AnimatedContainer(
|
2020-10-04 08:05:00 +00:00
|
|
|
duration: Duration(milliseconds: 300),
|
2020-07-04 08:22:51 +00:00
|
|
|
height: _connected ? 0 : 5,
|
|
|
|
child: LinearProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|