1,新增获取设备信息的公用方法

2,用户登录新增入参:设备信息
3,注册接口新增入参:设备信息
This commit is contained in:
Daisy 2024-05-31 14:11:16 +08:00
parent 0a9aeb2027
commit fd4dab3e2e
9 changed files with 142 additions and 74 deletions

View File

@ -1,3 +1,7 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import '../../flavors.dart';
class XSConstantMacro {
@ -85,4 +89,25 @@ class XSConstantMacro {
static int webBuyTypeVip = 3; //VIP购买
static int webBuyTypeAuth = 4; //
static int webBuyTypeShop = 5; //
//
Future<Map<String, dynamic>> getDeviceInfoData() async {
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
final Map<String, dynamic> deviceData = <String, dynamic>{};
if (Platform.isAndroid) {
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
deviceData['deviceBrand'] = androidInfo.brand;
deviceData['deviceModel'] = androidInfo.model;
deviceData['deviceVersion'] = androidInfo.version.release;
deviceData['deviceType'] = 10;
} else if (Platform.isIOS) {
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
deviceData['deviceBrand'] = iosInfo.name;
deviceData['deviceModel'] = iosInfo.model;
deviceData['deviceVersion'] = iosInfo.systemVersion;
deviceData['deviceType'] = 20;
}
return deviceData;
}
}

View File

@ -1,10 +1,11 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_bugly_plugin/flutter_bugly_plugin.dart';
import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/blue/blue_manage.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/mine/mine/starLockMine_state.dart';
import 'package:star_lock/tools/baseGetXController.dart';
@ -44,7 +45,8 @@ class StarLockLoginLogic extends BaseGetXController {
loginType: '1',
password: state.pwd.value,
countryCode: state.countryCode.value,
username: state.emailOrPhone.value);
username: state.emailOrPhone.value,
deviceInfo: state.deviceInfoMap.value);
if (entity.errorCode!.codeIsSuccessful) {
Storage.saveLoginData(entity.data);
Storage.setBool(saveIsVip, entity.data!.isVip == 0 ? false : true);
@ -86,4 +88,16 @@ class StarLockLoginLogic extends BaseGetXController {
state.onClose();
super.onClose();
}
@override
void onReady() {
super.onReady();
XSConstantMacro().getDeviceInfoData().then((Map<String, dynamic> data) {
state.deviceInfoMap.value = data;
}).catchError((error) {
//
AppLog.log('获取设备信息时出错: $error');
});
}
}

View File

@ -19,6 +19,7 @@ class StarLockLoginState {
FocusNode emailOrPhoneFocusNode = FocusNode();
FocusNode pwdFocusNode = FocusNode();
RxMap<String, dynamic> deviceInfoMap = <String, dynamic>{}.obs;
StarLockLoginState() {
// emailOrPhone.value = StoreService.to.getLastUserAccount() as String;

View File

@ -1,8 +1,10 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart';
import '../../network/api_repository.dart';
import '../../tools/baseGetXController.dart';
@ -13,7 +15,7 @@ class StarLockRegisterLogic extends BaseGetXController {
late Timer _timer;
void _startTimer() {
_timer = Timer.periodic(1.seconds, (timer) {
_timer = Timer.periodic(1.seconds, (Timer timer) {
if (state.currentSecond > 1) {
state.currentSecond--;
} else {
@ -29,35 +31,38 @@ class StarLockRegisterLogic extends BaseGetXController {
// _timer = null;
}
void register() async {
AppLog.log("state.pwd.value:${state.pwd.value} state.surePwd.value:${state.surePwd.value}");
if(state.pwd.value != state.surePwd.value){
showToast("密码不一致哦".tr);
Future<void> register() async {
AppLog.log(
'state.pwd.value:${state.pwd.value} state.surePwd.value:${state.surePwd.value}');
if (state.pwd.value != state.surePwd.value) {
showToast('密码不一致哦'.tr);
return;
}
var entity = await ApiRepository.to.register(
final LoginEntity entity = await ApiRepository.to.register(
receiverType: state.isIphoneType.value == true ? 1 : 2,
countryCode: int.parse(state.countryCode.value),
account: state.phoneOrEmailStr.value,
password: state.pwd.value,
verificationCode: state.verificationCode.value);
verificationCode: state.verificationCode.value,
deviceInfo: state.deviceInfoMap.value);
if (entity.errorCode!.codeIsSuccessful) {
showToast("注册成功".tr);
Get.back(result:{
"phoneOrEmailStr":state.phoneOrEmailStr.value,
"pwd":state.pwd.value
showToast('注册成功'.tr);
Get.back(result: <String, String>{
'phoneOrEmailStr': state.phoneOrEmailStr.value,
'pwd': state.pwd.value
});
}
}
void sendValidationCode() async {
var entity = await ApiRepository.to.sendValidationCodeUnLogin(
// state.countryCode.value,
countryCode: state.countryCode.value.toString(),
account: state.phoneOrEmailStr.value,
channel: state.isIphoneType.value ? "1" : "2",
codeType: '1',
xWidth: state.xWidth.value.toString());
Future<void> sendValidationCode() async {
final SendValidationCodeEntity entity =
await ApiRepository.to.sendValidationCodeUnLogin(
// state.countryCode.value,
countryCode: state.countryCode.value.toString(),
account: state.phoneOrEmailStr.value,
channel: state.isIphoneType.value ? '1' : '2',
codeType: '1',
xWidth: state.xWidth.value.toString());
if (entity.errorCode!.codeIsSuccessful) {
_startTimer();
} else {}
@ -93,4 +98,16 @@ class StarLockRegisterLogic extends BaseGetXController {
state.codeIsOK &&
(state.isIphoneType.value ? state.isIphone : state.isEmail);
}
@override
void onReady() {
super.onReady();
XSConstantMacro().getDeviceInfoData().then((Map<String, dynamic> data) {
state.deviceInfoMap.value = data;
}).catchError((error) {
//
AppLog.log('获取设备信息时出错: $error');
});
}
}

View File

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/login/register/starLock_register_state.dart';
import '../../appRouters.dart';
import '../../app_settings/app_colors.dart';
@ -21,8 +22,8 @@ class StarLockRegisterPage extends StatefulWidget {
}
class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
final logic = Get.put(StarLockRegisterLogic());
final state = Get.find<StarLockRegisterLogic>().state;
final StarLockRegisterLogic logic = Get.put(StarLockRegisterLogic());
final StarLockRegisterState state = Get.find<StarLockRegisterLogic>().state;
@override
Widget build(BuildContext context) {
@ -35,7 +36,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
backgroundColor: AppColors.mainColor),
body: ListView(
padding: EdgeInsets.only(top: 40.h, left: 40.w, right: 40.w),
children: [
children: <Widget>[
topSelectCountryAndRegionWidget(),
middleTFWidget(),
Obx(() {
@ -67,11 +68,11 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Widget topSelectCountryAndRegionWidget() {
return Column(
children: [
children: <Widget>[
SizedBox(height: 50.h),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: <Widget>[
Container(
width: 340.w,
height: 60.h,
@ -81,7 +82,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
border:
Border.all(width: 1.0, color: AppColors.greyLineColor)),
child: Row(
children: [
children: <Widget>[
GestureDetector(
onTap: () {
state.isIphoneType.value = true;
@ -141,19 +142,19 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
SizedBox(height: 60.h),
GestureDetector(
onTap: () async {
var result = await Get.toNamed(Routers.selectCountryRegionPage);
final result = await Get.toNamed(Routers.selectCountryRegionPage);
if (result != null) {
result as Map<String, dynamic>;
state.countryCode.value = result['code'];
state.countryName.value = result['countryName'];
}
AppLog.log(
"路由返回值: $result, countryCode:${logic.state.countryCode}");
'路由返回值: $result, countryCode:${logic.state.countryCode}');
},
child: Obx(() => SizedBox(
height: 70.h,
child: Row(
children: [
children: <Widget>[
SizedBox(width: 5.w),
Expanded(
child: Text(
@ -163,7 +164,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
SizedBox(width: 20.w),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
children: <Widget>[
Text(
state.isIphoneType.value
? '${state.countryName.value} +${state.countryCode.value}'
@ -194,7 +195,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Widget middleTFWidget() {
return Column(
children: [
children: <Widget>[
Obx(() => LoginInput(
controller: state.phoneOrEmailController,
onchangeAction: (v) {
@ -207,7 +208,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
child: Image.asset(
state.isIphoneType.value
? 'images/icon_login_account.png'
: "images/icon_login_email.png",
: 'images/icon_login_email.png',
width: 30.w,
height: 30.w,
),
@ -215,7 +216,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
hintText:
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${state.isIphoneType.value ? "手机号".tr : TranslationLoader.lanKeys!.email!.tr}",
keyboardType: TextInputType.number,
inputFormatters: [
inputFormatters: <TextInputFormatter>[
// FilteringTextInputFormatter.allow(RegExp('[0-9]')),
LengthLimitingTextInputFormatter(30),
])),
@ -236,8 +237,8 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
),
),
hintText:
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.password!.tr}",
inputFormatters: [
'${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.password!.tr}',
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(20),
]),
SizedBox(height: 15.w),
@ -263,13 +264,13 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
),
),
hintText:
"${TranslationLoader.lanKeys!.sure!.tr}${TranslationLoader.lanKeys!.password!.tr}",
inputFormatters: [
'${TranslationLoader.lanKeys!.sure!.tr}${TranslationLoader.lanKeys!.password!.tr}',
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(20),
]),
SizedBox(height: 10.w),
Row(
children: [
children: <Widget>[
Expanded(
child: LoginInput(
controller: state.codeController,
@ -284,8 +285,8 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
),
),
hintText:
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.verificationCode!.tr}",
inputFormatters: [
'${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.verificationCode!.tr}',
inputFormatters: <TextInputFormatter>[
LengthLimitingTextInputFormatter(20),
]),
),
@ -297,14 +298,14 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
state.phoneOrEmailStrIsOK.value && state.canResend.value
? () async {
// Navigator.pushNamed(context, Routers.safetyVerificationPage, arguments: {"countryCode":"+86", "account":state.phoneOrEmailStr.value});
var result = await Navigator.pushNamed(
final Object? result = await Navigator.pushNamed(
context, Routers.safetyVerificationPage,
arguments: {
"countryCode": state.countryCode,
"account": state.phoneOrEmailStr.value
arguments: <String, Object>{
'countryCode': state.countryCode,
'account': state.phoneOrEmailStr.value
});
state.xWidth.value =
(result as Map<String, dynamic>)['xWidth'];
(result! as Map<String, dynamic>)['xWidth'];
logic.sendValidationCode();
}
: null,
@ -337,7 +338,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Widget _buildBottomAgreement() {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
children: <Widget>[
Obx(() => GestureDetector(
onTap: () {
state.agree.value = !state.agree.value;
@ -358,7 +359,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
text: TextSpan(
text: TranslationLoader.lanKeys!.readAndAgree!.tr,
style: TextStyle(color: const Color(0xff333333), fontSize: 20.sp),
children: [
children: <InlineSpan>[
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: GestureDetector(
@ -367,10 +368,11 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
style: TextStyle(
color: AppColors.mainColor, fontSize: 20.sp)),
onTap: () {
Get.toNamed(Routers.webviewShowPage, arguments: {
"url": XSConstantMacro.userAgreementURL,
"title": '用户协议'.tr
});
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.userAgreementURL,
'title': '用户协议'.tr
});
},
)),
WidgetSpan(
@ -381,10 +383,11 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
style: TextStyle(
color: AppColors.mainColor, fontSize: 20.sp)),
onTap: () {
Get.toNamed(Routers.webviewShowPage, arguments: {
"url": XSConstantMacro.privacyPolicyURL,
"title": '隐私政策'.tr
});
Get.toNamed(Routers.webviewShowPage,
arguments: <String, String>{
'url': XSConstantMacro.privacyPolicyURL,
'title': '隐私政策'.tr
});
},
)),
],

View File

@ -32,6 +32,7 @@ class StarLockRegisterState {
var btnText = ''.obs;
var totalSeconds = 120;
var currentSecond = 120;
RxMap<String, dynamic> deviceInfoMap = <String, dynamic>{}.obs;
StarLockRegisterState() {
resetResend();

View File

@ -193,18 +193,21 @@ class _StarLockRegisterPageState extends State<StarLockRegisterXHJPage> {
),
Obx(() => GestureDetector(
onTap:
state.phoneOrEmailStrIsOK.value && state.canResend.value ? () async {
state.phoneOrEmailStrIsOK.value && state.canResend.value
? () async {
// Navigator.pushNamed(context, Routers.safetyVerificationPage, arguments: {"countryCode":"+86", "account":state.phoneOrEmailStr.value});
if(state.pwd.value != state.surePwd.value){
logic.showToast("密码不一致哦".tr);
return;
}
var result = await Get.toNamed(Routers.safetyVerificationPage,
if (state.pwd.value != state.surePwd.value) {
logic.showToast("密码不一致哦".tr);
return;
}
var result = await Get.toNamed(
Routers.safetyVerificationPage,
arguments: {
"countryCode": state.countryCode,
"account": state.phoneOrEmailStr.value
});
state.xWidth.value = (result as Map<String, dynamic>)['xWidth'];
state.xWidth.value =
(result as Map<String, dynamic>)['xWidth'];
logic.sendValidationCode();
}
: null,

View File

@ -22,6 +22,7 @@ class ApiProvider extends BaseProvider {
String account,
String password,
String verificationCode,
Map deviceInfo,
) =>
post(
registerUrl.toUrl,
@ -32,6 +33,7 @@ class ApiProvider extends BaseProvider {
'password': password,
'verificationCode': verificationCode,
'platId': '2',
'deviceInfo': deviceInfo,
}));
// post(
@ -65,7 +67,7 @@ class ApiProvider extends BaseProvider {
}));
Future<Response> login(String loginType, String password, String countryCode,
String username) =>
String username, Map deviceInfo) =>
post(
loginUrl.toUrl,
jsonEncode({
@ -74,7 +76,8 @@ class ApiProvider extends BaseProvider {
'platId': '2',
'uniqueid': '477E6814-289D-402A-9F49-F89A8BD05D63',
'countryCode': countryCode,
'username': username
'username': username,
'deviceInfo': deviceInfo,
}));
Future<Response> resetPassword(

View File

@ -98,9 +98,10 @@ class ApiRepository {
required int countryCode,
required String account,
required String password,
required String verificationCode}) async {
final res = await apiProvider.register(
receiverType, countryCode, account, password, verificationCode);
required String verificationCode,
required Map deviceInfo}) async {
final res = await apiProvider.register(receiverType, countryCode, account,
password, verificationCode, deviceInfo);
return LoginEntity.fromJson(res.body);
}
@ -124,9 +125,10 @@ class ApiRepository {
{required String loginType,
required String password,
required String countryCode,
required String username}) async {
final res =
await apiProvider.login(loginType, password, countryCode, username);
required String username,
required Map deviceInfo}) async {
final res = await apiProvider.login(
loginType, password, countryCode, username, deviceInfo);
return LoginEntity.fromJson(res.body);
}
@ -2154,8 +2156,7 @@ class ApiRepository {
//
Future<GetAppInfo> getAppInfo() async {
final Response<dynamic> res =
await apiProvider.getAppInfo();
final Response<dynamic> res = await apiProvider.getAppInfo();
return GetAppInfo.fromJson(res.body);
}
}