import 'package:chicken_farm/routes/app_routes.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class VberAppBar extends StatelessWidget implements PreferredSizeWidget { final String title; final bool showLeftButton; final List? actions; final VoidCallback? onLeftPressed; final bool alwaysGoToHome; const VberAppBar({ super.key, required this.title, this.showLeftButton = true, this.actions, this.onLeftPressed, this.alwaysGoToHome = false, }); @override Widget build(BuildContext context) { return AppBar( title: Text(title), centerTitle: true, leading: showLeftButton ? IconButton( icon: Icon(alwaysGoToHome ? Icons.home : Icons.arrow_back), onPressed: () { if (onLeftPressed != null) { onLeftPressed!(); } else if (alwaysGoToHome) { context.go(AppRouteNames.home); } else if (context.canPop()) { // 如果可以返回,则返回上一页 context.pop(); } else { context.go(AppRouteNames.home); } }, ) : null, actions: actions, ); } @override Size get preferredSize => const Size.fromHeight(kToolbarHeight); }