Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do I make custom app bar like this in flutter?

Anyone knows how to make appbar that has the bottom third of a circle attached to the bottom? Horizontal bar with a semi-circle attached to the bottom on the left. A circular photo sits inside the semi-circle.

This it what I am able to get: The bottom of the appbar curves down into the semi-circle rather than being straight until it reaches that shape. The bottom of the semi-circle is a bit flat so it's more like an oval than a perfect circle.

This is my code. The image of the person is not the problem the padding at the left and right side and the rounded left bottom and right bottom are the problems . I am not able to achieve those.


class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      shape: CustomShapeBorder(),
    );
  }

  @override
  // TODO: implement preferredSiz
  Size get preferredSize => Size.fromHeight(40);
}

class CustomShapeBorder extends ContinuousRectangleBorder {
  @override
  Path getOuterPath(Rect rect, {TextDirection textDirection}) {
    double x = 150, y = 45, r = 0.5;
    Path path = Path()
      ..addRRect(RRect.fromRectAndCorners(rect))
      ..moveTo(rect.bottomRight.dx - 30, rect.bottomCenter.dy)
      ..relativeQuadraticBezierTo(
          ((-x / 2) + (x / 6)) * (1 - r), 0, -x / 2 * r, y * r)
      ..relativeQuadraticBezierTo(
          -x / 6 * r, y * (1 - r), -x / 2 * (1 - r), y * (1 - r))
      ..relativeQuadraticBezierTo(
          ((-x / 2) + (x / 6)) * (1 - r), 0, -x / 2 * (1 - r), -y * (1 - r))
      ..relativeQuadraticBezierTo(-x / 6 * r, -y * r, -x / 2 * r, -y * r);
    path.close();
    return path;
  }
}
like image 580
Mee Avatar asked Oct 29 '25 15:10

Mee


2 Answers

output

  import 'package:flutter/cupertino.dart';
    import 'package:flutter/material.dart';
    class page extends StatefulWidget {
    @override
    _pageState createState() => _pageState();
    }

    class _pageState extends State<page> {
    @override
    Widget build(BuildContext context) {
    return Scaffold(

        appBar: AppBar(elevation:0,backgroundColor:Colors.purple,title: Row(mainAxisAlignment: MainAxisAlignment.end,children: <Widget>[
          IconButton(onPressed:(){},icon: Icon(Icons.settings,),color: Colors.white,)


        ],),),body: SingleChildScrollView(child: Column(children: <Widget>[

      Stack(children: <Widget>[

        
    Container(color:Colors.purple,width:MediaQuery.of(context).size.width,height:
        MediaQuery.of(context).size.height/5,
       ), Row(mainAxisAlignment:MainAxisAlignment.spaceBetween,children: <Widget>[
      Padding(padding:EdgeInsets.only( ),child:
    Container(width:130,decoration:BoxDecoration(border:Border.all(color: 
     Colors.white),color:Colors.purple,shape:BoxShape.circle),
    child:CircleAvatar(backgroundColor:Colors.purple,child: 
    [![enter image description here][1]][1]Image.asset("assets/yourimg.png",height: 100,),radius: 70,),)
        ),Column(children: <Widget>[
            Text("Ahmed-AlKheerow",style: TextStyle(fontSize: 20,fontWeight:
            FontWeight.bold),),
            Text("ID:93956")

          ],) ])

      ])])));}}

use Navigator.pushReplacement to disable the back button

like image 98
Biruk Telelew Avatar answered Nov 01 '25 13:11

Biruk Telelew


Instead of using

..addRRect(RRect.fromRectAndCorners(rect))

use

..addRRect(RRect.fromLTRBAndCorners(
          10, 24, rect.bottomRight.dx - 10, rect.bottomRight.dy,
          bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10))
like image 27
Rasul Aliyev Avatar answered Nov 01 '25 13:11

Rasul Aliyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!