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

208 lines
6.6 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
import 'package:star_lock/mine/mineSet/lockUserManage/lockUserManageList/keyListByUserEntity.dart';
import 'package:star_lock/mine/mineSet/lockUserManage/ownedKeyList/ownedKeyList_state.dart';
import 'package:star_lock/tools/noData.dart';
import 'package:star_lock/tools/showIosTipView.dart';
import '../../../../../app_settings/app_colors.dart';
import '../../../../../tools/titleAppBar.dart';
import '../../../../tools/EasyRefreshTool.dart';
import 'ownedKeyList_logic.dart';
class OwnedKeyListPage extends StatefulWidget {
const OwnedKeyListPage({Key? key}) : super(key: key);
@override
State<OwnedKeyListPage> createState() => _OwnedKeyListPageState();
}
class _OwnedKeyListPageState extends State<OwnedKeyListPage> {
final OwnedKeyListLogic logic = Get.put(OwnedKeyListLogic());
final OwnedKeyListState state = Get.find<OwnedKeyListLogic>().state;
Future<void> getHttpData() async {
logic.mockNetworkDataRequest().then((KeyListByUserEntity value){
if(mounted) {
setState(() {});
}
});
}
@override
void initState() {
super.initState();
getHttpData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '拥有的钥匙'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
),
body: EasyRefreshTool(
onRefresh: () {
logic.pageNo = 1;
getHttpData();
},
onLoad: () {
getHttpData();
},
child: Column(
children: [
_topOwnedKeyText(),
Obx(() => Expanded(child: _buildMainUI())),
],
)));
}
Widget _topOwnedKeyText() {
return Container(
color: Colors.white,
width: ScreenUtil().screenWidth,
// margin: EdgeInsets.only(left: 30.w, top: 30.w, right: 30.w, bottom: 30.w),
child: Padding(
padding:
EdgeInsets.only(left: 30.w, top: 20.w, right: 20.w, bottom: 10.w),
child: Text(
'拥有的钥匙'.tr,
style: TextStyle(fontSize: 24.sp),
),
),
);
}
Widget _buildMainUI() {
return state.dataList.isEmpty
? NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 190.h - 64.h)
: SlidableAutoCloseBehavior(
child: ListView.builder(
itemCount: state.dataList.length,
itemBuilder: (BuildContext c, int index) {
final KeyListItem itemData = state.dataList[index];
return Slidable(
key:ValueKey(itemData.keyId),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (BuildContext context){
showIosTipViewDialog(itemData);
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
label: '删除'.tr,
padding: EdgeInsets.only(left: 5.w, right: 5.w),
),
],
),
child: _electronicKeyItem(itemData),
);
}),
);
}
Widget _electronicKeyItem(KeyListItem itemData) {
var isHaveExpired = false;
if(itemData.keyStatus == XSConstantMacro.keyStatusExpired){
isHaveExpired = true;
}
return GestureDetector(
onTap: () {},
child: Container(
height: 90.h,
margin: const EdgeInsets.only(top: 1),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.w),
),
child: Row(
children: [
SizedBox(width: 30.w,),
Image.asset('images/icon_lockGroup_item.png', width: 60.w, height: 60.w),
SizedBox(width: 20.w),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// Text(itemData.lockAlias ?? '', style: TextStyle(fontSize: 24.sp, color: AppColors.blackColor)),
SizedBox(
width: 1.sw - 110.w - 100.w,
child: Row(
children: [
Flexible(
child: Text(
itemData.lockAlias ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 24.sp, color: isHaveExpired ? Colors.grey:AppColors.blackColor)
),
),
],
),
),
Visibility(
visible: isHaveExpired,
child: Text('已过期'.tr,
style: TextStyle(fontSize: 22.sp, color: Colors.grey)),
),
SizedBox(width: 10.w),
],
),
SizedBox(height: 5.h),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
logic.getUseDateStr(itemData),
style: TextStyle(fontSize: 18.sp, color: isHaveExpired ? Colors.grey:AppColors.placeholderTextColor),
),
],
),
SizedBox(width: 20.h),
],
),
),
SizedBox(width: 20.h),
],
),
),
);
}
void showIosTipViewDialog(KeyListItem lockUserData) {
showDialog(
context: Get.context!,
builder: (BuildContext context) {
return ShowIosTipView(
title: '提示'.tr,
tipTitle: '删除钥匙会在用户APP连网后生效'.tr,
sureClick: () {
Get.back();
logic.deleteKeyRequest(lockUserData.keyId!);
},
cancelClick: () {
Get.back();
},
);
}
);
}
}