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