profile_page.dart 15 KB

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