您只需要使用您在其上创建 AppBar 的 GlobalUtilclass 并在整个类中使用,如下所示
GlobalUtil.dart
import 'package:flutter/material.dart';
import 'colors.dart';
class GlobalUtil {
static Widget showAppBar(BuildContext context, String msg, String path) {
return AppBar(
centerTitle: true,
title: Text(
msg,
style: TextStyle(
color: ColorConst.TEXT_DARK_GREY_COLOR, /// USE THE COLOR AS PER YOUR REQUIREMENT
fontFamily: 'Medium', /// USE THE FONT FAMILY AS PER YOUR REQUIREMENT
fontSize: Dimens.TEXT_EXTRA_EXTRA_LARGE),////// USE THE DIMENSION OF TEXT AS PER YOUR REQUIREMENT
),
actions: [
new IconButton(
icon: new Image.asset("YOUR_ICON_PATH",height: 20.0,width: 20.0,),
onPressed: () => {
},
)
],
leading: Padding(
padding: EdgeInsets.all(8),
child: new IconButton(
// icon: new Icon(iconData, color: Colors.black),
icon: new Image.asset(path),
onPressed: () => Navigator.of(context).pop(),
)),
backgroundColor: Colors.PINK,
elevation: 0.0,
);
}
}
在任何类中,您都可以按如下方式使用它
GlobalUtil.showAppBar(context, "YOUR HEADING TEXT",
"YOUR_ICON_FOR_BACK"),