0

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);
}
2
  • I would say implement PreferredSizeWidget when you need custom appBar. Commented Dec 18, 2022 at 17:22
  • Thanks but i already did that. What I want to ask is, would it be advantageous for me to do as above? Commented Dec 19, 2022 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.