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/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 createState() => _AddLockSelectCountryPageState(); } class _AddLockSelectCountryPageState extends State { final logic = Get.put(AddLockSelectCountryLogic()); final state = Get.find().state; List countriesList = []; int selectindex = 10000; @override void initState() { super.initState(); SuspensionUtil.setShowSuspensionStatus( countriesList.cast()); Future.delayed(const Duration(milliseconds: 20), () { getCountriesListRequest(); }); } //请求国家/地区json文件 Future getCountriesListRequest() async { CountryRegionEntity entity = await ApiRepository.to.getCountryRegion('1'); countriesList.clear(); if (entity.errorCode!.codeIsSuccessful) { countriesList.addAll(entity.dataList!); _handleList(countriesList); } } Future loadJsonFromAssets(String assetsPath) async { return await rootBundle.loadString(assetsPath); } void _handleList(List list) { if (list.isEmpty) return; for (int i = 0, length = list.length; i < length; i++) { CountryRegionModel countryModel = list[i]; 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: "请选择您的位置", haveBack: true, backgroundColor: AppColors.mainColor, ), body: Column( children: [ Expanded( child: ListView.builder( itemCount: countriesList.length, itemBuilder: (c, index) { 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( TranslationLoader.lanKeys!.next!.tr, style: TextStyle(color: Colors.black, fontSize: 24.sp), ), onPressed: () { if(selectindex == 10000){ logic.showToast("请选择国家"); return; } 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 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], // ), ); } }