profile_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. import 'package:dotted_border/dotted_border.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/rendering.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import 'package:keyboard/base/base_page.dart';
  8. import 'package:keyboard/data/bean/keyboard_info.dart';
  9. import 'package:keyboard/module/profile/profile_controller.dart';
  10. import 'package:keyboard/utils/intimacy_util.dart';
  11. import '../../resource/assets.gen.dart';
  12. import '../../resource/string.gen.dart';
  13. import '../../router/app_pages.dart';
  14. import '../../utils/styles.dart';
  15. import '../../widget/avatar/avatar_image_widget.dart';
  16. class ProfilePage extends BasePage<ProfileController> {
  17. const ProfilePage({super.key});
  18. static Future<dynamic> start() async {
  19. return await Get.toNamed(RoutePath.profile);
  20. }
  21. @override
  22. Color backgroundColor() {
  23. return const Color(0xFFF6F5FA);
  24. }
  25. @override
  26. immersive() {
  27. return true;
  28. }
  29. @override
  30. Widget buildBody(BuildContext context) {
  31. return Stack(
  32. children: [
  33. SafeArea(
  34. child: CustomScrollView(
  35. slivers: [
  36. SliverToBoxAdapter(
  37. child: Column(
  38. crossAxisAlignment: CrossAxisAlignment.start,
  39. children: [_buildTitle(), SizedBox(height: 26.h)],
  40. ),
  41. ),
  42. // 键盘列表
  43. Obx(() {
  44. if (controller.customKeyboardInfoList.isEmpty) {
  45. return SliverToBoxAdapter(child: _buildKeyboardListItem(
  46. keyboardInfo: null,
  47. isChosen: false,
  48. hasKeyboard: false,
  49. ));
  50. }
  51. return SliverList(
  52. delegate: SliverChildBuilderDelegate((context, index) {
  53. KeyboardInfo keyboardInfo =
  54. controller.customKeyboardInfoList[index];
  55. return Obx(() {
  56. return _buildKeyboardListItem(
  57. keyboardInfo: keyboardInfo,
  58. isChosen: keyboardInfo.id == controller.currentCustomKeyboardInfo.id,
  59. hasKeyboard: true,
  60. );
  61. });
  62. }, childCount: controller.customKeyboardInfoList.length),
  63. );
  64. }),
  65. SliverToBoxAdapter(
  66. child: SizedBox(height: 110.h),
  67. ),
  68. ],
  69. )
  70. ),
  71. Positioned(
  72. bottom: 20.h,
  73. left: 16.w,
  74. right: 16.w,
  75. child: InkWell(
  76. onTap: () {
  77. controller.clickSaveButton();
  78. },
  79. child: Container(
  80. height: 48.h,
  81. alignment: Alignment.center,
  82. decoration: Styles.getActivateButtonDecoration(31.r),
  83. child: Text(
  84. StringName.profileSave,
  85. style: Styles.getTextStyleWhiteW500(16.sp),
  86. ),
  87. ),
  88. ),
  89. ),
  90. // 背景图片
  91. IgnorePointer(child: Assets.images.bgMine.image(width: 360.w)),
  92. ],
  93. );
  94. }
  95. // 爱心
  96. _buildLoveIndex(int? intimacy) {
  97. return Container(
  98. width: 87.w,
  99. height: 71.h,
  100. decoration: BoxDecoration(
  101. image: DecorationImage(image: Assets.images.bgProfileLove.provider()),
  102. ),
  103. child: Column(
  104. children: [
  105. SizedBox(height: 45.h),
  106. Row(
  107. mainAxisAlignment: MainAxisAlignment.center,
  108. children: [Container(
  109. padding: EdgeInsets.only(left: 8.w,right: 8.w),
  110. decoration: ShapeDecoration(
  111. color: Colors.white,
  112. shape: RoundedRectangleBorder(
  113. side: BorderSide(width: 1.18.w, color: const Color(0xFFFD649B)),
  114. borderRadius: BorderRadius.circular(12.36.r),
  115. ),
  116. ),
  117. child:
  118. (intimacy != null)
  119. ? Center(
  120. child: Text(
  121. IntimacyUtil.getIntimacyName(intimacy),
  122. style: TextStyle(
  123. color: const Color(0xFFFF73E0),
  124. fontSize: 11.sp,
  125. fontWeight: FontWeight.w500,
  126. ),
  127. ),
  128. )
  129. : Center(
  130. child: Text(
  131. "?",
  132. style: TextStyle(
  133. color: const Color(0xFFFF73E0),
  134. fontSize: 11.sp,
  135. fontWeight: FontWeight.w500,
  136. ),
  137. ),
  138. ),
  139. ),],)
  140. ],
  141. ),
  142. );
  143. }
  144. _buildTitle() {
  145. return Container(
  146. alignment: Alignment.centerLeft,
  147. padding: EdgeInsets.only(top: 12.h, left: 16.w, right: 16.w),
  148. child: Row(
  149. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  150. children: [
  151. GestureDetector(
  152. onTap: () => controller.clickBack(),
  153. child: Assets.images.iconMineBackArrow.image(
  154. width: 24.w,
  155. height: 24.w,
  156. ),
  157. ),
  158. Text(
  159. StringName.profileList,
  160. style: Styles.getTextStyleBlack204W500(17.sp),
  161. ),
  162. GestureDetector(
  163. onTap: () => controller.clickAddButton(),
  164. child: Assets.images.iconProfileAdd.image(
  165. width: 24.w,
  166. height: 24.w,
  167. ),
  168. ),
  169. ],
  170. ),
  171. );
  172. }
  173. Widget _buildKeyboardListItem({
  174. KeyboardInfo? keyboardInfo,
  175. bool isChosen = false,
  176. required bool hasKeyboard,
  177. }) {
  178. final String title = hasKeyboard ? '我&${keyboardInfo?.name ?? ""}' : '我';
  179. final int? intimacy = hasKeyboard ? keyboardInfo?.intimacy : null;
  180. final String? keyboardAvatar = hasKeyboard ? keyboardInfo?.imageUrl : null;
  181. final int gender = hasKeyboard ? (keyboardInfo?.gender ?? 1) : 1;
  182. return GestureDetector(
  183. onTap: hasKeyboard ? () => controller.clickOnChangeKeyboard(keyboardInfo!) : null,
  184. child: Container(
  185. height: 164.h,
  186. margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 12.h),
  187. decoration: isChosen
  188. ? ShapeDecoration(
  189. gradient: LinearGradient(
  190. begin: Alignment(0.02, 0.04),
  191. end: Alignment(1.00, 1.00),
  192. colors: [const Color(0xFFE7A0FF), const Color(0xFFAB8FFA)],
  193. ),
  194. shape: RoundedRectangleBorder(
  195. borderRadius: BorderRadius.circular(22.r),
  196. ),
  197. shadows: [
  198. BoxShadow(
  199. color: Color(0x1CD6C1FF),
  200. blurRadius: 4.r,
  201. offset: Offset(0, 4.r),
  202. spreadRadius: 0,
  203. ),
  204. ],
  205. )
  206. : ShapeDecoration(
  207. color: Colors.white,
  208. shape: RoundedRectangleBorder(
  209. borderRadius: BorderRadius.circular(20.r),
  210. ),
  211. ),
  212. child: Stack(
  213. children: [
  214. if (isChosen)
  215. Opacity(
  216. opacity: 0.1,
  217. child: Assets.images.bgProfileSelected.image(),
  218. ),
  219. Column(
  220. crossAxisAlignment: CrossAxisAlignment.center,
  221. children: [
  222. Padding(
  223. padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 10.h),
  224. child: Row(
  225. mainAxisAlignment: MainAxisAlignment.start,
  226. children: [
  227. Text(
  228. title,
  229. style: TextStyle(
  230. color: const Color(0xFF202020),
  231. fontSize: 16.sp,
  232. fontWeight: FontWeight.w700,
  233. ),
  234. ),
  235. ],
  236. ),
  237. ),
  238. SizedBox(height: 10.h),
  239. Padding(
  240. padding: EdgeInsets.symmetric(horizontal: 16.w),
  241. child: Divider(
  242. height: 1.h,
  243. color: isChosen ? Colors.transparent : Color(0xffF5F5F5),
  244. ),
  245. ),
  246. Expanded(
  247. child: Container(
  248. margin: isChosen ? EdgeInsets.symmetric(horizontal: 4.w, vertical: 4.w) : EdgeInsets.zero,
  249. decoration: ShapeDecoration(
  250. color: Colors.white,
  251. shape: RoundedRectangleBorder(
  252. borderRadius: BorderRadius.circular(20.r),
  253. ),
  254. shadows: [
  255. BoxShadow(
  256. color: Color(0x1CD6C1FF),
  257. blurRadius: 4.r,
  258. offset: Offset(0, 4),
  259. spreadRadius: 0,
  260. ),
  261. ],
  262. ),
  263. child: Row(
  264. mainAxisAlignment: MainAxisAlignment.center,
  265. children: [
  266. _buildProfileAvatar(
  267. imageUrl: controller.userInfo?.imageUrl,
  268. gender: controller.userGender,
  269. onTap: () => controller.clickAvatar(isUser: true),
  270. genderIconAlignment: Alignment.topRight,
  271. ),
  272. SizedBox(width: 8.w),
  273. _buildLoveIndex(intimacy),
  274. SizedBox(width: 8.w),
  275. hasKeyboard
  276. ? _buildProfileAvatar(
  277. imageUrl: keyboardAvatar,
  278. gender: gender,
  279. onTap: () => controller.clickAvatar(isUser: false,keyboardInfo:keyboardInfo),
  280. genderIconAlignment: Alignment.topLeft,
  281. )
  282. : _buildKeyboardListEmptyAvatar(
  283. onTap: () => controller.clickAddButton(),
  284. ),
  285. ],
  286. ),
  287. ),
  288. ),
  289. ],
  290. ),
  291. ],
  292. ),
  293. ),
  294. );
  295. }
  296. // 头像
  297. Widget _buildProfileAvatar({
  298. required String? imageUrl,
  299. required int gender,
  300. required VoidCallback? onTap,
  301. Alignment genderIconAlignment = Alignment.topRight,
  302. }) {
  303. return GestureDetector(
  304. onTap: onTap,
  305. child: Stack(
  306. alignment: Alignment.bottomCenter,
  307. children: [
  308. Container(
  309. margin: EdgeInsets.only(bottom: 10.h),
  310. width: 78.w,
  311. height: 78.w,
  312. decoration: ShapeDecoration(
  313. color: gender == 1 ? const Color(0xFFB7B6FF) : null,
  314. gradient:
  315. gender == 1
  316. ? null
  317. : const LinearGradient(
  318. begin: Alignment(0.5, 0),
  319. end: Alignment(0.5, 1.0),
  320. colors: [Color(0xFFEBE6FF), Color(0xFFFFE6FE)],
  321. ),
  322. shape: RoundedRectangleBorder(
  323. side: BorderSide(width: 1.5.w, color: Colors.white),
  324. borderRadius: BorderRadius.circular(40.r),
  325. ),
  326. ),
  327. child: CircleAvatarWidget(
  328. image: Assets.images.iconKeyboardDefaultAvatar.provider(),
  329. imageUrl: imageUrl,
  330. size: 78.w,
  331. borderWidth: 0.r,
  332. placeholder: (_, __) {
  333. return const CupertinoActivityIndicator();
  334. },
  335. ),
  336. ),
  337. Positioned(
  338. top: 0,
  339. left: genderIconAlignment == Alignment.topLeft ? 0 : null,
  340. right: genderIconAlignment == Alignment.topRight ? 0 : null,
  341. child:
  342. gender == 1
  343. ? Assets.images.iconProfileMale.image(
  344. width: 20.w,
  345. height: 20.w,
  346. )
  347. : Assets.images.iconProfileFemale.image(
  348. width: 20.w,
  349. height: 20.w,
  350. ),
  351. ),
  352. Positioned(
  353. child: Container(
  354. width: 58.w,
  355. height: 28.h,
  356. decoration: ShapeDecoration(
  357. color: Colors.white,
  358. shape: RoundedRectangleBorder(
  359. side: BorderSide(width: 1, color: const Color(0x6BE1E1E1)),
  360. borderRadius: BorderRadius.circular(50.r),
  361. ),
  362. shadows: [
  363. BoxShadow(
  364. color: Color(0x56E6D9FF),
  365. blurRadius: 4,
  366. offset: Offset(0, 3),
  367. spreadRadius: 0,
  368. ),
  369. ],
  370. ),
  371. child: Row(
  372. mainAxisAlignment: MainAxisAlignment.center,
  373. children: [
  374. Assets.images.iconProfileEdit.image(
  375. width: 12.w,
  376. height: 12.w,
  377. ),
  378. Text(
  379. StringName.profileEdit,
  380. style: Styles.getTextStyleBlack178W500(11.sp),
  381. ),
  382. ],
  383. ),
  384. ),
  385. ),
  386. ],
  387. ),
  388. );
  389. }
  390. // 没有Keyboard时
  391. _buildKeyboardListEmptyAvatar({required VoidCallback? onTap}) {
  392. return GestureDetector(
  393. onTap: onTap,
  394. child: Stack(
  395. alignment: Alignment.bottomCenter,
  396. children: [
  397. Container(
  398. margin: EdgeInsets.only(bottom: 10.h),
  399. width: 78.w,
  400. height: 78.w,
  401. child: DottedBorder(
  402. color: const Color(0xFFA595C8),
  403. strokeWidth: 1.0.w,
  404. borderType: BorderType.Circle,
  405. child: Container(
  406. width: 78.w,
  407. height: 78.w,
  408. margin: EdgeInsets.only(bottom: 10.h),
  409. alignment: Alignment.center,
  410. child: Column(
  411. crossAxisAlignment: CrossAxisAlignment.center,
  412. mainAxisAlignment: MainAxisAlignment.end,
  413. children: [
  414. Assets.images.iconProfilePlus.image(
  415. width: 22.5.w,
  416. height: 22.5.w,
  417. fit: BoxFit.cover,
  418. ),
  419. SizedBox(height: 2.h),
  420. Text(
  421. StringName.profileAdd,
  422. style: TextStyle(
  423. color: const Color(0xB2755BAB),
  424. fontSize: 12.sp,
  425. fontWeight: FontWeight.w400,
  426. ),
  427. ),
  428. ],
  429. ),
  430. ),
  431. )
  432. ),
  433. ],
  434. ),
  435. );
  436. }
  437. }