Test
Test

Reputation: 23

Custom Rounded appbar in flutter

Screenshot of Customise Appbar :

enter image description here

I want to make a Custom app bar like in the photo Can anybody help me in creating this i had searched a lot but not found anywhere

Upvotes: 2

Views: 2082

Answers (2)

Ashesh Shrestha
Ashesh Shrestha

Reputation: 388

I don't think it is a rounded appBar but a rounded container below it.

I have added backgroundColor in the Scaffold which matches with the background color of AppBar. Also, I have set the elevation of AppBar to 0 to prevent shadow.

enter image description here

import 'package:flutter/material.dart';

class TempMyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test App',
      home: Scaffold(
        backgroundColor: Colors.indigo.shade800,
        appBar: AppBar(
          title: Text(
            'Test App',
          ),
          elevation: 0,
          backgroundColor: Colors.indigo.shade800,
        ),
        body: Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(60),
              topRight: Radius.circular(60),
            ),
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}

Upvotes: 6

Saiful Islam Adar
Saiful Islam Adar

Reputation: 221

The trick is to not curve the appbar but curve the bottom container instead. Have a look at the code below and you will understand it.

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final key = GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFF012B44),
      key: key,
      appBar: AppBar(
        title: Text("OTP Verification"),
        backgroundColor: Colors.transparent,
      ),
      body: SingleChildScrollView(
        child: Container(
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(15),
              topRight: Radius.circular(15),
            )
          ),
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(
                "Welcome to the login page",
                style: Theme.of(context).textTheme.display1,
              ),
              TextField(
                decoration: InputDecoration(hintText: "Name"),
              ),
              FlatButton(
                  onPressed: () {
                    key.currentState.showSnackBar(SnackBar(
                      content:
                          Text("I won't say your name but stay home, stay safe!"),
                    ));
                  },
                  child: Text("Say my name"))
            ],
          ),
        ),
      ),
    );
  }
}

Upvotes: 1

Related Questions