525 lines
20 KiB
Dart
525 lines
20 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.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_compontent.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_tts.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_loading_manager.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_pick_utils.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
import 'package:aslan/chatvibe_managers/authentication_manager.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:aslan/chatvibe_ui/components/custom_cached_image.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_screen.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_routes.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_date_utils.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/login_res.dart';
|
|
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
|
|
|
|
import '../../../chatvibe_domain/usecases/at_custom_filtering_textinput_formatter.dart';
|
|
import '../../country/at_country_page.dart';
|
|
|
|
///编辑个人信息
|
|
class EditProfilePage extends StatefulWidget {
|
|
const EditProfilePage({super.key});
|
|
|
|
@override
|
|
_EditProfilePageState createState() => _EditProfilePageState();
|
|
}
|
|
|
|
class _EditProfilePageState extends State<EditProfilePage> {
|
|
///默认女
|
|
int type = 0;
|
|
DateTime birthdayDate = DateTime(2006);
|
|
TextEditingController nicknameController = TextEditingController();
|
|
ChatVibeUserProfileManager? userProvider;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
userProvider = Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
Provider.of<AppGeneralManager>(context, listen: false).selectCountryInfo =
|
|
null;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
userProvider?.clearEditUserUser();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final businessLogicStrategy = ATGlobalConfig.businessLogicStrategy;
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false,
|
|
body: Stack(
|
|
alignment: Alignment.topCenter,
|
|
children: [
|
|
Image.asset(
|
|
businessLogicStrategy.getEditProfileBackgroundImage(),
|
|
width: ScreenUtil().screenWidth,
|
|
height: ScreenUtil().screenHeight,
|
|
fit: BoxFit.cover,
|
|
),
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 120.w),
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
GestureDetector(
|
|
child: Consumer<ChatVibeUserProfileManager>(
|
|
builder: (_, provider, __) {
|
|
return provider.editUser != null &&
|
|
provider.editUser!.userAvatar != null
|
|
? head(
|
|
url: provider.editUser!.userAvatar ?? "",
|
|
width: 75.w,
|
|
)
|
|
: Image.asset(
|
|
businessLogicStrategy
|
|
.getEditProfileDefaultAvatarImage(),
|
|
width: 75.w,
|
|
height: 75.w,
|
|
);
|
|
},
|
|
),
|
|
onTap: () {
|
|
ATPickUtils.pickImageProcess(context, (
|
|
bool success,
|
|
String url,
|
|
) {
|
|
if (success) {
|
|
userProvider?.setUserAvatar(url);
|
|
}
|
|
});
|
|
},
|
|
),
|
|
SizedBox(width: 10.w),
|
|
Container(
|
|
padding: EdgeInsets.only(left: width(12), right: width(12)),
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 185.w,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
businessLogicStrategy
|
|
.getEditProfileInputBackgroundColor(),
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(height(8)),
|
|
),
|
|
),
|
|
child: TextField(
|
|
textAlign: TextAlign.center,
|
|
controller: nicknameController,
|
|
onChanged: (text) {
|
|
setState(() {});
|
|
},
|
|
inputFormatters: [ATCustomFilteringTextInputFormatter()],
|
|
maxLength: 38,
|
|
decoration: InputDecoration(
|
|
hintText: ATAppLocalizations.of(context)!.enterNickname,
|
|
hintStyle: TextStyle(
|
|
color: Colors.white54,
|
|
fontSize: 14.sp,
|
|
),
|
|
contentPadding: EdgeInsets.only(top: 0.w),
|
|
counterText: '',
|
|
isDense: true,
|
|
filled: false,
|
|
focusColor: Colors.transparent,
|
|
hoverColor: Colors.transparent,
|
|
border: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
disabledBorder: InputBorder.none,
|
|
errorBorder: InputBorder.none,
|
|
focusedErrorBorder: InputBorder.none,
|
|
fillColor: Colors.black45,
|
|
),
|
|
style: TextStyle(
|
|
fontSize: sp(15),
|
|
color: Colors.black,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 25.w),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 128.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
gradient:
|
|
type == 1
|
|
? LinearGradient(
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
colors: businessLogicStrategy
|
|
.getEditProfileGenderButtonGradient(
|
|
true,
|
|
type == 1,
|
|
),
|
|
)
|
|
: LinearGradient(
|
|
colors: [Colors.white30, Colors.white30],
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Image.asset(
|
|
businessLogicStrategy.getEditProfileGenderIcon(
|
|
true,
|
|
),
|
|
width: 25.w,
|
|
height: 25.w,
|
|
color: type == 1 ? Colors.white : Colors.white,
|
|
),
|
|
SizedBox(width: 8.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.male,
|
|
textColor: type == 1 ? Colors.white : Colors.white,
|
|
fontSize: 13.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
onTap: () {
|
|
if (type == 0) {
|
|
setState(() {
|
|
type = 1;
|
|
userProvider?.setUserSex(type);
|
|
});
|
|
}
|
|
},
|
|
),
|
|
SizedBox(width: 15.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 128.w,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
color: type == 1 ? Colors.white : Colors.white,
|
|
gradient:
|
|
type == 1
|
|
? LinearGradient(
|
|
colors: [Colors.white30, Colors.white30],
|
|
)
|
|
: LinearGradient(
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
colors: businessLogicStrategy
|
|
.getEditProfileGenderButtonGradient(
|
|
false,
|
|
type != 1,
|
|
),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Image.asset(
|
|
businessLogicStrategy.getEditProfileGenderIcon(
|
|
false,
|
|
),
|
|
width: 25.w,
|
|
height: 25.w,
|
|
color: type == 1 ? Colors.white : Colors.white,
|
|
),
|
|
SizedBox(width: 8.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.female,
|
|
textColor: type == 1 ? Colors.white : Colors.white,
|
|
fontSize: 13.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
onTap: () {
|
|
if (type == 1) {
|
|
setState(() {
|
|
type = 0;
|
|
userProvider?.setUserSex(type);
|
|
});
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 12.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
padding: EdgeInsets.only(left: width(12), right: width(12)),
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 270.w,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
businessLogicStrategy
|
|
.getEditProfileInputBackgroundColor(),
|
|
borderRadius: BorderRadius.all(Radius.circular(height(12))),
|
|
),
|
|
child: text(
|
|
ATMDateUtils.formatDateTime(birthdayDate),
|
|
textColor: Colors.white54,
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
onTap: () {
|
|
_selectDate();
|
|
},
|
|
),
|
|
SizedBox(height: 12.w),
|
|
GestureDetector(
|
|
child: Consumer<AppGeneralManager>(
|
|
builder: (_, provider, __) {
|
|
return Container(
|
|
padding: EdgeInsets.only(
|
|
left: width(12),
|
|
right: width(12),
|
|
),
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 270.w,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
businessLogicStrategy
|
|
.getEditProfileInputBackgroundColor(),
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(height(12)),
|
|
),
|
|
),
|
|
child:
|
|
provider.selectCountryInfo != null
|
|
? Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
CustomCachedImage(
|
|
imageUrl:
|
|
provider
|
|
.selectCountryInfo!
|
|
.nationalFlag ??
|
|
"",
|
|
width: 26.w,
|
|
height: 16.w,
|
|
),
|
|
SizedBox(width: 5.w),
|
|
text(
|
|
provider.selectCountryInfo!.aliasName ?? "",
|
|
textColor: Colors.white54,
|
|
fontSize: 14.sp,
|
|
),
|
|
],
|
|
)
|
|
: text(
|
|
ATAppLocalizations.of(
|
|
context,
|
|
)!.selectYourCountry,
|
|
textColor: Colors.white54,
|
|
fontSize: 15.sp,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
onTap: () {
|
|
SmartDialog.show(
|
|
tag: "showCountryPage",
|
|
alignment: Alignment.bottomCenter,
|
|
debounce: true,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return SizedBox(
|
|
height: ScreenUtil().screenHeight * 0.5,
|
|
child: ATCountryPage(isDialog: true),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
SizedBox(height: 25.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
padding: EdgeInsets.only(left: width(12), right: width(12)),
|
|
alignment: Alignment.center,
|
|
height: 46.w,
|
|
width: 270.w,
|
|
decoration: BoxDecoration(
|
|
color:
|
|
businessLogicStrategy
|
|
.getEditProfileContinueButtonColor(),
|
|
borderRadius: BorderRadius.all(Radius.circular(height(12))),
|
|
),
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.conntinue,
|
|
textColor: Colors.white,
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
onTap: () {
|
|
_submitUserProfile();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _selectDate() async {
|
|
showCupertinoModalPopup(
|
|
context: context,
|
|
builder:
|
|
(context) => SafeArea(
|
|
top: false,
|
|
child: Container(
|
|
height: 240.w,
|
|
padding: EdgeInsets.only(top: 6),
|
|
color: CupertinoColors.systemBackground,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 10.w),
|
|
Row(
|
|
children: [
|
|
SizedBox(width: 10.w),
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: Alignment.topCenter,
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.cancel,
|
|
textColor: Colors.black87,
|
|
fontSize: 15.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
alignment: Alignment.topCenter,
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.birthday,
|
|
textColor: Colors.black87,
|
|
fontSize: 15.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
child: Container(
|
|
alignment: Alignment.topCenter,
|
|
child: text(
|
|
ATAppLocalizations.of(context)!.confirm,
|
|
textColor:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getEditProfileDatePickerConfirmColor(),
|
|
fontSize: 15.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
onTap: () {
|
|
setState(() {});
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
SizedBox(width: 10.w),
|
|
],
|
|
),
|
|
Expanded(
|
|
child: CupertinoDatePicker(
|
|
mode: CupertinoDatePickerMode.date,
|
|
initialDateTime: _getBefor18(),
|
|
maximumDate: _getBefor18(),
|
|
onDateTimeChanged: (date) => birthdayDate = date,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
DateTime _getBefor18() {
|
|
DateTime currentDate = DateTime.now();
|
|
DateTime eighteenYearsAgo = DateTime(
|
|
currentDate.year - 18,
|
|
currentDate.month,
|
|
currentDate.day,
|
|
currentDate.hour,
|
|
currentDate.minute,
|
|
currentDate.second,
|
|
currentDate.millisecond,
|
|
currentDate.microsecond,
|
|
);
|
|
return eighteenYearsAgo;
|
|
}
|
|
|
|
///提交数据
|
|
void _submitUserProfile() async {
|
|
if (nicknameController.text.isEmpty) {
|
|
ATTts.show(ATAppLocalizations.of(context)!.pleaseEnterNickname);
|
|
return;
|
|
}
|
|
if (userProvider?.editUser?.userAvatar == null) {
|
|
ATTts.show(ATAppLocalizations.of(context)!.pleaseUploadUserAvatar);
|
|
return;
|
|
}
|
|
if (Provider.of<AppGeneralManager>(
|
|
context,
|
|
listen: false,
|
|
).selectCountryInfo ==
|
|
null) {
|
|
ATTts.show(ATAppLocalizations.of(context)!.pleaseSelectYourCountry);
|
|
return;
|
|
}
|
|
|
|
ATLoadingManager.exhibitOperation(context: context);
|
|
userProvider?.setUserNickname(nicknameController.text);
|
|
userProvider?.setBornYear(birthdayDate.year);
|
|
userProvider?.setBornMonth(birthdayDate.month);
|
|
userProvider?.setBornDay(birthdayDate.day);
|
|
num age = DateTime.now().year - birthdayDate.year;
|
|
userProvider?.setAge(age.abs());
|
|
String authType =
|
|
Provider.of<ChatVibeAuthenticationManager>(
|
|
context,
|
|
listen: false,
|
|
).authType;
|
|
String idToken =
|
|
Provider.of<ChatVibeAuthenticationManager>(context, listen: false).uid;
|
|
ChatVibeLoginRes user = await AccountRepository().regist(
|
|
authType,
|
|
idToken,
|
|
userProvider!.editUser!,
|
|
);
|
|
AccountStorage().setCurrentUser(user);
|
|
ATLoadingManager.veilRoutine();
|
|
ATNavigatorUtils.push(context, ATRoutes.home, clearStack: true);
|
|
}
|
|
}
|