app-starlock/lib/tools/titleAppBar.dart

86 lines
2.8 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/flavors.dart';
import 'package:star_lock/tools/langue/langue_tool.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;
final double? leadingWidth;
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.leadingWidth,
this.leftWidget})
: super(key: key);
@override
_TitleAppBarState createState() => _TitleAppBarState();
}
class _TitleAppBarState extends State<TitleAppBar> {
@override
Widget build(BuildContext context) {
bool isRTL =
LanguageTool.instance.isArabic || LanguageTool.instance.isHebrew;
return AppBar(
elevation: 0,
leadingWidth: widget.leadingWidth,
leading: widget.haveOtherLeftWidget!
? widget.leftWidget
: (widget.haveBack ?? false
? IconButton(
icon: Icon(
isRTL ? Icons.arrow_forward_ios : Icons.arrow_back_ios,
color: widget.iconColor ?? Colors.white),
onPressed: () {
if (widget.backAction != null) {
widget.backAction!();
} else {
if (EasyLoading.isShow) {
EasyLoading.dismiss();
}
Navigator.pop(context);
FocusScope.of(context).unfocus(); // 收起键盘
}
})
: Container()),
backgroundColor: widget.backgroundColor ?? Colors.white,
title: widget.haveTitleWidget!
? widget.titleWidget
: Text(widget.barTitle ?? '',
// '发生的发生的发生的发生大发三大发手打',
maxLines: 3,
textAlign: TextAlign.center,
style: TextStyle(
color: widget.titleColor ?? Colors.white,
fontSize: 26.sp,
fontWeight: FontWeight.w500)),
centerTitle: true,
actions: widget.actionsList ?? []);
}
}