mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add setting
This commit is contained in:
@@ -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/http.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/main.dart';
|
||||
import 'package:qinglong_app/module/login/login_viewmodel.dart';
|
||||
import 'package:qinglong_app/utils/utils.dart';
|
||||
|
||||
import 'login_bean.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
class LoginPage extends ConsumerStatefulWidget {
|
||||
const LoginPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_LoginPageState createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
final TextEditingController _hostController =
|
||||
TextEditingController(text: getIt<UserInfoViewModel>().host);
|
||||
final TextEditingController _userNameController = TextEditingController();
|
||||
@@ -33,8 +33,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SizedBox(
|
||||
return ColoredBox(
|
||||
color: ref.watch(themeProvider).themeColor.settingBgColor(),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Stack(
|
||||
children: [
|
||||
@@ -45,7 +46,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||
width: MediaQuery.of(context).size.width,
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40,
|
||||
@@ -180,7 +183,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||
_userNameController.text.isNotEmpty &&
|
||||
_passwordController.text.isNotEmpty &&
|
||||
!isLoading)
|
||||
? Theme.of(context).primaryColor
|
||||
? ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.buttonBgColor()
|
||||
: Theme.of(context)
|
||||
.primaryColor
|
||||
.withOpacity(0.4),
|
||||
@@ -206,6 +212,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -223,6 +230,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
Navigator.of(context).pushReplacementNamed(Routes.route_HomePage);
|
||||
} else {
|
||||
failDialog(context, response.message ?? "请检查网络情况");
|
||||
isLoading = false;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user