add checkbox

This commit is contained in:
jyuesong
2022-01-18 10:10:03 +08:00
parent 074580952f
commit a6208ea5f2
8 changed files with 273 additions and 233 deletions

View File

@@ -20,14 +20,25 @@ 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();
bool rememberPassword = false;
@override
void initState() {
super.initState();
if (getIt<UserInfoViewModel>().userName != null && getIt<UserInfoViewModel>().userName!.isNotEmpty) {
_userNameController.text = getIt<UserInfoViewModel>().userName!;
rememberPassword = true;
} else {
rememberPassword = false;
}
if (getIt<UserInfoViewModel>().passWord != null && getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
_passwordController.text = getIt<UserInfoViewModel>().passWord!;
}
getIt<UserInfoViewModel>().updateToken("");
}
@@ -96,7 +107,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 10,
height: MediaQuery.of(context).size.height / 15,
),
const Text(
"域名:",
@@ -105,9 +116,6 @@ class _LoginPageState extends ConsumerState<LoginPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
onChanged: (_) {
setState(() {});
@@ -120,7 +128,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
autofocus: false,
),
const SizedBox(
height: 20,
height: 15,
),
const Text(
"用户名:",
@@ -129,9 +137,6 @@ class _LoginPageState extends ConsumerState<LoginPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
onChanged: (_) {
setState(() {});
@@ -144,7 +149,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
autofocus: false,
),
const SizedBox(
height: 20,
height: 15,
),
const Text(
"密码:",
@@ -153,9 +158,6 @@ class _LoginPageState extends ConsumerState<LoginPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
onChanged: (_) {
setState(() {});
@@ -168,28 +170,41 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
autofocus: false,
),
const SizedBox(
height: 10,
),
Row(
children: [
Checkbox(
value: rememberPassword,
onChanged: (checked) {
rememberPassword = checked ?? false;
setState(() {});
},
),
const Text(
"记住密码",
style: TextStyle(
fontSize: 14,
),
),
],
),
const SizedBox(
height: 30,
),
SizedBox(
width: MediaQuery.of(context).size.width - 80,
child: IgnorePointer(
ignoring: _hostController.text.isEmpty ||
_userNameController.text.isEmpty ||
_passwordController.text.isEmpty ||
isLoading,
ignoring: _hostController.text.isEmpty || _userNameController.text.isEmpty || _passwordController.text.isEmpty || isLoading,
child: CupertinoButton(
color: (_hostController.text.isNotEmpty &&
_userNameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty &&
!isLoading)
? ref
.watch(themeProvider)
.themeColor
.buttonBgColor()
: Theme.of(context)
.primaryColor
.withOpacity(0.4),
padding: const EdgeInsets.symmetric(
vertical: 5,
),
color:
(_hostController.text.isNotEmpty && _userNameController.text.isNotEmpty && _passwordController.text.isNotEmpty && !isLoading)
? ref.watch(themeProvider).themeColor.buttonBgColor()
: Theme.of(context).primaryColor.withOpacity(0.4),
child: isLoading
? const CupertinoActivityIndicator()
: const Text(
@@ -199,12 +214,14 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
),
onPressed: () {
if (rememberPassword) {
getIt<UserInfoViewModel>().updateUserName(_userNameController.text, _passwordController.text);
}
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>()
.updateHost(_hostController.text);
login(_userNameController.text,
_passwordController.text);
getIt<UserInfoViewModel>().updateHost(_hostController.text);
login(_userNameController.text, _passwordController.text);
}),
),
),