import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:wow_english/common/core/assets_const.dart'; import 'package:wow_english/common/core/user_util.dart'; import 'package:wow_english/common/widgets/we_app_bar.dart'; import 'package:wow_english/models/user_entity.dart'; import 'package:wow_english/pages/user/bloc/user_bloc.dart'; import 'package:wow_english/utils/image_util.dart'; import 'package:wow_english/utils/log_util.dart'; import '../modify/modify_user_information_page.dart'; class UserInformationPage extends StatelessWidget { const UserInformationPage({super.key}); @override Widget build(BuildContext context) { return BlocProvider( create: (context) => UserBloc(), child: const _UserInformationView(), ); } } class _UserInformationView extends StatelessWidget { const _UserInformationView({super.key}); @override Widget build(BuildContext context) { return BlocListener( listener: (context, state) { Log.d('UserInformationPage: $state'); }, child: BlocBuilder(builder: (context, state) { return _UserInformationContentView(); }), ); } } class _UserInformationContentView extends StatelessWidget { const _UserInformationContentView({super.key}); void _openModifyPage(BuildContext context, ModifyUserInformationType type) { Log.d('_openModifyPage($type)'); // 暂时关闭修改,修复后打开 //ModifyUserInformationPage.push(context, type); } @override Widget build(BuildContext context) { UserEntity user = UserUtil.getUser()!; return Scaffold( backgroundColor: Colors.white, appBar: const WEAppBar( titleText: "个人信息", ), body: SingleChildScrollView( padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h), child: Column( children: [ _buildContentRow( '头像', CircleAvatar( radius: 22.5.r, backgroundColor: const Color(0xFF140C10), child: CircleAvatar( radius: 21.r, backgroundImage: ImageUtil.getImageProviderOnDefault(user.avatarUrl), ), )), 11.verticalSpace, _buildContentRow( '名字', Text( user.name, style: TextStyle( fontWeight: FontWeight.w500, color: const Color(0xFF333333), fontSize: 21.sp, ), ), onTap: () => _openModifyPage(context, ModifyUserInformationType.name)), 11.verticalSpace, _buildContentRow( '年龄', Text( user.age.toString(), style: TextStyle( fontWeight: FontWeight.w500, color: const Color(0xFF333333), fontSize: 21.sp, ), ), onTap: () => _openModifyPage(context, ModifyUserInformationType.age)), 11.verticalSpace, _buildContentRow( '性别', Text( user.getGenderString(), style: TextStyle( fontWeight: FontWeight.w500, color: const Color(0xFF333333), fontSize: 21.sp, ), ), onTap: () => _openModifyPage(context, ModifyUserInformationType.gender)), 11.verticalSpace, _buildContentRow( '账号', Text( user.phoneNum, style: TextStyle( fontWeight: FontWeight.w500, color: const Color(0xFF999999), fontSize: 21.sp, ), ), isHideEndIcon: true, ), ], ), ), ); } Widget _buildContentRow(String filedName, Widget contentWidget, {bool isHideEndIcon = false, Function()? onTap}) { return GestureDetector( onTap: onTap, child: Container( padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 18.h, bottom: 18.h), decoration: BoxDecoration( image: DecorationImage( image: ImageUtil.getImageProviderOnDefault(AssetsConst.bgUserInformationText), fit: BoxFit.fill)), child: Row(children: [ Text( filedName, style: TextStyle( fontWeight: FontWeight.w700, color: const Color(0xFF999999), fontSize: 21.sp, ), ), 32.horizontalSpace, Expanded( child: Container( alignment: Alignment.centerLeft, child: contentWidget, )), Offstage( offstage: isHideEndIcon, child: Image.asset(AssetsConst.icNext, width: 20.w, height: 25.h), ) ]), )); } }