Custom AppBar in Flutter

In Flutter, you can use a custom AppBar by defining a new class that extends the built-in AppBar class. Here's an example of how to create a custom AppBar in Flutter:

import 'package:flutter/material.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final Color backgroundColor;
  final List<Widget> actions;
  CustomAppBar({required this.title, required this.backgroundColor, required this.actions});
  @override
  Widget build(BuildContext context) {
    return AppBar(
      title: Text(title),
      backgroundColor: backgroundColor,
      actions: actions,
    );
  }
  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight);
}

In this example we create a new class CustomAppBar which extends AppBar and implements PreferredSizeWidget. I also define some custom properties like title, backgroundColor, and actions which can be passed in when creating a new instance of the custom AppBar.

To use this custom AppBar in your Flutter app, you just need to create a new instance of the class CustomAppBar and pass in the required properties. Here is an example:

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/130089443