diff --git a/flutter/lib/common/widgets/login.dart b/flutter/lib/common/widgets/login.dart index a125d1c37..9b00c4cc3 100644 --- a/flutter/lib/common/widgets/login.dart +++ b/flutter/lib/common/widgets/login.dart @@ -378,7 +378,10 @@ Future loginDialog() async { var isInProgress = false; final RxString curOP = ''.obs; - final loginOptions = await UserModel.queryLoginOptions(); + final loginOptions = [].obs; + Future.delayed(Duration.zero, () async { + loginOptions.value = await UserModel.queryLoginOptions(); + }); final res = await gFFI.dialogManager.show((setState, close, context) { username.addListener(() { @@ -451,48 +454,50 @@ Future loginDialog() async { setState(() => isInProgress = false); } - final oidcOptions = loginOptions - .where((opt) => opt.startsWith(kAuthReqTypeOidc)) - .map((opt) => opt.substring(kAuthReqTypeOidc.length)) - .toList(); - - thirdAuthWidget() => Offstage( - offstage: oidcOptions.isEmpty, - child: Column( - children: [ - const SizedBox( - height: 8.0, - ), - Center( - child: Text( - translate('or'), - style: TextStyle(fontSize: 16), - )), - const SizedBox( - height: 8.0, - ), - LoginWidgetOP( - ops: [ - ConfigOP(op: 'GitHub', iconWidth: 20), - ConfigOP(op: 'Google', iconWidth: 20), - ConfigOP(op: 'Okta', iconWidth: 38), - ] - .where((op) => oidcOptions.contains(op.op.toLowerCase())) - .toList(), - curOP: curOP, - cbLogin: (Map authBody) { - try { - // access_token is already stored in the rust side. - gFFI.userModel.getLoginResponseFromAuthBody(authBody); - } catch (e) { - debugPrint('Failed too parse oidc login body: "$authBody"'); - } - close(true); - }, - ), - ], - ), - ); + thirdAuthWidget() => Obx(() { + final oidcOptions = loginOptions + .where((opt) => opt.startsWith(kAuthReqTypeOidc)) + .map((opt) => opt.substring(kAuthReqTypeOidc.length)) + .toList(); + return Offstage( + offstage: oidcOptions.isEmpty, + child: Column( + children: [ + const SizedBox( + height: 8.0, + ), + Center( + child: Text( + translate('or'), + style: TextStyle(fontSize: 16), + )), + const SizedBox( + height: 8.0, + ), + LoginWidgetOP( + ops: [ + ConfigOP(op: 'GitHub', iconWidth: 20), + ConfigOP(op: 'Google', iconWidth: 20), + ConfigOP(op: 'Okta', iconWidth: 38), + ] + .where((op) => oidcOptions.contains(op.op.toLowerCase())) + .toList(), + curOP: curOP, + cbLogin: (Map authBody) { + try { + // access_token is already stored in the rust side. + gFFI.userModel.getLoginResponseFromAuthBody(authBody); + } catch (e) { + debugPrint( + 'Failed to parse oidc login body: "$authBody"'); + } + close(true); + }, + ), + ], + ), + ); + }); return CustomAlertDialog( title: Text(translate('Login')), diff --git a/flutter/lib/models/user_model.dart b/flutter/lib/models/user_model.dart index f24cca429..5730f5054 100644 --- a/flutter/lib/models/user_model.dart +++ b/flutter/lib/models/user_model.dart @@ -10,7 +10,7 @@ import '../common.dart'; import 'model.dart'; import 'platform_model.dart'; -bool refresing_user = false; +bool refreshingUser = false; class UserModel { final RxString userName = ''.obs; @@ -31,16 +31,16 @@ class UserModel { 'id': await bind.mainGetMyId(), 'uuid': await bind.mainGetUuid() }; - if (refresing_user) return; + if (refreshingUser) return; try { - refresing_user = true; + refreshingUser = true; final response = await http.post(Uri.parse('$url/api/currentUser'), headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer $token' }, body: json.encode(body)); - refresing_user = false; + refreshingUser = false; final status = response.statusCode; if (status == 401 || status == 400) { reset(); @@ -57,7 +57,7 @@ class UserModel { } catch (e) { debugPrint('Failed to refreshCurrentUser: $e'); } finally { - refresing_user = false; + refreshingUser = false; await updateOtherModels(); } }