add setting

This commit is contained in:
NewTab
2022-01-17 20:36:53 +08:00
parent 30cc0c6caf
commit f8db860d56
2 changed files with 161 additions and 185 deletions

View File

@@ -5,21 +5,21 @@ import 'package:qinglong_app/base/common_dialog.dart';
import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/userinfo_viewmodel.dart'; import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import 'package:qinglong_app/main.dart'; import 'package:qinglong_app/main.dart';
import 'package:qinglong_app/module/login/login_viewmodel.dart';
import 'package:qinglong_app/utils/utils.dart'; import 'package:qinglong_app/utils/utils.dart';
import 'login_bean.dart'; import 'login_bean.dart';
class LoginPage extends StatefulWidget { class LoginPage extends ConsumerStatefulWidget {
const LoginPage({Key? key}) : super(key: key); const LoginPage({Key? key}) : super(key: key);
@override @override
_LoginPageState createState() => _LoginPageState(); _LoginPageState createState() => _LoginPageState();
} }
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends ConsumerState<LoginPage> {
final TextEditingController _hostController = final TextEditingController _hostController =
TextEditingController(text: getIt<UserInfoViewModel>().host); TextEditingController(text: getIt<UserInfoViewModel>().host);
final TextEditingController _userNameController = TextEditingController(); final TextEditingController _userNameController = TextEditingController();
@@ -33,8 +33,9 @@ class _LoginPageState extends State<LoginPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return ColoredBox(
body: SizedBox( color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: SizedBox(
height: MediaQuery.of(context).size.height, height: MediaQuery.of(context).size.height,
child: Stack( child: Stack(
children: [ children: [
@@ -45,164 +46,170 @@ class _LoginPageState extends State<LoginPage> {
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
), ),
), ),
SingleChildScrollView( Scaffold(
child: Padding( backgroundColor: Colors.transparent,
padding: const EdgeInsets.symmetric( body: SingleChildScrollView(
horizontal: 40, child: Padding(
), padding: const EdgeInsets.symmetric(
child: Column( horizontal: 40,
mainAxisAlignment: MainAxisAlignment.start, ),
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ mainAxisAlignment: MainAxisAlignment.start,
SizedBox( crossAxisAlignment: CrossAxisAlignment.start,
height: MediaQuery.of(context).size.height / 10, children: [
), SizedBox(
SizedBox( height: MediaQuery.of(context).size.height / 10,
height: 50, ),
width: MediaQuery.of(context).size.width, SizedBox(
child: Stack( height: 50,
children: [ width: MediaQuery.of(context).size.width,
Positioned( child: Stack(
top: 0, children: [
left: 0, Positioned(
child: Image.asset( top: 0,
"assets/images/login_tip.png", left: 0,
height: 45, child: Image.asset(
), "assets/images/login_tip.png",
), height: 45,
const Positioned(
top: 10,
left: 0,
child: Text(
"登录",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
), ),
), ),
), const Positioned(
Positioned( top: 10,
top: 5, left: 0,
right: 0, child: Text(
child: Image.asset( "登录",
"assets/images/ql.png", style: TextStyle(
height: 45, fontSize: 30,
fontWeight: FontWeight.bold,
),
),
), ),
), Positioned(
], top: 5,
right: 0,
child: Image.asset(
"assets/images/ql.png",
height: 45,
),
),
],
),
), ),
), SizedBox(
SizedBox( height: MediaQuery.of(context).size.height / 10,
height: MediaQuery.of(context).size.height / 10,
),
const Text(
"域名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
), ),
), const Text(
const SizedBox( "域名:",
height: 10, style: TextStyle(
), fontSize: 16,
TextField( fontWeight: FontWeight.w600,
onChanged: (_) { ),
setState(() {});
},
controller: _hostController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "http://1.1.1.1:5700",
), ),
autofocus: false, const SizedBox(
), height: 10,
const SizedBox(
height: 20,
),
const Text(
"用户名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
), ),
), TextField(
const SizedBox( onChanged: (_) {
height: 10, setState(() {});
), },
TextField( controller: _hostController,
onChanged: (_) { decoration: const InputDecoration(
setState(() {}); contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
}, hintText: "http://1.1.1.1:5700",
controller: _userNameController, ),
decoration: const InputDecoration( autofocus: false,
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
), ),
autofocus: false, const SizedBox(
), height: 20,
const SizedBox(
height: 20,
),
const Text(
"密码:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
), ),
), const Text(
const SizedBox( "用户名:",
height: 10, style: TextStyle(
), fontSize: 16,
TextField( fontWeight: FontWeight.w600,
onChanged: (_) { ),
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
), ),
autofocus: false, const SizedBox(
), height: 10,
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,
child: CupertinoButton(
color: (_hostController.text.isNotEmpty &&
_userNameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty &&
!isLoading)
? Theme.of(context).primaryColor
: Theme.of(context)
.primaryColor
.withOpacity(0.4),
child: isLoading
? const CupertinoActivityIndicator()
: const Text(
"登 录",
style: TextStyle(
fontSize: 16,
),
),
onPressed: () {
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>()
.updateHost(_hostController.text);
login(_userNameController.text,
_passwordController.text);
}),
), ),
), TextField(
], onChanged: (_) {
setState(() {});
},
controller: _userNameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
),
autofocus: false,
),
const SizedBox(
height: 20,
),
const Text(
"密码:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
),
autofocus: false,
),
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,
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),
child: isLoading
? const CupertinoActivityIndicator()
: const Text(
"登 录",
style: TextStyle(
fontSize: 16,
),
),
onPressed: () {
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>()
.updateHost(_hostController.text);
login(_userNameController.text,
_passwordController.text);
}),
),
),
],
),
), ),
), ),
), ),
@@ -223,6 +230,8 @@ class _LoginPageState extends State<LoginPage> {
Navigator.of(context).pushReplacementNamed(Routes.route_HomePage); Navigator.of(context).pushReplacementNamed(Routes.route_HomePage);
} else { } else {
failDialog(context, response.message ?? "请检查网络情况"); failDialog(context, response.message ?? "请检查网络情况");
isLoading = false;
setState(() {});
} }
} }
} }

View File

@@ -1,33 +0,0 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/base_viewmodel.dart';
import 'package:qinglong_app/base/http/api.dart';
import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/http/url.dart';
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import 'package:qinglong_app/main.dart';
import 'login_bean.dart';
var loginProvider = ChangeNotifierProvider((ref) => LoginViewModel());
class LoginViewModel extends ViewModel {
bool isLoading = false;
String msg = "";
Future<void> login(String userName, String password) async {
isLoading = true;
msg = "";
notifyListeners();
HttpResponse<LoginBean> response = await Api.login(userName, password);
if (response.success) {
getIt<UserInfoViewModel>().updateToken(response.bean?.token ?? "");
isLoading = false;
} else {
isLoading = false;
msg = response.message ?? "";
}
notifyListeners();
}
}