home_tab_header_widget.dart 4.12 KB
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wow_english/common/blocs/cachebloc/cache_bloc.dart';
import 'package:wow_english/common/extension/string_extension.dart';

enum HeaderActionType {
  //视频跟读
  video,
  //阶段选择
  phase,
  //磨耳朵
  listen,
  //购买
  shop,
  //个人信息
  user
}

class HomeTabHeaderWidget extends StatelessWidget {

  const HomeTabHeaderWidget({super.key,  this.actionTap});

  final Function(HeaderActionType type)? actionTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 45,
      width: double.infinity,
      color: Colors.purple,
      padding: EdgeInsets.symmetric(horizontal: 9.5.w),
      child: Row(
        children: [
          ScreenUtil().bottomBarHeight.horizontalSpace,
          GestureDetector(
            onTap: () {
              if(actionTap != null) {
                actionTap!(HeaderActionType.user);
              }
            },
            child: Container(
              decoration: BoxDecoration(
                border: Border.all(
                  width: 1.0,
                  color: const Color(0xFF140C10),
                ),
                borderRadius: BorderRadius.circular(21),
              ),
              child: CircleAvatar(
                radius: 21,
                backgroundImage: NetworkImage(
                    context.read<CacheBloc>().userEntity?.avatarUrl??'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Faa1c2213-820a-4223-8757-5f8cee318a28%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1688713226&t=192b18a613683bcdc5bd76f65c9ff032',
                ),
              ),
            ),
          ),
          GestureDetector(
            onTap: () {
              if(actionTap != null) {
                actionTap!(HeaderActionType.user);
              }
            },
            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(
                context.read<CacheBloc>().userEntity?.name??'',
                style: TextStyle(
                    color: const Color(0xFF333333),
                    fontSize: 16.sp
                ),
              ),
            ),
          ),
          20.horizontalSpace,
          const Expanded(
              child:Text(
                  'learn wow!yellow',
                  textAlign:TextAlign.left,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 30.0
                ),
              )
          ),
          IconButton(
              onPressed: (){
                if(actionTap != null) {
                  actionTap!(HeaderActionType.video);
                }
              },
              icon: Image.asset('video'.assetPng)
          ),
          IconButton(
              onPressed: (){
                if(actionTap != null) {
                  actionTap!(HeaderActionType.phase);
                }
              },
              icon: Image.asset('home'.assetPng)
          ),
          IconButton(
              onPressed: (){
                if(actionTap != null) {
                  actionTap!(HeaderActionType.listen);
                }
              },
              icon: Image.asset('listen'.assetPng)
          ),
          // IconButton(
          //     onPressed: (){
          //       if(actionTap != null) {
          //         actionTap!(HeaderActionType.shop);
          //       }
          //     },
          //     icon: Image.asset('shop'.assetPng)
          // ),
          ScreenUtil().bottomBarHeight.horizontalSpace,
        ],
      ),
    );
  }
}