Short answer
Wrap the widget in PreferredSize with a height: appBar: PreferredSize(preferredSize: const Size.fromHeight(64), child: MyAppBar()). For a reusable custom app bar, have the class implement PreferredSizeWidget and return its size from preferredSize.
Why Scaffold rejects the widget, and the fix
01
A plain widget passed to appBar
“Parents like Scaffold use PreferredSizeWidget to require that their children implement that interface.” Flutter, PreferredSize class
Wrap it in PreferredSize. The height you give is what Scaffold reserves at the top of the screen. PreferredSize adds no status bar padding, so wrap your bar’s content in SafeArea.
Scaffold( appBar: PreferredSize( preferredSize: const Size.fromHeight(64), child: MyGradientBar(title: title), ), body: body, )02
A reusable custom app bar class
Implement PreferredSizeWidget on the widget itself, so every screen can pass it straight to appBar.
class MyAppBar extends StatelessWidget implements PreferredSizeWidget { const MyAppBar({super.key, required this.title}); final String title; @override Size get preferredSize => const Size.fromHeight(kToolbarHeight); @override Widget build(BuildContext context) => AppBar(title: Text(title)); }03
The same rule in AppBar.bottom
AppBar(bottom: …) also takes a PreferredSizeWidget. A TabBar works as is; anything else, such as a search field, needs PreferredSize too.
AppBar( bottom: PreferredSize( preferredSize: const Size.fromHeight(56), child: Padding( padding: const EdgeInsets.all(8), child: SearchField(onChanged: onSearch), ), ), )
Checked against the vendor’s docs on : Flutter API: Scaffold.appBar; Flutter API: PreferredSize.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Flutter “A RenderFlex overflowed” · Flutter “Invalid constant value” · Flutter “No MediaQuery widget found” · Flutter “The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’”