Appbarを共通化しようとしたらエラー発生

こんな感じで実装してエラー回避しましたー

import 'package:flutter/material.dart';

class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
  CustomAppBar(this.title);
  
  final String title;

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);

  @override
  Widget build(BuildContext context) {
    return AppBar(
      title: Text(title),
      leading: GestureDetector(
        onTap: () {
          /* Write listener code here */
        },
        child: const Icon(
          Icons.menu, // add custom icons also
        ),
      ),
      actions: <Widget>[
        Padding(
            padding: const EdgeInsets.only(right: 20),
            child: GestureDetector(
              onTap: () {},
              child: const Icon(
                Icons.edit,
                size: 26,
              ),
            )),
        Padding(
            padding: const EdgeInsets.only(right: 20),
            child: GestureDetector(
              onTap: () {},
              child: const Icon(Icons.more_vert),
            )),
      ],
    );
  }
}

参考記事

The AppBarDesign can’t be assigned to the parameter type ‘PreferredSizeWidget’

コメントをどうぞ

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

CAPTCHA