I'm trying to improve myself to write better quality code. However, I have a question. For example, does it make sense to create an appbar class like the one below and call that code where I need it? Will it benefit me? Does it provide a performance advantage? Or should I call and use the appbar widget wherever I want instead?
import 'package:flutter/material.dart';
class MyAppBar extends StatelessWidget with PreferredSizeWidget {
final Widget? leading;
final Widget? title;
final List<Widget>? actions;
final bool? centerTitle;
final PreferredSizeWidget? bottom;
final Color? backgroundColor;
final TextStyle? titleTextStyle;
const MyAppBar(
{super.key,
this.leading,
this.title,
this.actions,
this.centerTitle,
this.bottom,
this.backgroundColor,
this.titleTextStyle});
@override
AppBar build(BuildContext context) {
return AppBar(
leading: leading,
title: title,
actions: actions,
centerTitle: centerTitle,
bottom: bottom,
backgroundColor: backgroundColor,
titleTextStyle: titleTextStyle);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
PreferredSizeWidgetwhen you need custom appBar.