diff --git a/flutter/lib/common/widgets/address_book.dart b/flutter/lib/common/widgets/address_book.dart index d5441acfe..6b19d098a 100644 --- a/flutter/lib/common/widgets/address_book.dart +++ b/flutter/lib/common/widgets/address_book.dart @@ -30,43 +30,28 @@ class _AddressBookState extends State { } @override - Widget build(BuildContext context) => Obx(() => Offstage( - offstage: stateGlobal.svcStatus.value != SvcStatus.ready, - child: FutureBuilder( - future: buildBody(context), - builder: (context, snapshot) { - if (snapshot.hasData) { - return snapshot.data!; - } else { - return const Offstage(); - } - }), - )); - - Future 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( diff --git a/flutter/lib/common/widgets/login.dart b/flutter/lib/common/widgets/login.dart index 81cfa1f47..99422cb9d 100644 --- a/flutter/lib/common/widgets/login.dart +++ b/flutter/lib/common/widgets/login.dart @@ -526,9 +526,7 @@ Future loginDialog() async { }); if (res != null) { - // update ab and group status - await gFFI.abModel.pullAb(); - await gFFI.groupModel.pull(); + await UserModel.updateOtherModels(); } return res; diff --git a/flutter/lib/desktop/pages/connection_page.dart b/flutter/lib/desktop/pages/connection_page.dart index 5d0addbca..94f55cb7f 100644 --- a/flutter/lib/desktop/pages/connection_page.dart +++ b/flutter/lib/desktop/pages/connection_page.dart @@ -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 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 gFFI.userModel.isAdmin.value = false; gFFI.groupModel.reset(); } + if (preStatus != stateGlobal.svcStatus.value) { + UserModel.updateOtherModels(); + } svcIsUsingPublicServer.value = await bind.mainIsUsingPublicServer(); } } diff --git a/flutter/lib/models/user_model.dart b/flutter/lib/models/user_model.dart index 7835e50b1..9f3f1571a 100644 --- a/flutter/lib/models/user_model.dart +++ b/flutter/lib/models/user_model.dart @@ -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 _updateOtherModels() async { + // update ab and group status + static Future updateOtherModels() async { await gFFI.abModel.pullAb(); await gFFI.groupModel.pull(); }