Skip to content

Instantly share code, notes, and snippets.

@ansarizafar
Forked from mjohnsullivan/curved_appbar.dart
Created November 29, 2019 02:35
Show Gist options
  • Save ansarizafar/29333e754f22cada2dcb3ae172e06b02 to your computer and use it in GitHub Desktop.
Save ansarizafar/29333e754f22cada2dcb3ae172e06b02 to your computer and use it in GitHub Desktop.
A curved Flutter AppBar where widgets scroll nicely beneath the curved portion
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(home: MyHomePage()),
);
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
const curveHeight = 50.0;
return Scaffold(
appBar: AppBar(
shape: const MyShapeBorder(curveHeight),
),
body: ListView(
padding: const EdgeInsets.only(top: curveHeight),
children: List.generate(
100,
(i) => Text('This is item $i in this list'),
),
),
);
}
}
class MyShapeBorder extends ContinuousRectangleBorder {
const MyShapeBorder(this.curveHeight);
final double curveHeight;
@override
Path getOuterPath(Rect rect, {TextDirection textDirection}) => Path()
..lineTo(0, rect.size.height)
..quadraticBezierTo(
rect.size.width / 2,
rect.size.height + curveHeight * 2,
rect.size.width,
rect.size.height,
)
..lineTo(rect.size.width, 0)
..close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment