Files
flutter-go/lib/utils/data_utils.dart
2019-05-30 20:04:01 +08:00

52 lines
1.4 KiB
Dart

import 'dart:async' show Future;
import './net_utils.dart';
import '../model/user_info.dart';
import 'package:flutter_go/api/api.dart';
class DataUtils {
// 登陆获取用户信息
static Future doLogin(Map<String, String> params) async {
var response = await NetUtils.post(Api.DO_LOGIN, params);
try {
UserInformation userInfo = UserInformation.fromJson(response['data']);
return userInfo;
} catch (err) {
return response['message'];
}
}
// 获取用户信息
static Future<UserInformation> getUserInfo(Map<String, String> params) async {
var response = await NetUtils.get(Api.GET_USER_INFO, params);
try {
UserInformation userInfo = UserInformation.fromJson(response['data']);
return userInfo;
} catch (err) {
return response['message'];
}
}
// 验证登陆
static Future checkLogin() async {
var response = await NetUtils.get(Api.CHECK_LOGIN);
try {
if (response['success']) {
UserInformation userInfo = UserInformation.fromJson(response['data']);
return userInfo;
} else {
return response['success'];
}
} catch (err) {
return response['message'];
}
}
// 退出登陆
static Future<bool> logout() async {
var response = await NetUtils.get(Api.LOGOUT);
print('退出登陆 $response');
return response['success'];
}
}