mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add login
This commit is contained in:
@@ -1,19 +1,41 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/base/http/url.dart';
|
||||
import 'package:qinglong_app/main.dart';
|
||||
|
||||
import 'login_bean.dart';
|
||||
|
||||
var loginProvider = ChangeNotifierProvider((ref) => LoginViewModel());
|
||||
|
||||
class LoginViewModel extends ViewModel {
|
||||
bool loginSuccess = false;
|
||||
bool isLoading = false;
|
||||
String msg = "";
|
||||
|
||||
void login(String userName, String password) {
|
||||
void login(String userName, String password) async {
|
||||
isLoading = true;
|
||||
loginSuccess = false;
|
||||
msg = "";
|
||||
|
||||
notifyListeners();
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
isLoading = false;
|
||||
HttpResponse<LoginBean> response = await Http.post<LoginBean>(
|
||||
Url.LOGIN,
|
||||
{
|
||||
"username": userName,
|
||||
"password": password,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
userInfoViewModel.updateToken(response.bean?.token ?? "");
|
||||
loginSuccess = true;
|
||||
notifyListeners();
|
||||
});
|
||||
isLoading = false;
|
||||
} else {
|
||||
isLoading = false;
|
||||
loginSuccess = false;
|
||||
msg = response.message ?? "";
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user