Add first-load indicator and error handling
This commit is contained in:
parent
766f5a94e2
commit
33e46c9f22
3 changed files with 20 additions and 11 deletions
|
@ -62,10 +62,9 @@ class MessagingClient extends ChangeNotifier {
|
|||
int _attempts = 0;
|
||||
WebSocket? _wsChannel;
|
||||
bool _isConnecting = false;
|
||||
String _initError = "";
|
||||
bool _initDone = false;
|
||||
String? _initStatus;
|
||||
|
||||
String get initError => _initError;
|
||||
String? get initStatus => _initStatus;
|
||||
|
||||
MessagingClient({required ApiClient apiClient, required NotificationClient notificationClient})
|
||||
: _apiClient = apiClient, _notificationClient = notificationClient {
|
||||
|
@ -86,15 +85,19 @@ class MessagingClient extends ChangeNotifier {
|
|||
_wsChannel!.add(jsonEncode(data)+eofChar);
|
||||
}
|
||||
|
||||
void resetStatus() {
|
||||
_initStatus = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void refreshFriendsListWithErrorHandler () async {
|
||||
try {
|
||||
await refreshFriendsList();
|
||||
_initDone = true;
|
||||
} catch (e) {
|
||||
_initError = "$e";
|
||||
}
|
||||
_initStatus = "$e";
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshFriendsList() async {
|
||||
if (_refreshTimeout?.isActive == true) return;
|
||||
|
@ -121,7 +124,7 @@ class MessagingClient extends ChangeNotifier {
|
|||
aVal += a.userStatus.onlineStatus.compareTo(b.userStatus.onlineStatus) * 2;
|
||||
return aVal.compareTo(bVal);
|
||||
}));
|
||||
_initError = "";
|
||||
_initStatus = "";
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
|
|
@ -254,19 +254,24 @@ class _FriendsListState extends State<FriendsList> {
|
|||
],
|
||||
),
|
||||
body: Stack(
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
Consumer<MessagingClient>(
|
||||
builder: (context, mClient, _) {
|
||||
if (mClient.initError.isNotEmpty) {
|
||||
if (mClient.initStatus == null) {
|
||||
return const LinearProgressIndicator();
|
||||
} else if (mClient.initStatus!.isNotEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultErrorWidget(
|
||||
message: mClient.initError,
|
||||
message: mClient.initStatus,
|
||||
onRetry: () async {
|
||||
mClient.resetStatus();
|
||||
mClient.refreshFriendsListWithErrorHandler();
|
||||
},
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.0.1+1
|
||||
version: 1.0.2+1
|
||||
|
||||
environment:
|
||||
sdk: '>=2.19.6 <3.0.0'
|
||||
|
@ -52,6 +52,7 @@ dependencies:
|
|||
flutter_local_notifications: ^14.0.0+1
|
||||
collection: ^1.17.0
|
||||
package_info_plus: ^3.1.2
|
||||
provider: ^6.0.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue