app_bar.dart 3.51 KB

import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

import '../utils/utils.dart';

class MyAppBar extends StatelessWidget {
  MyAppBar(this.title,
      {this.showBack = true,
      this.backgroundColor = MyColours.color_ffffff,
      this.fontColor = MyColours.color_131313,
      this.callback,
      this.rightImgName,
      this.onTapRight});
  final VoidCallback? callback; //返回回调
  final String title; //标题文字
  final bool showBack; //是否显示返回按钮
  final Color backgroundColor; //背景色
  final Color fontColor; //字体颜色
  final String? rightImgName;
  final GestureTapCallback? onTapRight;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
        width: double.infinity,
        color: backgroundColor,
        padding: EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(30)),
        child: Stack(alignment: Alignment.center, children: <Widget>[
          Positioned(
            left: 0,
            child: showBack
                ? GestureDetector(
                    onTap: () {
                      if (this.callback != null) {
                        this.callback!();
                      } else {
                        Navigator.of(context).pop();
                      }
                    },
                    behavior: HitTestBehavior.opaque,
                    child: Padding(
                      padding: EdgeInsets.symmetric(
                          horizontal: ScreenUtil().setWidth(40),
                          vertical: ScreenUtil().setHeight(15)),
                      child: Image.asset(
                        "assets/icon_back.png",
                        width: ScreenUtil().setWidth(20),
                        height: ScreenUtil().setHeight(31),
                      ),
                    ),
                  )
                : Container(),
          ),
          Center(
            child: Text(
              title,
              style: TextStyle(
                  color: fontColor,
                  fontSize: ScreenUtil().setSp(34),
                  fontWeight: FontWeight.normal,
                  decoration: TextDecoration.none),
            ),
          ),
          Positioned(
              right: 0,
              child: ObjectUtil.isNotEmpty(rightImgName)
                  ? InkWell(
                      onTap: onTapRight,
                      child: Padding(
                          padding:
                              EdgeInsets.only(right: ScreenUtil().setWidth(40)),
                          child: rightImgName!.endsWith('png')
                              ? Image.asset(
                                  Utils.getImgPath(
                                      rightImgName!.replaceAll('.png', '')),
                                  width: ScreenUtil().setWidth(48))
                              : Container(
                                  // color: Colors.red,
                                  alignment: Alignment.center,
                                  child: Text(
                                    rightImgName!,
                                    style: TextStyle(
                                        color: MyColours.color_199095,
                                        fontSize: ScreenUtil().setSp(34)),
                                  ),
                                )),
                    )
                  : Text(''))
        ]));
  }
}