app_bar.dart 1.87 KB
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';

class MyAppBar extends StatelessWidget {
  MyAppBar(this.title, {this.showBack = true,this.backgroundColor=MyColours.color_ffffff,this.fontColor=MyColours.color_131313});

  final String title;//标题文字
  final bool showBack;//是否显示返回按钮
  final Color backgroundColor;//背景色
  final Color fontColor;//字体颜色

  @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: () {
                  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
                ),
              ),
            )
          ],
        ));
  }
}