profile_page.dart 15 KB

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