creek

The AI Image Editor of 2030

lib/ui/widgets/app_bar.dart (1493B)


 1import 'package:flutter/material.dart';
 2import 'package:creekui/ui/styles/variables.dart';
 3
 4class CommonAppBar extends StatelessWidget implements PreferredSizeWidget {
 5  final String? title;
 6  final Widget? titleWidget;
 7  final bool showBack;
 8  final VoidCallback? onBack;
 9  final List<Widget>? actions;
10  final Widget? leading;
11  final double? leadingWidth;
12  final bool centerTitle;
13
14  const CommonAppBar({
15    super.key,
16    this.title,
17    this.titleWidget,
18    this.showBack = true,
19    this.onBack,
20    this.actions,
21    this.leading,
22    this.leadingWidth,
23    this.centerTitle = false,
24  });
25
26  @override
27  Widget build(BuildContext context) {
28    return AppBar(
29      title:
30          titleWidget ??
31          (title != null ? Text(title!, style: Variables.headerStyle) : null),
32      backgroundColor: Variables.background,
33      elevation: 0,
34      centerTitle: centerTitle,
35      leadingWidth: leadingWidth ?? (showBack ? 50 : 0),
36      titleSpacing: showBack ? 0 : 16,
37      automaticallyImplyLeading: false,
38      leading:
39          leading ??
40          (showBack
41              ? IconButton(
42                icon: const Icon(
43                  Icons.arrow_back,
44                  size: 20,
45                  color: Variables.textPrimary,
46                ),
47                onPressed: onBack ?? () => Navigator.pop(context),
48              )
49              : null),
50      actions: actions,
51    );
52  }
53
54  @override
55  Size get preferredSize => const Size.fromHeight(kToolbarHeight);
56}