Bläddra i källkod

1、新增用户信息管理provide

2、网络请求post方法新增是否缓存标志
tags/0.0.1
PH2 4 år sedan
förälder
incheckning
31f2869250
5 ändrade filer med 88 tillägg och 2 borttagningar
  1. +44
    -0
      lib/models/user/user_info_model.dart
  2. +35
    -0
      lib/models/user/user_info_model_notifier.dart
  3. +1
    -1
      lib/util/net_util.dart
  4. +5
    -0
      lib/zhiying_comm.dart
  5. +3
    -1
      pubspec.yaml

+ 44
- 0
lib/models/user/user_info_model.dart Visa fil

@@ -0,0 +1,44 @@

///
/// 用户信息类
///
class UserInfoModel {
String token;
String mobile;
String userId;
String username;
List<String> perms;
String registerInviteCodeEnable;

UserInfoModel(
{this.token,
this.userId,
this.username,
this.perms,
this.registerInviteCodeEnable});

UserInfoModel.fromJson(Map<String, dynamic> json) {
token = json['token'];
userId = json['user_id'];
username = json['username'];
mobile = json['mobile'];
perms = json['perms']?.cast<String>();
registerInviteCodeEnable = json['register_invite_code_enable'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['token'] = this.token;
data['user_id'] = this.userId;
data['username'] = this.username;
data['perms'] = this.perms;
data['mobile'] = this.mobile;
data['register_invite_code_enable'] = this.registerInviteCodeEnable;
return data;
}

@override
String toString() {
return 'LoginUser{token: $token, userId: $userId, username: $username, perms: $perms, registerInviteCodeEnable: $registerInviteCodeEnable}';
}
}

+ 35
- 0
lib/models/user/user_info_model_notifier.dart Visa fil

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:zhiying_comm/models/user/user_info_model.dart';

///
/// 用户信息
///
class UserInfoNotifier with ChangeNotifier {
UserInfoModel _userInfo;

/// 初始化,是否需要读取缓存信息?
UserInfoNotifier();

/// 更新用户数据
void setUserInfo(UserInfoModel loginUser) async {
print('${loginUser.toString()}');
this._userInfo = loginUser;
// 缓存数据 TODO
/// token
}

/// 退出登陆
void unLogin() {
this._userInfo = null;
// 清除缓存数据 TODO
}

/// 获取登陆数据
UserInfoModel getUserInfoModel() {
if (null != _userInfo) {
return _userInfo;
}
// TODO 需要读取缓存的数据?
return null;
}
}

+ 1
- 1
lib/util/net_util.dart Visa fil

@@ -86,7 +86,7 @@ class NetUtil {

/// 同步请求
static Future<dynamic> post(String path,
{Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = true}) async {
{Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = false}) async {
if (params == null) {
params = {};
}


+ 5
- 0
lib/zhiying_comm.dart Visa fil

@@ -15,6 +15,11 @@ export 'util/page_factory.dart';
export 'util/widget_factory.dart';
export 'util/router_util.dart';
export 'util/log/let_log.dart';
export 'util/empty_util.dart';

// 用户信息
export 'models/user/user_info_model.dart';
export 'models/user/user_info_model_notifier.dart';

// 屏幕适配
export 'package:flutter_screenutil/flutter_screenutil.dart';


+ 3
- 1
pubspec.yaml Visa fil

@@ -12,10 +12,11 @@ dependencies:
sdk: flutter

dio: ^3.0.9
provider: ^4.0.0
package_info: ^0.4.0+17
device_info: ^0.4.0+1
flutter_native_image: ^0.0.5
fluttertoast: ^7.0.4
fluttertoast: 4.0.1
cached_network_image: ^2.2.0+1
equatable: ^1.2.0
json_serializable: ^3.3.0
@@ -26,6 +27,7 @@ dependencies:
shared_preferences: ^0.5.10



dev_dependencies:
flutter_test:
sdk: flutter


Laddar…
Avbryt
Spara