app-starlock/star_lock/lib/tools/titleAppBar.dart
2023-09-07 18:36:16 +08:00

63 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class TitleAppBar extends AppBar {
@override
final Color? backgroundColor;
final String? barTitle;
final Color? titleColor;
final Color? iconColor;
final bool? haveTitleWidget;
final Widget? titleWidget;
final bool? haveBack;
final Function? backAction;
final bool? haveOtherLeftWidget;
final Widget? leftWidget;
List<Widget>? actionsList;
TitleAppBar(
{Key? key,
this.barTitle,
this.titleColor,
this.haveTitleWidget = false,
this.titleWidget,
this.iconColor,
this.backgroundColor,
this.actionsList,
this.haveBack,
this.backAction,
this.haveOtherLeftWidget = false,
this.leftWidget})
: super(key: key);
@override
_TitleAppBarState createState() => _TitleAppBarState();
}
class _TitleAppBarState extends State<TitleAppBar> {
@override
Widget build(BuildContext context) {
return AppBar(
elevation: 0,
leading: widget.haveOtherLeftWidget!
? widget.leftWidget
: (widget.haveBack!
? IconButton(
icon: Icon(Icons.arrow_back_ios,
color: widget.iconColor ?? Colors.white),
onPressed: () => widget.backAction ?? Navigator.of(context).pop(),
)
: Container()),
backgroundColor: widget.backgroundColor ?? Colors.white,
title: widget.haveTitleWidget!
? widget.titleWidget
: Text(widget.barTitle ?? '',
style: TextStyle(
color: widget.titleColor ?? Colors.white,
fontSize: 28.sp,
fontWeight: FontWeight.w600)),
centerTitle: true,
actions: widget.actionsList ?? []);
}
}