支持主题切换

This commit is contained in:
NewTab
2022-01-21 19:54:59 +08:00
parent b8b195b663
commit b9d0071302
12 changed files with 813 additions and 175 deletions

View File

@@ -24,7 +24,8 @@ class LoginPage extends ConsumerStatefulWidget {
}
class _LoginPageState extends ConsumerState<LoginPage> {
final TextEditingController _hostController = TextEditingController(text: getIt<UserInfoViewModel>().host);
final TextEditingController _hostController =
TextEditingController(text: getIt<UserInfoViewModel>().host);
final TextEditingController _userNameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _cIdController = TextEditingController();
@@ -40,7 +41,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
super.initState();
useSecretLogin = getIt<UserInfoViewModel>().useSecretLogined;
if (getIt<UserInfoViewModel>().userName != null && getIt<UserInfoViewModel>().userName!.isNotEmpty) {
if (getIt<UserInfoViewModel>().userName != null &&
getIt<UserInfoViewModel>().userName!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) {
_cIdController.text = getIt<UserInfoViewModel>().userName!;
} else {
@@ -50,7 +52,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
} else {
rememberPassword = false;
}
if (getIt<UserInfoViewModel>().passWord != null && getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
if (getIt<UserInfoViewModel>().passWord != null &&
getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) {
_cSecretController.text = getIt<UserInfoViewModel>().passWord!;
} else {
@@ -115,13 +118,22 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (debugBtnIsShow()) {
dismissDebugBtn();
} else {
showDebugBtn(context, btnColor: ref.watch(themeProvider).primaryColor);
showDebugBtn(context,
btnColor: ref
.watch(themeProvider)
.primaryColor);
}
WidgetsBinding.instance?.endOfFrame;
},
child: Image.asset(
"assets/images/ql.png",
height: 45,
child: ColorFiltered(
colorFilter: ColorFilter.mode(
ref.watch(themeProvider).primaryColor,
BlendMode.srcIn,
),
child: Image.asset(
"assets/images/ql.png",
height: 45,
),
),
),
],
@@ -178,7 +190,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
},
controller: _userNameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
),
autofocus: false,
@@ -200,7 +213,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
),
autofocus: false,
@@ -234,7 +248,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
},
controller: _cIdController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_id",
),
autofocus: false,
@@ -256,7 +271,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
controller: _cSecretController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_secret",
),
autofocus: false,
@@ -294,7 +310,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
GestureDetector(
onTap: () {
cardKey.currentState?.toggleCard();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
WidgetsBinding.instance
?.addPostFrameCallback((timeStamp) {
setState(() {});
});
},
@@ -327,7 +344,12 @@ class _LoginPageState extends ConsumerState<LoginPage> {
padding: const EdgeInsets.symmetric(
vertical: 5,
),
color: canClickLoginBtn() ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).primaryColor.withOpacity(0.4),
color: canClickLoginBtn()
? ref.watch(themeProvider).primaryColor
: ref
.watch(themeProvider)
.primaryColor
.withOpacity(0.4),
child: isLoading
? const CupertinoActivityIndicator()
: const Text(
@@ -339,12 +361,15 @@ class _LoginPageState extends ConsumerState<LoginPage> {
onPressed: () {
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>().updateHost(_hostController.text);
getIt<UserInfoViewModel>()
.updateHost(_hostController.text);
Http.clear();
if (loginByUserName()) {
login(_userNameController.text, _passwordController.text);
login(_userNameController.text,
_passwordController.text);
} else {
login(_cIdController.text, _cSecretController.text);
login(_cIdController.text,
_cSecretController.text);
}
},
),
@@ -381,7 +406,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
loginSuccess(response, userName, password);
} else if (loginByUserName() && response.code == 401) {
//可能用户使用的是老版本qinglong
HttpResponse<LoginBean> oldResponse = await Api.loginOld(userName, password);
HttpResponse<LoginBean> oldResponse =
await Api.loginOld(userName, password);
if (oldResponse.success) {
loginSuccess(oldResponse, userName, password);
} else {
@@ -412,7 +438,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
setState(() {});
}
void loginSuccess(HttpResponse<LoginBean> response, String userName, String password) {
void loginSuccess(
HttpResponse<LoginBean> response, String userName, String password) {
getIt<UserInfoViewModel>().updateToken(response.bean?.token ?? "");
getIt<UserInfoViewModel>().useSecretLogin(!loginByUserName());
if (rememberPassword) {
@@ -428,9 +455,11 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (_hostController.text.isEmpty) return false;
if (!loginByUserName()) {
return _cIdController.text.isNotEmpty && _cSecretController.text.isNotEmpty;
return _cIdController.text.isNotEmpty &&
_cSecretController.text.isNotEmpty;
} else {
return _userNameController.text.isNotEmpty && _passwordController.text.isNotEmpty;
return _userNameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty;
}
}
@@ -481,7 +510,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
onPressed: () async {
Navigator.of(context).pop(true);
HttpResponse<LoginBean> response = await Api.loginTwo(userName, password, twoFact);
HttpResponse<LoginBean> response =
await Api.loginTwo(userName, password, twoFact);
if (response.success) {
loginSuccess(response, userName, password);
} else {
@@ -501,7 +531,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
void update() async {
String? result = await UpdateUtils().checkUpdate();
if (result != null && result.isNotEmpty) {
UpdateDialog updateDialog = UpdateDialog(context, title: "发现新版本", updateContent: "版本号:v${result}", onUpdate: () {
UpdateDialog updateDialog = UpdateDialog(context,
title: "发现新版本", updateContent: "版本号:v${result}", onUpdate: () {
UpdateUtils.launchURL(result);
});
updateDialog.show();