189 lines
6.8 KiB
Dart
Executable File
189 lines
6.8 KiB
Dart
Executable File
|
|
import 'package:azlistview/azlistview.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/mine/addLock/addLockSelectCountry/addLockSelectCountry_state.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
import '../../../appRouters.dart';
|
|
import '../../../app_settings/app_colors.dart';
|
|
import '../../../login/selectCountryRegion/common/countryRegionEntity.dart';
|
|
import '../../../network/api_repository.dart';
|
|
import '../../../tools/commonItem.dart';
|
|
import '../../../tools/titleAppBar.dart';
|
|
import '../../../translations/trans_lib.dart';
|
|
import 'addLockSelectCountry_logic.dart';
|
|
|
|
class AddLockSelectCountryPage extends StatefulWidget {
|
|
const AddLockSelectCountryPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<AddLockSelectCountryPage> createState() => _AddLockSelectCountryPageState();
|
|
}
|
|
|
|
class _AddLockSelectCountryPageState extends State<AddLockSelectCountryPage> {
|
|
final AddLockSelectCountryLogic logic = Get.put(AddLockSelectCountryLogic());
|
|
final AddLockSelectCountryState state = Get.find<AddLockSelectCountryLogic>().state;
|
|
|
|
List<CountryRegionModel> countriesList = [];
|
|
int selectindex = 10000;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
SuspensionUtil.setShowSuspensionStatus(
|
|
countriesList.cast<ISuspensionBean>());
|
|
Future.delayed(const Duration(milliseconds: 20), getCountriesListRequest);
|
|
}
|
|
|
|
//请求国家/地区json文件
|
|
Future<void> getCountriesListRequest() async {
|
|
final CountryRegionEntity entity = await ApiRepository.to.getCountryRegion('1');
|
|
countriesList.clear();
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
countriesList.addAll(entity.dataList!);
|
|
_handleList(countriesList);
|
|
}
|
|
}
|
|
|
|
Future<String> loadJsonFromAssets(String assetsPath) async {
|
|
return await rootBundle.loadString(assetsPath);
|
|
}
|
|
|
|
void _handleList(List<CountryRegionModel> list) {
|
|
if (list.isEmpty) return;
|
|
for (int i = 0, length = list.length; i < length; i++) {
|
|
final CountryRegionModel countryModel = list[i];
|
|
final String tag = countryModel.group!;
|
|
if (RegExp('[A-Z]').hasMatch(tag)) {
|
|
list[i].tagIndex = tag;
|
|
} else {
|
|
list[i].tagIndex = '#';
|
|
}
|
|
}
|
|
// A-Z sort.
|
|
SuspensionUtil.sortListBySuspensionTag(list);
|
|
// show sus tag.
|
|
SuspensionUtil.setShowSuspensionStatus(countriesList);
|
|
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
backgroundColor: const Color(0xFFFFFFFF),
|
|
appBar: TitleAppBar(
|
|
barTitle: '请选择您的位置'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: countriesList.length,
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final CountryRegionModel model = countriesList[index];
|
|
return CommonItem(
|
|
leftTitel: model.name,
|
|
rightTitle: '',
|
|
allHeight: 60.h,
|
|
isHaveLine: true,
|
|
isHaveRightWidget: true,
|
|
action: (){
|
|
setState(() {
|
|
selectindex = index;
|
|
});
|
|
},
|
|
rightWidget: Row(
|
|
children: [
|
|
Image.asset((selectindex == index) ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w,),
|
|
],
|
|
)
|
|
);
|
|
}
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 30.h, bottom: 30.h),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
TextButton(
|
|
child: Text(
|
|
'跳过',
|
|
style: TextStyle(color: Colors.black, fontSize: 24.sp),
|
|
),
|
|
onPressed: () {
|
|
Get.toNamed(Routers.saveLockPage, arguments: {
|
|
'addressInfo': {},
|
|
'pwdTimestamp': state.pwdTimestamp.value,
|
|
'lockInfo': state.lockInfo,
|
|
'featureValue': state.featureValue,
|
|
'featureSettingValue': state.featureSettingValue,
|
|
'featureSettingParams': state.featureSettingParams,
|
|
'isFromMap': 0,
|
|
});
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text(
|
|
'下一步'.tr,
|
|
style: TextStyle(color: Colors.black, fontSize: 24.sp),
|
|
),
|
|
onPressed: () {
|
|
if(selectindex == 10000){
|
|
logic.showToast('请选择国家');
|
|
return;
|
|
}
|
|
final CountryRegionModel model = countriesList[selectindex];
|
|
Get.toNamed(Routers.saveLockPage, arguments: {
|
|
'addressInfo': {'country':model.name},
|
|
'pwdTimestamp': state.pwdTimestamp.value,
|
|
'lockInfo': state.lockInfo,
|
|
'featureValue': state.featureValue,
|
|
'featureSettingValue': state.featureSettingValue,
|
|
'featureSettingParams': state.featureSettingParams,
|
|
'isFromMap': 0,
|
|
});
|
|
// Navigator.pushNamed(context, Routers.saveLockPage);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
// body: AzListView(
|
|
// data: countriesList,
|
|
// itemCount: countriesList.length,
|
|
// itemBuilder: (BuildContext context, int index) {
|
|
// CountryRegionModel model = countriesList[index];
|
|
// model.code = " ";
|
|
// return Utils.getListItem(context, model, () {
|
|
// Map<String, dynamic> resultMap = {};
|
|
// resultMap['code'] = model.code;
|
|
// resultMap['countryId'] = model.countryId.toString();
|
|
// resultMap['countryName'] = model.name;
|
|
// Navigator.pop(context, resultMap);
|
|
// });
|
|
// },
|
|
// padding: EdgeInsets.zero,
|
|
// susItemBuilder: (BuildContext context, int index) {
|
|
// CountryRegionModel model = countriesList[index];
|
|
// String tag = model.getSuspensionTag();
|
|
// return Utils.getSusItem(context, tag);
|
|
// },
|
|
// // indexBarData: const ['★', ...kIndexBarData],
|
|
// ),
|
|
);
|
|
}
|
|
|
|
|
|
}
|