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/app_config_helper.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import '../../../common/core/user_util.dart'; import '../../../models/course_entity.dart'; import '../../../route/route.dart'; import '../../../utils/image_util.dart'; import '../../user/bloc/user_bloc.dart'; typedef HeaderCallback = void Function(dynamic); class BaseHomeHeaderWidget extends StatelessWidget { const BaseHomeHeaderWidget({super.key, this.entity, this.callBack}); final CourseEntity? entity; final HeaderCallback? callBack; @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { return Container( height: 45, width: double.infinity, decoration: BoxDecoration( image: DecorationImage( image: AssetImage('bg_header_sliver'.assetPng), fit: BoxFit.cover, ), ), padding: EdgeInsets.symmetric(horizontal: 9.5.w), child: Row( children: [ ScreenUtil().bottomBarHeight.horizontalSpace, GestureDetector( onTap: () => {onUserClick()}, child: Container( decoration: BoxDecoration( border: Border.all( width: 1.0, color: const Color(0xFF140C10), ), borderRadius: BorderRadius.circular(21), ), child: CircleAvatar( radius: 21, backgroundImage: ImageUtil.getImageProviderOnDefault( UserUtil.getUser()?.avatarUrl), ), ), ), GestureDetector( onTap: () => {onUserClick()}, child: Container( margin: const EdgeInsets.only(left: 7), padding: const EdgeInsets.all(4.0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(2), border: Border.all( width: 1.0, color: const Color(0xFF140C10), style: BorderStyle.solid), ), child: Text( UserUtil.getUser()?.name ?? '未登录', style: TextStyle( color: const Color(0xFF333333), fontSize: 16.sp), ), ), ), 20.horizontalSpace, const Expanded( child: Text( "WOW ENGLISH", textAlign: TextAlign.left, style: TextStyle(color: Colors.white, fontSize: 30.0), )), Offstage( offstage: AppConfigHelper.shouldHidePay() || !UserUtil.isLogined(), child: GestureDetector( onTap: () => { pushNamed(AppRouteName.shop).then((value) { if (value != null) { if (callBack == null) { } else { callBack!(value); } } }) }, child: Row(children: [ Image( width: 20.0.w, height: 20.0.h, image: AssetImage('ic_countdown'.assetPng)), // 替换为你的图片资源路径 const SizedBox(width: 6.0), // 图片和文本之间的间隔 UserUtil.hasPermission() ? Text('还剩${UserUtil.getRemainingValidity()}天') : const Text('未购买'), ]), )), ScreenUtil().bottomBarHeight.horizontalSpace, ], )); }, ); } void onUserClick() { if (UserUtil.isLogined()) { pushNamed(AppRouteName.user).then((value) { if (value != null) { if (callBack == null) { } else { callBack!(value); } } }); } else { pushNamed(AppRouteName.login); } } }