推送配置,测试
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:aliyun_push_flutter/aliyun_push_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:getx_scaffold/getx_scaffold.dart';
|
||||
import 'package:ln_jq_app/common/login_util.dart';
|
||||
@@ -21,8 +22,10 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
|
||||
bool cLogin = true;
|
||||
bool _obscureText = true;
|
||||
|
||||
// 用于管理“记住密码”的复选框状态
|
||||
bool _rememberPassword = true;
|
||||
|
||||
// 用于确保凭证只在首次加载时回填一次
|
||||
bool _credentialsLoaded = false;
|
||||
|
||||
@@ -198,20 +201,24 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
phone: phone,
|
||||
);
|
||||
|
||||
//注册推送别名
|
||||
addAlias(phone);
|
||||
|
||||
//登录后查询已绑定车辆信息
|
||||
var carInfo = await HttpService.to.get(
|
||||
"appointment/driver/getTruckInfoByDriver?phone=$phone"
|
||||
"appointment/driver/getTruckInfoByDriver?phone=$phone",
|
||||
);
|
||||
if (carInfo != null) {
|
||||
var carInforesult = BaseModel.fromJson(carInfo.data);
|
||||
if (carInforesult.data != null) {
|
||||
final vehicle = VehicleInfo.fromJson(carInforesult.data as Map<String, dynamic>);
|
||||
final vehicle = VehicleInfo.fromJson(
|
||||
carInforesult.data as Map<String, dynamic>,
|
||||
);
|
||||
//保存使用
|
||||
await StorageService.to.saveVehicleInfo(vehicle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//页面操作
|
||||
dismissLoading();
|
||||
showToast('登录成功,欢迎您');
|
||||
@@ -269,9 +276,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
hintText: '请输入密码',
|
||||
border: OutlineInputBorder(),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureText ? Icons.visibility_off : Icons.visibility,
|
||||
),
|
||||
icon: Icon(_obscureText ? Icons.visibility_off : Icons.visibility),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureText = !_obscureText;
|
||||
@@ -304,7 +309,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
GestureDetector(
|
||||
onTap: () => setState(() => _rememberPassword = !_rememberPassword),
|
||||
child: const Text('记住密码', style: TextStyle(color: Colors.grey)),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20), // 调整间距
|
||||
@@ -317,7 +322,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
onPressed: () async {
|
||||
String account = controller.stationIdController.text;
|
||||
String password = controller.passwordController.text;
|
||||
|
||||
|
||||
if (account.isEmpty || password.isEmpty) {
|
||||
showToast("请输入账号和密码");
|
||||
return;
|
||||
@@ -353,13 +358,18 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
|
||||
String token = result.data['token'] ?? '';
|
||||
String userId = result.data['userId'] ?? '';
|
||||
String mobile = result.data['mobile'] ?? '';
|
||||
|
||||
await StorageService.to.saveLoginInfo(
|
||||
token: token,
|
||||
userId: userId,
|
||||
phone: mobile,
|
||||
channel: "station",
|
||||
);
|
||||
|
||||
//注册推送别名
|
||||
addAlias(mobile);
|
||||
|
||||
// 根据复选框状态保存或清除密码 ---
|
||||
if (_rememberPassword) {
|
||||
await StorageService.to.saveStationCredentials(account, password);
|
||||
@@ -384,6 +394,20 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
|
||||
);
|
||||
}
|
||||
|
||||
final _aliyunPush = AliyunPushFlutter();
|
||||
|
||||
void addAlias(String alias) async {
|
||||
var result = await _aliyunPush.addAlias(alias);
|
||||
var code = result['code'];
|
||||
if (code == kAliyunPushSuccessCode) {
|
||||
Logger.d('添加别名$alias成功');
|
||||
} else {
|
||||
var errorCode = result['code'];
|
||||
var errorMsg = result['errorMsg'];
|
||||
Logger.d('添加别名$alias失败: $errorCode - $errorMsg');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<LoginController>(
|
||||
|
||||
Reference in New Issue
Block a user