dart - Rounded bottom on appbar

Dart - Rounded bottom on appbar

To create a rounded bottom for an AppBar in Flutter, you'll need to use a combination of custom shapes and decorations, as the AppBar widget itself doesn't support rounded corners directly. Here's a step-by-step guide to achieving a rounded bottom effect on an AppBar:

1. Using a ClipPath with a Custom Clipper

You can use a ClipPath with a custom Clipper to achieve rounded corners on the bottom of the AppBar.

Example

import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: MyHomePage(), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: CustomScrollView( slivers: <Widget>[ SliverAppBar( expandedHeight: 200.0, flexibleSpace: ClipPath( clipper: BottomRoundedClipper(), child: Container( color: Colors.blue, child: Center( child: Text( 'Custom AppBar', style: TextStyle(color: Colors.white, fontSize: 20), ), ), ), ), pinned: true, ), SliverList( delegate: SliverChildBuilderDelegate( (context, index) => ListTile( title: Text('Item #$index'), ), childCount: 100, ), ), ], ), ); } } class BottomRoundedClipper extends CustomClipper<Path> { @override Path getClip(Size size) { final path = Path(); path.lineTo(0, size.height - 30); path.quadraticBezierTo( size.width / 2, size.height, size.width, size.height - 30); path.lineTo(size.width, 0); path.close(); return path; } @override bool shouldReclip(CustomClipper<Path> oldClipper) => false; } 

2. Using a Container with BoxDecoration

Alternatively, you can use a Container with BoxDecoration to create a rounded bottom effect and place it behind a PreferredSize AppBar.

Example

import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: MyHomePage(), ); } } class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Container( width: double.infinity, height: 150, decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.vertical( bottom: Radius.circular(30), ), ), child: Center( child: Text( 'Custom AppBar', style: TextStyle(color: Colors.white, fontSize: 20), ), ), ), Expanded( child: ListView.builder( itemCount: 100, itemBuilder: (context, index) => ListTile( title: Text('Item #$index'), ), ), ), ], ), ); } } 

Summary

  • Custom Clipper: Use ClipPath with a custom CustomClipper to round the bottom corners of the AppBar.
  • Container with Decoration: Use a Container with a BoxDecoration to create a rounded bottom effect and position it above your ListView or other content.

Choose the method that best fits your layout and design requirements.

Examples

  1. "Dart - How to create an AppBar with rounded bottom corners in Flutter?"

    Description: Creates an AppBar with rounded bottom corners using custom decoration and clip path.

    Code:

    import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; class RoundedAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: ClipPath( clipper: RoundedBottomClipper(), child: Container( color: Colors.blue, child: AppBar( title: Text('Rounded Bottom AppBar'), backgroundColor: Colors.transparent, // Transparent to show the rounded corners elevation: 0, // Remove the default shadow ), ), ), ), body: Center(child: Text('Content goes here')), ); } } class RoundedBottomClipper extends CustomClipper<Path> { @override Path getClip(Size size) { final path = Path(); path.lineTo(0, size.height - 30); path.quadraticBezierTo(size.width / 2, size.height, size.width, size.height - 30); path.lineTo(size.width, 0); path.close(); return path; } @override bool shouldReclip(CustomClipper<Path> oldClipper) => false; } void main() => runApp(MaterialApp(home: RoundedAppBar())); 
  2. "Dart - Adding a rounded bottom to AppBar with a CustomContainer"

    Description: Uses a Container with rounded corners at the bottom to create a custom AppBar.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), ), child: AppBar( title: Text('Custom Rounded AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  3. "Dart - Flutter AppBar with bottom border radius using ClipRRect"

    Description: Applies a border radius to the bottom of an AppBar using ClipRRect.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: ClipRRect( borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), child: AppBar( title: Text('ClipRRect AppBar'), backgroundColor: Colors.blue, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  4. "Dart - Create a curved AppBar with a BottomShape using CustomPaint"

    Description: Creates a custom AppBar with a curved bottom using CustomPaint and CustomPainter.

    Code:

    import 'package:flutter/material.dart'; class CurvedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: CustomPaint( painter: AppBarPainter(), child: AppBar( title: Text('Curved Bottom AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } class AppBarPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { final paint = Paint() ..color = Colors.blue ..style = PaintingStyle.fill; final path = Path() ..lineTo(0, size.height - 30) ..quadraticBezierTo(size.width / 2, size.height, size.width, size.height - 30) ..lineTo(size.width, 0) ..close(); canvas.drawPath(path, paint); } @override bool shouldRepaint(CustomPainter oldDelegate) => false; } void main() => runApp(MaterialApp(home: CurvedBottomAppBar())); 
  5. "Dart - Rounded bottom corners on AppBar using ShapeDecoration"

    Description: Uses ShapeDecoration to apply rounded bottom corners to an AppBar.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: ShapeDecoration( color: Colors.blue, shape: RoundedRectangleBorder( borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), ), ), child: AppBar( title: Text('ShapeDecoration AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  6. "Dart - AppBar with rounded bottom using Container with BoxDecoration"

    Description: Applies a rounded bottom to the AppBar using BoxDecoration inside a Container.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), ), child: AppBar( title: Text('BoxDecoration AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  7. "Dart - Custom AppBar with bottom radius using ClipPath and CustomClipper"

    Description: Utilizes ClipPath and CustomClipper to create a custom AppBar with a rounded bottom.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: ClipPath( clipper: BottomRoundedClipper(), child: Container( color: Colors.blue, child: AppBar( title: Text('CustomClipper AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), ), body: Center(child: Text('Content goes here')), ); } } class BottomRoundedClipper extends CustomClipper<Path> { @override Path getClip(Size size) { final path = Path(); path.lineTo(0, size.height - 30); path.quadraticBezierTo(size.width / 2, size.height, size.width, size.height - 30); path.lineTo(size.width, 0); path.close(); return path; } @override bool shouldReclip(CustomClipper<Path> oldClipper) => false; } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  8. "Dart - Flutter AppBar with rounded bottom and elevation"

    Description: Adds a rounded bottom to the AppBar while maintaining some elevation for visual effects.

    Code:

    import 'package:flutter/material.dart'; class RoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), ), child: AppBar( title: Text('Elevated Rounded AppBar'), backgroundColor: Colors.blue, elevation: 4, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: RoundedBottomAppBar())); 
  9. "Dart - Rounded bottom AppBar with gradient background"

    Description: Creates an AppBar with a gradient background and rounded bottom corners.

    Code:

    import 'package:flutter/material.dart'; class GradientBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.blue, Colors.purple], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), ), child: AppBar( title: Text('Gradient AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: GradientBottomAppBar())); 
  10. "Dart - AppBar with rounded bottom corners and shadow effect"

    Description: Adds a shadow effect to the AppBar with rounded bottom corners.

    Code:

    import 'package:flutter/material.dart'; class ShadowRoundedBottomAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: Container( decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.vertical(bottom: Radius.circular(30)), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.2), spreadRadius: 5, blurRadius: 7, offset: Offset(0, 3), // changes position of shadow ), ], ), child: AppBar( title: Text('Shadow AppBar'), backgroundColor: Colors.transparent, elevation: 0, ), ), ), body: Center(child: Text('Content goes here')), ); } } void main() => runApp(MaterialApp(home: ShadowRoundedBottomAppBar())); 

More Tags

arguments odbc date-conversion osx-yosemite ngx-translate roi sim-card php-extension gitpython vectormath

More Programming Questions

More Organic chemistry Calculators

More Electronics Circuits Calculators

More Other animals Calculators

More Tax and Salary Calculators