Flutter 3.x+Live previewCopy-paste Dart

Flutter Curved AppBar

A curved bottom edge is a single quadratic Bezier. Set the curve depth and choose whether it bulges down (convex) or scoops up (concave), then copy the code. Pass the ShapeBorder as the shape of an AppBar, or use ClipPath for a header you build yourself.

Curve
Flutter ShapeBorder Code
import 'dart:math' as math;
import 'package:flutter/material.dart';

// A bulging (convex) bottom edge, drawn with one quadratic Bezier.
Path curvedAppBarPath(Rect r) {
  const depth = 32.0;
  final d = math.min(depth, r.height / 2);
  return Path()
    ..moveTo(r.left, r.top)
    ..lineTo(r.right, r.top)
    ..lineTo(r.right, r.bottom - d)
    ..quadraticBezierTo(r.center.dx, r.bottom + d, r.left, r.bottom - d)
    ..close();
}

class CurvedAppBarBorder extends ShapeBorder {
  const CurvedAppBarBorder({this.side = BorderSide.none});

  final BorderSide side;

  @override
  EdgeInsetsGeometry get dimensions => EdgeInsets.all(side.width);

  @override
  Path getInnerPath(Rect rect, {TextDirection? textDirection}) =>
      curvedAppBarPath(rect.deflate(side.width));

  @override
  Path getOuterPath(Rect rect, {TextDirection? textDirection}) =>
      curvedAppBarPath(rect);

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {
    if (side.style == BorderStyle.none) return;
    canvas.drawPath(curvedAppBarPath(rect.deflate(side.width / 2)), side.toPaint());
  }

  @override
  ShapeBorder scale(double t) => CurvedAppBarBorder(side: side.scale(t));
}

// Usage:
// Container(
//   decoration: const ShapeDecoration(
//     color: Colors.indigo,
//     shape: CurvedAppBarBorder(),
//   ),
//   child: const SizedBox(width: 160, height: 160),
// )
// Card(shape: const CurvedAppBarBorder(), child: ...)

When to use ClipPath vs ShapeBorder for this shape

Use the ShapeBorder for an AppBar or SliverAppBar: AppBar(shape: const CurvedAppBarBorder(), ...). The elevation shadow follows the curve.

Use ClipPath when the curved header is a plain Container or an image behind other content and you do not need a shadow.

Common mistakes

  • A convex curve drawn past the bottom of the rect. In the code above the curve touches the bottom edge exactly at the middle and the sides sit depth higher, so nothing is cut off.
  • Content hidden by the curve. Add bottom padding equal to the curve depth under any text or buttons at the bottom of the bar.
  • A fixed pixel depth on very different screen widths. The curve gets flatter or steeper as the width changes; use a fraction of the width if the look must stay constant.
  • Setting toolbarHeight smaller than the curve. The curve is clamped to half the rect height, so a very short bar shows a shallower curve than you asked for.

FAQ

How do I make a curved AppBar in Flutter?

Pass a custom ShapeBorder as the shape of AppBar or SliverAppBar. The ShapeBorder tab above gives you one whose getOuterPath draws the curved bottom edge, and the app bar shadow follows it.

What is the difference between convex and concave here?

Convex bulges down, so the middle of the bar is the lowest point. Concave scoops up, so the middle is raised and the corners hang lower. The Curve option switches between them.

Can I use ClipPath for the app bar instead?

You can clip a header you build yourself, but a clipped widget loses its shadow. For AppBar, the shape property with a ShapeBorder is the better fit.

Related