generateCustomAppBar static method
Implementation
static String generateCustomAppBar() {
return '''
import 'package:flutter/material.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final String title;
final List<Widget>? actions;
final Widget? leading;
final bool centerTitle;
final double elevation;
final Color? backgroundColor;
final PreferredSizeWidget? bottom;
final bool showBackButton;
const CustomAppBar({
Key? key,
required this.title,
this.actions,
this.leading,
this.centerTitle = true,
this.elevation = 0,
this.backgroundColor,
this.bottom,
this.showBackButton = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AppBar(
title: Text(
title,
style: const TextStyle(
fontWeight: FontWeight.w700,
letterSpacing: 0.5,
),
),
centerTitle: centerTitle,
elevation: elevation,
backgroundColor: backgroundColor ?? theme.scaffoldBackgroundColor,
surfaceTintColor: Colors.transparent,
leading: leading ??
(showBackButton || Navigator.of(context).canPop()
? IconButton(
icon: const Icon(Icons.arrow_back_ios_new, size: 20),
onPressed: () => Navigator.of(context).pop(),
)
: null),
actions: actions,
bottom: bottom,
shape: elevation > 0
? Border(
bottom: BorderSide(
color: theme.colorScheme.outline.withOpacity(0.1),
),
)
: null,
);
}
@override
Size get preferredSize => Size.fromHeight(
kToolbarHeight + (bottom?.preferredSize.height ?? 0.0),
);
}
''';
}