魏少阳 15af50d951 1、完善星锁APP国际化 36种语言。
2、修复国际化问题
2024-10-15 18:32:11 +08:00

382 lines
14 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/mine/mineSet/transferSmartLock/recipientInformation/recipientInformation_logic.dart';
import 'package:star_lock/mine/mineSet/transferSmartLock/recipientInformation/recipientInformation_state.dart';
import 'package:star_lock/tools/submitBtn.dart';
import '../../../../../appRouters.dart';
import '../../../../../app_settings/app_colors.dart';
import '../../../../../tools/titleAppBar.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/customNetworkImage.dart';
import '../../../../tools/showTipView.dart';
import 'recipientInformation_entity.dart';
class RecipientInformationPage extends StatefulWidget {
const RecipientInformationPage({Key? key}) : super(key: key);
@override
State<RecipientInformationPage> createState() =>
_RecipientInformationPageState();
}
class _RecipientInformationPageState extends State<RecipientInformationPage> {
final RecipientInformationLogic logic = Get.put(RecipientInformationLogic());
final RecipientInformationState state = Get.find<RecipientInformationLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '接收人信息'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
),
body: Column(
children: <Widget>[
SizedBox(height: 150.h, child: _buildMainUI()),
SizedBox(height: 10.h),
_buildAccoutRow(),
_buildBottomText(),
_buildNextBtn(context),
SizedBox(height: 64.h),
Visibility(
visible: state.isFromType.value == 1,
child: _buildRemoveBadLockBtn()),
SizedBox(
height: 64.h,
)
],
),
);
}
Widget _buildMainUI() {
return Obx(() => Column(
children: <Widget>[
_electronicKeyItem(
state.type.value == 1
? 'images/select_circle.png'
: 'images/normal_circle.png',
'个人用户'.tr, () {
setState(() {
state.type.value = 1;
});
}),
_electronicKeyItem(
state.type.value == 2
? 'images/select_circle.png'
: 'images/normal_circle.png',
'星寓'.tr, () {
setState(() {
state.type.value = 2;
});
})
],
));
}
Widget _electronicKeyItem(
String leftIcon, String leftTitle, Function() action) {
return GestureDetector(
onTap: action,
child: Container(
color: Colors.white,
height: 70.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(width: 20.w),
GestureDetector(
child: Image.asset(
leftIcon,
width: 20.w,
height: 20.w,
),
),
SizedBox(width: 16.w),
Text(
leftTitle,
style: TextStyle(fontSize: 24.sp),
)
],
),
),
);
}
Widget _buildAccoutRow() {
return Container(
// height: 60.h,
color: Colors.white,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
SizedBox(
width: 20.w,
),
Text('账号'.tr,
style: TextStyle(
color: AppColors.darkGrayTextColor, fontSize: 22.sp)),
Expanded(
child: TextField(
controller: state.numberController,
textAlign: TextAlign.right,
keyboardType: TextInputType.text,
onChanged: (String value) {},
decoration: InputDecoration(
border: InputBorder.none,
hintText:
state.type.value == 1 ? '请输入手机号或email'.tr : '请输入星寓管理员的账号'.tr,
hintStyle: TextStyle(
color: AppColors.placeholderTextColor,
fontSize: ScreenUtil().setSp(22),
textBaseline: TextBaseline.alphabetic),
),
)),
SizedBox(
width: 20.w,
),
GestureDetector(
onTap: () async {
Contact? currentContact = await state.contactPicker.selectContact();
state.contact = currentContact!;
if (currentContact.phoneNumbers!.isNotEmpty) {
state.numberController.text = currentContact
.phoneNumbers![0]
.replaceAll(RegExp(r'\s+\b|\b\s'), '');
}
},
child: Image.asset(
'images/icon_addressBook.png',
width: 28.w,
height: 28.h,
),
),
SizedBox(
width: 40.w,
)
],
),
Divider(
color: AppColors.greyLineColor,
indent: 20.w,
endIndent: 20.w,
height: 1,
),
CommonItem(
leftTitel: '国家/地区'.tr,
rightTitle: '',
isHaveLine: true,
isHaveRightWidget: true,
isHaveDirection: true,
rightWidget: Text(
'${state.countryName.value} +${state.countryCode.value}',
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 22.sp, color: AppColors.darkGrayTextColor),
),
action: () async {
Object? result = await Navigator.pushNamed(
context, Routers.selectCountryRegionPage);
if (result != null) {
result as Map<String, dynamic>;
state.countryCode.value = result['code'];
state.countryName.value = result['countryName'];
setState(() {});
}
},
),
],
),
);
}
Widget _buildBottomText() {
return Padding(
padding: EdgeInsets.only(top: 20.h, bottom: 80.h),
child: Text(
'选中的智能锁将会转移到您输入的账号中,您将失去锁的管理权'.tr,
style:
TextStyle(fontSize: 18.sp, color: AppColors.placeholderTextColor),
textAlign: TextAlign.left,
),
);
}
Widget _buildNextBtn(BuildContext context) {
return SubmitBtn(
btnName: '下一步'.tr,
onClick: () {
if (state.numberController.text.isEmpty) {
logic.showToast('请输入手机号或email'.tr);
return;
}
if (state.isFromType.value == 1) {
// 转移智能锁
if (state.type.value == 1) {
logic.transferLockConfirmInfoData((RecipientInformationData v) {
showCupertinoAlertDialog(context, v);
});
} else {
logic.showToast('暂不支持跨平台转移,敬请期待'.tr);
// Get.toNamed(Routers.selectBranchPage, arguments: {
// "idList": state.idList.value,
// "countryCode": state.countryCode.value,
// "number": state.numberController.text,
// "isFromType": state.isFromType.value,
// });
}
} else {
// 转移网关
if (state.type.value == 1) {
logic.transferGateWayConfirmInfoData((RecipientInformationData v) {
showCupertinoAlertDialog(context, v);
});
} else {
logic.showToast('暂不支持跨平台转移,敬请期待'.tr);
// Get.toNamed(Routers.selectBranchPage, arguments: {
// "idList": state.idList.value,
// "countryCode": state.countryCode.value,
// "number": state.numberController.text,
// "isFromType": state.isFromType.value
// });
}
}
});
}
Widget _buildRemoveBadLockBtn() {
return Row(
children: <Widget>[
const Expanded(child: SizedBox()),
TextButton(
onPressed: logic.showDeletAlertDialog,
child: Text(
'移除坏锁'.tr,
style: TextStyle(
fontSize: 22.sp, color: AppColors.darkGrayTextColor),
textAlign: TextAlign.end,
)),
SizedBox(
width: 10.h,
)
],
);
}
// 点击确认
void showCupertinoAlertDialog(
BuildContext context, RecipientInformationData recipientInformationData) {
showGeneralDialog(
context: context,
barrierColor: Colors.black.withOpacity(.5),
barrierDismissible: true,
barrierLabel: '',
transitionDuration: const Duration(milliseconds: 200),
transitionBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
return ScaleTransition(scale: animation, child: child);
},
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
// recipientInformationData.nickname = "张三张三张三";
return Center(
child: Container(
width: 400.w,
height: 400.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.w),
color: Colors.white
),
child: Column(
children: <Widget>[
SizedBox(height: 20.h),
Text('转移确认'.tr, style: TextStyle(fontSize: 24.sp)),
SizedBox(height: 20.h),
ClipRRect(
borderRadius: BorderRadius.circular(40.w),
child:CustomNetworkImage(
url: recipientInformationData.headUrl!,
defaultUrl: 'images/controls_user.png',
width: 80.w,
height: 80.w)
),
// Image.asset('images/icon_lockGroup_item.png',
// width: 70.h, height: 70.h, fit: BoxFit.fill),
SizedBox(height: 15.h),
Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: <Widget>[
Text(recipientInformationData.nickname!,
style: TextStyle(fontSize: 22.sp)),
// Positioned(
// left: (recipientInformationData.nickname!.length * 19.w)
// .w,
// child: Container(
// width: 80.w,
// color: Colors.red,
// child: Center(
// child: Text(state.type.value == 1 ? '个人用户'.tr : '星寓'.tr,
// style: TextStyle(
// fontSize: 18.sp, color: Colors.white))),
// ),
// )
],
),
SizedBox(height: 8.h),
Text(recipientInformationData.userid!,
style: TextStyle(fontSize: 22.sp)),
SizedBox(height: 8.h),
Text('本次共转移'.tr + '${state.idList.value.length}' + '把智能锁'.tr,
style: TextStyle(fontSize: 20.sp)),
SizedBox(height: 20.h),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ElevatedButton(
onPressed: Get.back,
style: ElevatedButton.styleFrom(
foregroundColor: AppColors.appBarIconColor, backgroundColor: Colors.grey,
minimumSize: Size(110.w, 45.h),
padding: const EdgeInsets.symmetric(horizontal: 16),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
),
),
child: Text('取消'.tr, style: TextStyle(fontSize: 22.sp)),
),
ElevatedButton(
onPressed: () {
Get.back();
ShowTipView().showTFViewAlertDialog(state.passwordTF, '请输入登录密码'.tr, '请输入登录密码'.tr, logic.checkLoginPassword);
},
style: ElevatedButton.styleFrom(
foregroundColor: AppColors.appBarIconColor, backgroundColor: AppColors.mainColor,
minimumSize: Size(110.w, 45.h),
padding: const EdgeInsets.symmetric(horizontal: 16),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
),
),
child: Text('确认'.tr, style: TextStyle(fontSize: 22.sp)),
),
],
)
],
),
),
);
});
}
}