| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/src/widgets/framework.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:get/get_core/src/get_main.dart';
- import 'package:location/data/repositories/config_repository.dart';
- import 'package:location/module/avatar/user_avatar_controller.dart';
- import 'package:location/resource/assets.gen.dart';
- import 'package:location/resource/string.gen.dart';
- import 'package:location/utils/common_expand.dart';
- import '../../handler/error_handler.dart';
- import '../../resource/colors.gen.dart';
- import '../../utils/common_style.dart';
- class UserAvatarView extends GetView<UserAvatarController> {
- UserAvatarView({super.key, required List<String> avatarList}) {
- Get.lazyPut(() => UserAvatarController(avatarList));
- }
- static void show() {
- ConfigRepository.getInstance().requestUserAvatarList().then((list) {
- Get.bottomSheet(UserAvatarView(avatarList: list),
- isScrollControlled: true,
- barrierColor: ColorName.black55,
- backgroundColor: ColorName.transparent);
- }).catchError((error) {
- ErrorHandler.toastError(error);
- });
- }
- @override
- Widget build(BuildContext context) {
- return Container(
- width: 1.sw,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(10.w),
- topRight: Radius.circular(10.w),
- ),
- ),
- child: IntrinsicHeight(
- child: Column(
- children: [
- SizedBox(height: 12.w),
- buildTitleView(),
- SizedBox(height: 22.w),
- buildAvatarListView(),
- SizedBox(height: 30.w),
- buildSureBtnView(),
- SizedBox(height: 20.w),
- ],
- ),
- ),
- );
- }
- Widget buildTitleView() {
- return Row(
- children: [
- SizedBox(width: 37.w),
- Spacer(),
- Text(
- StringName.accountPleaseSelectAvatar,
- style: TextStyle(fontSize: 14.sp, color: '#404040'.color),
- ),
- Spacer(),
- GestureDetector(
- onTap: controller.onCloseClick,
- child:
- Assets.images.iconAvatarClose.image(width: 25.w, height: 25.w)),
- SizedBox(width: 12.w),
- ],
- );
- }
- Widget buildAvatarListView() {
- return Container(
- margin: EdgeInsets.symmetric(horizontal: 20.w),
- child: Builder(builder: (context) {
- return Wrap(
- spacing: 25.w,
- runSpacing: 30.w,
- children: controller.avatarList.map((url) {
- double itemWidth =
- (MediaQuery.of(context).size.width - 25.w * 5) / 4;
- return GestureDetector(
- onTap: () {
- controller.onSelectAvatarClick(url);
- },
- child: buildAvatarItem(itemWidth, url),
- );
- }).toList(),
- );
- }));
- }
- Widget buildAvatarItem(double itemWidth, String url) {
- return Stack(
- children: [
- Container(
- width: itemWidth,
- height: itemWidth,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- border: Border.all(width: 1.w, color: '#F0F0F0'.color)),
- child: ClipOval(
- child: CachedNetworkImage(
- width: double.infinity,
- height: double.infinity,
- imageUrl: url,
- fit: BoxFit.cover,
- ),
- ),
- ),
- Obx(() {
- return Visibility(
- visible: controller.selectedAvatar == url ||
- (controller.selectedAvatar == null &&
- controller.mineInfo?.avatar == url),
- child: Container(
- width: itemWidth,
- height: itemWidth,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- border:
- Border.all(width: 3.w, color: ColorName.colorPrimary)),
- ),
- );
- }),
- Obx(() {
- return Visibility(
- visible: controller.selectedAvatar == url ||
- (controller.selectedAvatar == null &&
- controller.mineInfo?.avatar == url),
- child: Positioned(
- bottom: 0,
- right: 0,
- child: Assets.images.iconAvatarSelected
- .image(width: 20.w, height: 20.w)),
- );
- })
- ],
- );
- }
- Widget buildSureBtnView() {
- return GestureDetector(
- onTap: controller.onSelectedClick,
- child: Container(
- width: 312.w,
- height: 44.w,
- decoration: getPrimaryBtnDecoration(100.r),
- child: Center(
- child: Text(StringName.accountSelectAvatarBtnTxt,
- style: TextStyle(fontSize: 15.sp, color: Colors.white))),
- ),
- );
- }
- }
|