when ever I open my Reorders page, my app bar title is not center because of the back button so I'm wondering how can I make the app bar to always center like so that it will be the same with other screens.
Any Help or suggestion will be really appreciated.
appBar: AppBar(
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Maxis",
style:
TextStyle(fontFamily: "Raleway", fontWeight: FontWeight.w300),
),
Image.asset(
"assets/images/maxis.png",
width: 30,
),
Text(
"Mobile",
style:
TextStyle(fontFamily: "Raleway", fontWeight: FontWeight.w300),
),
],
),
),
mainAxisSize: MainAxisSize.min,
You need this inside your Row widget and it'll be centered perfectly.
Related
The Problem
I have a card that contains a row of two elements, the second one being a column of two texts. One of the texts can be long, so the column-element itself can overflow.
Coming from CSS, a "width: 100%" would usually be enough here.
What I already tried
I learned you could wrap the column with something like Expanded or Flexible, but it leads the text to become invisible (and the overflow still existing).
I am not sure where exactly I have to put the Flexible/Expanded.
I looked into similar questions and there was always an "Expanded", but I could not apply any of said solutions to my layout so far.
Question
What is the cleanest way to get the outlined box to be only as wide as the padding should allow?
Code
#override
Widget build(BuildContext context) {
return (Card(
child: InkWell(
onTap: () {
print("tab" + name);
},
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(25),
child: SizedBox(
width: 50,
height: 50,
child: Image(
image: NetworkImage(imageUrl),
),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 1, color: Colors.purpleAccent),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.left,
),
Text(
description,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.left,
),
],
),
),
),
],
),
),
),
));
}
You can surround the Padding widget inside your Row with an Expanded widget - The child of Expanded will then size itself to the space available.
For some additional context, Rows and Columns are both Flex widgets. Flex widgets layout their children along an axis, and the size of this axis is unbounded by default. Even though the widget "knows" how much space it has available on the display, it doesn't pass that information along to its children, so the children are free to take whatever size they want, which means they can potentially overflow the container.
An Expanded widget can only be placed as a direct child of a Flex widget, and it automatically takes up a given proportion (given by the flex property) of the space available to it (by default that will simply be all of the space which is not taken up by other widgets in the children list).
So essentially, Expanded will take up as much space as the parent widget has available, and then will constrain it's child to be no larger than that (along whichever axis pertains).
The link above to the Flex documentation has more info.
Column widget is showing extra space between consecutive widgets even when using simple containers with their padding set to 0. I have tried using SizedBox, setting mainAxisSize to min but nothing seems to be working.
Moreover this issue is only appearing in Android OS and not on Web or iOS.
My Code:
Scaffold(
backgroundColor: Colors.yellow,
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.zero,
height: 50,
color: Colors.black,
),
Container(
padding: EdgeInsets.zero,
height: 100,
color: Colors.black,
),
SizedBox(
height: 20,
),
Container(
height: 150,
color: Colors.black,
)
],
),
),
)
Output:
I have zoomed the image a bit to on the right to display the gap better. There is a line of space appearing between the 2 containers. I have placed another container of 150 height below the column to show the difference between complete opaque and space. I have recreated this same behaviour on Pixel 3 Emulator as well as OnePlus 6T device.
Can anybody help me with a fix to this. I know this can be solved using Stack and Positioned but I was hoping to find out if this is an issue in Flutter SDK or a fixable widget behaviour.
That's a pretty annoying effect indeed. And though I can't tell you why this is happening, playing around with it a bit, it seems that giving the Container a BoxDecoration with a Border instead of a color removes the artifacts:
Scaffold(
backgroundColor: Colors.yellow,
appBar: AppBar(
title: Text('title'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
padding: EdgeInsets.zero,
height: 51,
//color: Colors.black,
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
padding: EdgeInsets.zero,
height: 100,
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
color: Colors.black,
),
height: 150,
//color: Colors.black,
)
],
),
),
)
For me answer didn't work (probably because i had clipPath over container but i found similar solution)
decoration: BoxDecoration(
border: Border.all(width: 0, color: Colors.yourColor),
color: Colors.yourColor,
),
In all containers at your column
I am new to flutter and creating a project where the design contains rounded top navigation. In flutter we have tab bars. So I searched around but could not find the solution. There were solution for rounded tabs but not the tab bar as whole. Is it even possible or is there a work around it.
You can create custom tab bar using Container and Stack to positioned Container on top.
Something like this.
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Stack(
children: <Widget>[
Positioned(
top: 0,
child: Container(
width: MediaQuery.of(context).size.width,
height: 80,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(25.0))
),
child: Row(
children: <Widget>[
//icons buttons
],
),
),
)
],
)
),
I have implemented a bottom app bar in a flutter app, but the height in both the devices are different and even the margin also.
main.dart
bottomNavigationBar: BottomAppBar(
color: Colors.black,
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.fiber_manual_record,
color: Colors.white,
),
),
),
Currently the only way I could make this kind of curved effect would be through making 2 container, making 1 a child of another and making 1 container's colour into the background colour.
However I cannot replicate this effect if the background is an image. Could anyone assist?
Example of the code I use:
Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
Container(
height: 100,
color: Color(0xFF0D6068),
),
Expanded(
child: Container(
color: Color(0xFF0D6068),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(50),
topRight: Radius.circular(50),
)),
),
))
],
)),
);
You can make use of a Stack widget to achieve this, such that the background color or image would be at the back then the curved container would be stacked on it. Here is an example code.
Stack(children <Widget> [
Image.asset(''),
Container()
]
)
Instead of using an image asset, you can make use of BoxDecoration with the decoration parameter of a container. The BoxDecoration has an image parameter where you can provide your image with a DecorationImage() widget.