110 lines
3.3 KiB
Dart
110 lines
3.3 KiB
Dart
import 'package:azlistview/azlistview.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../app_settings/app_colors.dart';
|
|
import '../../tools/titleAppBar.dart';
|
|
import '../../translations/trans_lib.dart';
|
|
import 'common/countries_model.dart';
|
|
import 'common/index.dart';
|
|
|
|
class SeletCountryRegionPage extends StatefulWidget {
|
|
const SeletCountryRegionPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<SeletCountryRegionPage> createState() => _SeletCountryRegionPageState();
|
|
}
|
|
|
|
class _SeletCountryRegionPageState extends State<SeletCountryRegionPage> {
|
|
List<CountriesModel> countriesList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
SuspensionUtil.setShowSuspensionStatus(
|
|
countriesList.cast<ISuspensionBean>());
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
loadData();
|
|
});
|
|
}
|
|
|
|
Future<String> loadJsonFromAssets(String assetsPath) async {
|
|
return await rootBundle.loadString(assetsPath);
|
|
}
|
|
|
|
void loadData() async {
|
|
//加载国家列表
|
|
String jsonData = await loadJsonFromAssets('assets/countries.json');
|
|
countriesList.clear();
|
|
List list = json.decode(jsonData);
|
|
for (var v in list) {
|
|
countriesList.add(CountriesModel.fromJson(v));
|
|
}
|
|
|
|
_handleList(countriesList);
|
|
}
|
|
|
|
void _handleList(List<CountriesModel> list) {
|
|
if (list.isEmpty) return;
|
|
for (int i = 0, length = list.length; i < length; i++) {
|
|
CountriesModel countryModel = list[i];
|
|
// String pinyin = PinyinHelper.getPinyinE(list[i].name);
|
|
String tag = countryModel.pinyin!.substring(0, 1).toUpperCase();
|
|
// list[i].pinyin = pinyin;
|
|
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:
|
|
"${TranslationLoader.lanKeys!.selet!.tr} ${TranslationLoader.lanKeys!.countryAndRegion!.tr}",
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: [
|
|
TextButton(
|
|
child: Text(
|
|
TranslationLoader.lanKeys!.reset!.tr,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
onPressed: () {
|
|
Navigator.pop(context, {'code': "+86", "countryId": "9"});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: AzListView(
|
|
data: countriesList,
|
|
itemCount: countriesList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
CountriesModel model = countriesList[index];
|
|
return Utils.getListItem(context, model);
|
|
},
|
|
padding: EdgeInsets.zero,
|
|
susItemBuilder: (BuildContext context, int index) {
|
|
CountriesModel model = countriesList[index];
|
|
String tag = model.getSuspensionTag();
|
|
return Utils.getSusItem(context, tag);
|
|
},
|
|
indexBarData: ['★', ...kIndexBarData],
|
|
),
|
|
);
|
|
}
|
|
}
|