5

In my application, the flutter app is adding space between appbar and the body of the screen. Following is the image of the screen: enter image description here

Following is the code:

Widget build(BuildContext context) { // TODO: implement build return Scaffold( appBar: AppBar( automaticallyImplyLeading: true, title: Container( height: MediaQuery.of(context).size.width * 0.13, child: Text('Dashboard')), centerTitle: true, backgroundColor: kBluePrimaryColor, elevation: 0, ), body: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( height: MediaQuery.of(context).size.height * 0.33, child: Stack(children: [ Container( //color: kBluePrimaryColor, width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height * 0.23, child: bannerimage == '' || bannerimage == null ? Image.asset('images/user.jpg') : Image.network( bannerimage), ), Positioned( top: MediaQuery.of(context).size.height * 0.16, left: MediaQuery.of(context).size.width * 0.03, child: Row( children: [ Container( width: MediaQuery.of(context).size.height * 0.14, height: MediaQuery.of(context).size.height * 0.14, decoration: ShapeDecoration( shape: CircleBorder(), color: Colors.white), child: Padding( padding: EdgeInsets.all(8.0), child: DecoratedBox( decoration: ShapeDecoration( shape: CircleBorder(), image: DecorationImage( fit: BoxFit.cover, image: imageurl == '' || imageurl == null ? AssetImage('images/user.jpg') : NetworkImage(imageurl), )), ), ), ), SizedBox( width: MediaQuery.of(context).size.width * 0.05, ), ], ), ), Positioned( top: MediaQuery.of(context).size.height * 0.24, left: MediaQuery.of(context).size.height * 0.165, child: Container( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ RaisedButton( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30.0), ), color: kOrangePrimaryColor, onPressed: () { print('Contacts'); }, child: RichText( text: TextSpan( text: 'Total: ', style: TextStyle(color: Colors.white, fontSize: 12), children: <TextSpan>[ TextSpan( text: '30', style: TextStyle( color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold, fontFamily: 'Calibri')), ], ), )), SizedBox( width: 13, ), RaisedButton( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30.0), ), color: kBluePrimaryColor, onPressed: () { print('Address'); }, child: RichText( text: TextSpan( text: 'ADDRESS', style: TextStyle( color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold, fontFamily: 'Calibri')), )) ], )), ), ]), ), ], ), ), ); } 

I tried the various answers given but it wasn't working.

I want to remove the white space between the blue appbar and the image. Can someone help me with this please?

3
  • 1
    I think it is because of the image fit, make your image fit to cover, Image.asset(bannerimage,fit: BoxFit.cover,) Commented Apr 7, 2021 at 13:30
  • @karzankamal Thank you so much..it solve the problem Commented Apr 7, 2021 at 13:36
  • Don't mention it. Commented Apr 7, 2021 at 13:40

5 Answers 5

3

I think it is because the banner image is not filling the container Try adding fit: BoxFit.cover to the image

Sign up to request clarification or add additional context in comments.

Comments

3

I know I'm late but in case somebody needs this in the future here's the solution.

In the Scaffold widget set the property "extendBodyBehindAppBar" to "true"...

Comments

1

Add a toolbar height to appbar and scrollview to body:

Scaffold( appBar: AppBar( toolbarHeight: 40, ..... ), body: SingleChildScrollView(... 

Comments

0

You just need to wrap the Column(Which is inside SingleChildScrollView) with Container and give its height and width.

body: SingleChildScrollView( child: Container( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, child: Column( ... ) ) ) 

2 Comments

I tried what you said, but the space is still there.
@Ankit, I think you might be using an older version of Flutter. Try running flutter upgrade, if it still doesn't run change the channel of flutter to beta or master flutter channel beta or flutter channel master.
0

Make sure to set the elevation to 0 in the AppBar

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.