266 lines
9.9 KiB
Dart
266 lines
9.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_data/models/country_mode.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:aslan/chatvibe_ui/components/appbar/chatvibe_appbar.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
|
|
import 'package:aslan/chatvibe_ui/components/custom_cached_image.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/country_res.dart';
|
|
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
|
|
|
|
import '../../chatvibe_core/constants/at_global_config.dart';
|
|
import '../../chatvibe_core/config/business_logic_strategy.dart';
|
|
|
|
///国家
|
|
class ATCountryPage extends StatefulWidget {
|
|
bool isDialog = false;
|
|
|
|
ATCountryPage({this.isDialog = false});
|
|
|
|
@override
|
|
_CountryPageState createState() => _CountryPageState(isDialog);
|
|
}
|
|
|
|
class _CountryPageState extends State<ATCountryPage> {
|
|
bool isDialog = false;
|
|
Country? selectCountryInfo;
|
|
|
|
_CountryPageState(this.isDialog);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Provider.of<AppGeneralManager>(context, listen: false).loadCountry();
|
|
}
|
|
@override
|
|
void dispose() {
|
|
Provider.of<AppGeneralManager>(context, listen: false).resetCountryState();
|
|
super.dispose();
|
|
}
|
|
|
|
/// 获取业务逻辑策略
|
|
BusinessLogicStrategy get _strategy => ATGlobalConfig.businessLogicStrategy;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: _strategy.getCountryPageScaffoldBackgroundColor(),
|
|
resizeToAvoidBottomInset: false,
|
|
appBar:
|
|
widget.isDialog
|
|
? null
|
|
: ChatVibeStandardAppBar(
|
|
title: ATAppLocalizations.of(context)!.countryRegion,
|
|
onTag: () {
|
|
Provider.of<AppGeneralManager>(context, listen: false).resetCountryState();
|
|
ATNavigatorUtils.goBack(context);
|
|
},
|
|
actions: [
|
|
Consumer<AppGeneralManager>(
|
|
builder: (_, provider, __) {
|
|
return Container(
|
|
margin: EdgeInsets.only(right: 20.w),
|
|
child: ATDebounceWidget(
|
|
onTap: () {
|
|
if (selectCountryInfo != null) {
|
|
Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
).setCountry(selectCountryInfo!);
|
|
provider.setCurrentCountry(selectCountryInfo);
|
|
ATNavigatorUtils.goBack(context);
|
|
}
|
|
},
|
|
child: Image.asset(
|
|
selectCountryInfo != null
|
|
? _strategy.getCountrySelectOkIcon()
|
|
: _strategy.getCountrySelectUnOkIcon(),
|
|
width: 38.w,
|
|
height: 22.w,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: SafeArea(
|
|
top: false,
|
|
child: Column(
|
|
children: [
|
|
widget.isDialog ? SizedBox(height: 10.w) : Container(),
|
|
widget.isDialog
|
|
? Row(
|
|
children: [
|
|
ATDebounceWidget(
|
|
child: Container(
|
|
width: 50.w,
|
|
height: 30.w,
|
|
alignment: AlignmentDirectional.centerStart,
|
|
margin: EdgeInsetsDirectional.only(start: 10.w),
|
|
child: Icon(
|
|
ATGlobalConfig.lang == "ar"
|
|
? Icons.keyboard_arrow_right
|
|
: Icons.keyboard_arrow_left,
|
|
size: 28.w,
|
|
color: _strategy.getCountryPageIconColor(),
|
|
),
|
|
),
|
|
onTap: () {
|
|
Provider.of<AppGeneralManager>(context, listen: false).resetCountryState();
|
|
SmartDialog.dismiss(tag: "showCountryPage");
|
|
},
|
|
),
|
|
Spacer(),
|
|
Consumer<AppGeneralManager>(
|
|
builder: (_, provider, __) {
|
|
return Container(
|
|
margin: EdgeInsets.only(right: 20.w),
|
|
child: ATDebounceWidget(
|
|
onTap: () {
|
|
if (selectCountryInfo != null) {
|
|
Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
).setCountry(selectCountryInfo!);
|
|
provider.setCurrentCountry(selectCountryInfo);
|
|
SmartDialog.dismiss(tag: "showCountryPage");
|
|
}
|
|
},
|
|
child: Image.asset(
|
|
selectCountryInfo != null
|
|
? _strategy.getCountrySelectOkIcon()
|
|
: _strategy.getCountrySelectUnOkIcon(),
|
|
width: 38.w,
|
|
height: 22.w,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
)
|
|
: Container(),
|
|
widget.isDialog
|
|
? Row(
|
|
children: [
|
|
SizedBox(width: 15.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.selectYourCountry,
|
|
textColor: _strategy.getCountryPagePrimaryTextColor(),
|
|
fontSize: 16.sp,
|
|
),
|
|
],
|
|
)
|
|
: Container(),
|
|
widget.isDialog ? SizedBox(height: 12.w) : Container(),
|
|
Expanded(
|
|
child: Consumer<AppGeneralManager>(
|
|
builder: (_, provider, __) {
|
|
return ListView.separated(
|
|
itemCount: provider.countryModeList.length, // 列表项数量
|
|
padding: EdgeInsets.only(bottom: 15.w),
|
|
itemBuilder: (context, index) {
|
|
return _buildCountryItem(
|
|
index,
|
|
provider.countryModeList[index],
|
|
provider,
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return SizedBox(height: 10.w);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCountryItem(
|
|
int subIndex,
|
|
CountryMode countryModeList,
|
|
AppGeneralManager provider,
|
|
) {
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(left: 25.w),
|
|
alignment: Alignment.centerLeft,
|
|
child: text(
|
|
countryModeList.prefix,
|
|
textColor: _strategy.getCountryPageSecondaryTextColor(),
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
SizedBox(height: 5.w),
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: 15.w),
|
|
padding: EdgeInsets.symmetric(vertical: 8.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: _strategy.getCountryPageContainerBackgroundColor(),
|
|
border: Border.all(color: _strategy.getCountryItemBorderColor(), width: 1.w),
|
|
),
|
|
child: Column(
|
|
spacing: 3.w,
|
|
children: List.generate(countryModeList.prefixCountrys.length, (
|
|
cIndex,
|
|
) {
|
|
Country country = countryModeList.prefixCountrys[cIndex];
|
|
return Row(
|
|
children: [
|
|
SizedBox(width: 15.w),
|
|
CustomCachedImage(
|
|
imageUrl: country.nationalFlag ?? "",
|
|
width: 28.w,
|
|
height: 19.w,
|
|
),
|
|
SizedBox(width: 5.w),
|
|
Expanded(
|
|
child: text(
|
|
country.aliasName ?? "",
|
|
textColor: _strategy.getCountryPagePrimaryTextColor(),
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
GestureDetector(
|
|
child: Container(
|
|
color: Colors.transparent,
|
|
padding: EdgeInsets.all(8.w),
|
|
child: Image.asset(
|
|
selectCountryInfo?.id == country.id
|
|
? _strategy.getCountryRadioSelectedIcon()
|
|
: _strategy.getCountryRadioUnselectedIcon(),
|
|
width: 16.w,
|
|
height: 16.w,
|
|
),
|
|
),
|
|
onTap: () {
|
|
selectCountryInfo = provider.selectCountry(
|
|
subIndex,
|
|
cIndex,
|
|
);
|
|
setState(() {});
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|