Translate-Flutter/lib/widget/t_base_appbar_widget.dart
xuhang-x 4bccb583d6 1
2024-07-25 11:51:23 +08:00

91 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:trans_lark/generated/assets.dart';
class TBaseAppbarWidget extends StatelessWidget implements PreferredSizeWidget {
const TBaseAppbarWidget({
super.key,
this.backgroundColor,
this.backColor,
this.title,
this.titleWidget,
this.actionWidget,
this.onBackTap,
});
final Color? backgroundColor;
final Color? backColor;
final String? title;
final Widget? titleWidget;
final Widget? actionWidget;
final Function()? onBackTap;
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: backgroundColor ?? Colors.white,
surfaceTintColor: Colors.transparent,
automaticallyImplyLeading: false,
centerTitle: false,
title: _buildTitle(context),
titleSpacing: 0.0,
leadingWidth: 0.0,
);
}
Widget _buildTitle(BuildContext context) {
return SizedBox(
height: preferredSize.height,
child: Row(
children: [
SizedBox(
width: 60,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: FittedBox(
fit: BoxFit.none,
child: ClipOval(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onBackTap ?? Get.back,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Image.asset(
Assets.imagesBackIcon,
width: 24,
height: 24,
color: backColor,
),
),
),
),
),
),
),
),
Expanded(
child: titleWidget ??
Text(
title ?? '',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
SizedBox(
width: 60,
child: actionWidget,
),
],
),
);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}