Merge pull request #4725 from dignow/fix/address_book_state
fix address book state
This commit is contained in:
commit
398bc0c130
@ -30,43 +30,28 @@ class _AddressBookState extends State<AddressBook> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Obx(() => Offstage(
|
||||
offstage: stateGlobal.svcStatus.value != SvcStatus.ready,
|
||||
child: FutureBuilder<Widget>(
|
||||
future: buildBody(context),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return snapshot.data!;
|
||||
} else {
|
||||
return const Offstage();
|
||||
}
|
||||
}),
|
||||
));
|
||||
|
||||
Future<Widget> buildBody(BuildContext context) async {
|
||||
return Obx(() {
|
||||
if (gFFI.userModel.userName.value.isEmpty) {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: loginDialog, child: Text(translate("Login"))));
|
||||
} else {
|
||||
if (gFFI.abModel.abLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
Widget build(BuildContext context) => Obx(() {
|
||||
if (gFFI.userModel.userName.value.isEmpty) {
|
||||
return Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: loginDialog, child: Text(translate("Login"))));
|
||||
} else {
|
||||
if (gFFI.abModel.abLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
if (gFFI.abModel.abError.isNotEmpty) {
|
||||
return _buildShowError(gFFI.abModel.abError.value);
|
||||
}
|
||||
if (gFFI.abModel.fromServer.isFalse) {
|
||||
return Offstage();
|
||||
}
|
||||
return isDesktop
|
||||
? _buildAddressBookDesktop()
|
||||
: _buildAddressBookMobile();
|
||||
}
|
||||
if (gFFI.abModel.abError.isNotEmpty) {
|
||||
return _buildShowError(gFFI.abModel.abError.value);
|
||||
}
|
||||
if (gFFI.abModel.fromServer.isFalse) {
|
||||
return Offstage();
|
||||
}
|
||||
return isDesktop
|
||||
? _buildAddressBookDesktop()
|
||||
: _buildAddressBookMobile();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Widget _buildShowError(String error) {
|
||||
return Center(
|
||||
|
@ -526,9 +526,7 @@ Future<bool?> loginDialog() async {
|
||||
});
|
||||
|
||||
if (res != null) {
|
||||
// update ab and group status
|
||||
await gFFI.abModel.pullAb();
|
||||
await gFFI.groupModel.pull();
|
||||
await UserModel.updateOtherModels();
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:flutter_hbb/models/user_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
@ -339,7 +340,6 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
stateGlobal.svcStatus.value = SvcStatus.ready;
|
||||
if (preStatus != SvcStatus.ready) {
|
||||
gFFI.userModel.refreshCurrentUser();
|
||||
gFFI.groupModel.pull();
|
||||
}
|
||||
} else {
|
||||
stateGlobal.svcStatus.value = SvcStatus.notReady;
|
||||
@ -348,6 +348,9 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
gFFI.userModel.isAdmin.value = false;
|
||||
gFFI.groupModel.reset();
|
||||
}
|
||||
if (preStatus != stateGlobal.svcStatus.value) {
|
||||
UserModel.updateOtherModels();
|
||||
}
|
||||
svcIsUsingPublicServer.value = await bind.mainIsUsingPublicServer();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class UserModel {
|
||||
void refreshCurrentUser() async {
|
||||
final token = bind.mainGetLocalOption(key: 'access_token');
|
||||
if (token == '') {
|
||||
await _updateOtherModels();
|
||||
await updateOtherModels();
|
||||
return;
|
||||
}
|
||||
_updateLocalUserInfo();
|
||||
@ -53,7 +53,7 @@ class UserModel {
|
||||
} catch (e) {
|
||||
print('Failed to refreshCurrentUser: $e');
|
||||
} finally {
|
||||
await _updateOtherModels();
|
||||
await updateOtherModels();
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +86,8 @@ class UserModel {
|
||||
isAdmin.value = user.isAdmin;
|
||||
}
|
||||
|
||||
Future<void> _updateOtherModels() async {
|
||||
// update ab and group status
|
||||
static Future<void> updateOtherModels() async {
|
||||
await gFFI.abModel.pullAb();
|
||||
await gFFI.groupModel.pull();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user