ar_tourism_flutter_unity/lib/components/appbar.dart
2025-05-14 17:04:13 +08:00

45 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final String title;
final Widget? leading;
final List<Widget>? actions;
final bool showLeading; // 新增的参数,用于控制是否显示 leading
final VoidCallback? onBackPressed;
const CustomAppBar({
super.key,
required this.title,
this.leading,
this.actions,
this.showLeading = true, // 默认情况下显示 leading
this.onBackPressed,
});
@override
Widget build(BuildContext context) {
return AppBar(
automaticallyImplyLeading: showLeading, // 添加这个属性来控制是否自动显示返回按钮
leading: showLeading
? (leading ??
IconButton(
icon: Image.asset('images/arraw.png', width: 11, height: 22),
onPressed: () {
if (onBackPressed != null) {
onBackPressed!(); // 调用回调函数
} else {
Navigator.of(context).pop(); // 默认行为
}
},
))
: null, // 如果 showLeading 为 false则不显示 leading
title: Text(title),
actions: actions,
// toolbarHeight: 50,
);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}