71 lines
1.7 KiB
Dart
71 lines
1.7 KiB
Dart
// Author: fengshengxiong
|
|
// Date: 2024/5/7
|
|
// Description: BaseAppBar
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class BaseAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|
const BaseAppBar(
|
|
this.titleStr, {
|
|
super.key,
|
|
this.height,
|
|
this.backgroundColor,
|
|
this.titleStyle,
|
|
this.title,
|
|
this.iconColor,
|
|
this.showLeading = true,
|
|
this.leading,
|
|
this.leadingOnPressed,
|
|
this.actions,
|
|
this.systemOverlayStyle,
|
|
this.bottom,
|
|
});
|
|
|
|
final double? height;
|
|
final Color? backgroundColor;
|
|
final String titleStr;
|
|
final TextStyle? titleStyle;
|
|
final Widget? title;
|
|
final Color? iconColor;
|
|
final bool showLeading;
|
|
final Widget? leading;
|
|
final Function()? leadingOnPressed;
|
|
final List<Widget>? actions;
|
|
final SystemUiOverlayStyle? systemOverlayStyle;
|
|
final PreferredSizeWidget? bottom;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget titleWidget = title ??
|
|
Text(
|
|
titleStr,
|
|
style: titleStyle,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
Widget? leadingWidget = showLeading
|
|
? (leading ??
|
|
IconButton(
|
|
icon: Icon(
|
|
Icons.arrow_back_ios_rounded,
|
|
color: iconColor,
|
|
),
|
|
onPressed: leadingOnPressed ?? Get.back,
|
|
))
|
|
: null;
|
|
return AppBar(
|
|
title: titleWidget,
|
|
backgroundColor: backgroundColor,
|
|
systemOverlayStyle: systemOverlayStyle,
|
|
leading: leadingWidget,
|
|
actions: actions,
|
|
bottom: bottom,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Size get preferredSize => Size.fromHeight(height ?? kToolbarHeight);
|
|
}
|