app-starlock/lib/tools/titleAppBar.dart

85 lines
2.7 KiB
Dart
Raw Normal View History

2023-07-10 17:50:31 +08:00
import 'package:flutter/material.dart';
2024-01-02 18:03:50 +08:00
import 'package:flutter_easyloading/flutter_easyloading.dart';
2023-07-10 17:50:31 +08:00
import 'package:flutter_screenutil/flutter_screenutil.dart';
2024-04-29 10:45:49 +08:00
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/flavors.dart';
2024-11-21 18:11:11 +08:00
import 'package:star_lock/tools/langue/langue_tool.dart';
2023-07-10 17:50:31 +08:00
class TitleAppBar extends AppBar {
@override
2023-07-15 15:11:28 +08:00
final Color? backgroundColor;
final String? barTitle;
final Color? titleColor;
final Color? iconColor;
final bool? haveTitleWidget;
final Widget? titleWidget;
final bool? haveBack;
2023-09-07 18:36:16 +08:00
final Function? backAction;
2023-07-15 15:11:28 +08:00
final bool? haveOtherLeftWidget;
final Widget? leftWidget;
List<Widget>? actionsList;
final double? leadingWidth;
2023-07-10 17:50:31 +08:00
TitleAppBar(
{Key? key,
this.barTitle,
this.titleColor,
this.haveTitleWidget = false,
this.titleWidget,
this.iconColor,
this.backgroundColor,
this.actionsList,
this.haveBack,
2023-09-07 18:36:16 +08:00
this.backAction,
this.haveOtherLeftWidget = false,
this.leadingWidth,
this.leftWidget})
: super(key: key);
2023-07-10 17:50:31 +08:00
@override
_TitleAppBarState createState() => _TitleAppBarState();
}
class _TitleAppBarState extends State<TitleAppBar> {
@override
Widget build(BuildContext context) {
2024-11-21 18:11:11 +08:00
bool isRTL =
LanguageTool.instance.isArabic || LanguageTool.instance.isHebrew;
2023-07-10 17:50:31 +08:00
return AppBar(
elevation: 0,
leadingWidth: widget.leadingWidth,
leading: widget.haveOtherLeftWidget!
? widget.leftWidget
2024-04-28 18:26:31 +08:00
: (widget.haveBack ?? false
? IconButton(
2024-11-21 18:11:11 +08:00
icon: Icon(
isRTL ? Icons.arrow_forward_ios : Icons.arrow_back_ios,
2024-04-29 14:30:36 +08:00
color: widget.iconColor ?? Colors.white),
2024-01-02 18:03:50 +08:00
onPressed: () {
if (widget.backAction != null) {
widget.backAction!();
} else {
2024-04-28 18:26:31 +08:00
if (EasyLoading.isShow) {
2024-01-02 18:03:50 +08:00
EasyLoading.dismiss();
}
Navigator.pop(context);
}
2024-04-28 18:26:31 +08:00
})
: Container()),
2024-04-29 14:30:36 +08:00
backgroundColor: widget.backgroundColor ?? Colors.white,
title: widget.haveTitleWidget!
? widget.titleWidget
: Text(widget.barTitle ?? '',
2024-11-20 10:04:55 +08:00
// '发生的发生的发生的发生大发三大发手打',
maxLines: 3,
textAlign: TextAlign.center,
style: TextStyle(
2024-04-29 14:30:36 +08:00
color: widget.titleColor ?? Colors.white,
2024-11-20 10:04:55 +08:00
fontSize: 26.sp,
fontWeight: FontWeight.w500)),
centerTitle: true,
actions: widget.actionsList ?? []);
2023-07-10 17:50:31 +08:00
}
}