diff --git a/lib/base/userinfo_viewmodel.dart b/lib/base/userinfo_viewmodel.dart index 802339e..3c6f399 100644 --- a/lib/base/userinfo_viewmodel.dart +++ b/lib/base/userinfo_viewmodel.dart @@ -26,8 +26,7 @@ class UserInfoViewModel { _useSecertLogined = SpUtil.getBool(spSecretLogined, defValue: false); _host = SpUtil.getString(spHost, defValue: ''); - List? tempList = - jsonDecode(SpUtil.getString(spLoginHistory, defValue: '[]')); + List? tempList = jsonDecode(SpUtil.getString(spLoginHistory, defValue: '[]')); if (tempList != null && tempList.isNotEmpty) { for (Map value in tempList) { @@ -41,8 +40,7 @@ class UserInfoViewModel { SpUtil.putString(spUserInfo, token); } - void updateUserName( - String host, String userName, String password, bool secretLogin) { + void updateUserName(String host, String userName, String password, bool secretLogin) { updateHost(host); _useSecretLogin(secretLogin); _userName = userName; @@ -95,13 +93,11 @@ class UserInfoViewModel { historyAccounts.removeWhere((element) => element.host == _host); - historyAccounts.insert( - 0, - UserInfoBean( - userName: _userName, - password: _passWord, - useSecretLogined: _useSecertLogined, - host: _host)); + historyAccounts.insert(0, UserInfoBean(userName: _userName, password: _passWord, useSecretLogined: _useSecertLogined, host: _host)); + + while (historyAccounts.length > 5) { + historyAccounts.removeLast(); + } SpUtil.putString(spLoginHistory, jsonEncode(historyAccounts)); } @@ -121,8 +117,7 @@ class UserInfoBean { bool useSecretLogined = false; String? host; - UserInfoBean( - {this.userName, this.password, this.useSecretLogined = false, this.host}); + UserInfoBean({this.userName, this.password, this.useSecretLogined = false, this.host}); UserInfoBean.fromJson(Map json) { userName = json['userName'];