Centering in the AppBar with the back button - flutter

I store in the title the text and icon that are displayed in the AppBar in the center. During the transition, the back button that appears takes up part of the line and my centering shifts. Can I somehow get around this and make the titled centered even if there is a back button ?
The bottom icon is located in the center of the screen
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(
color: Colors.grey
),
elevation: 0,
title: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.telegram_sharp, color: iconColor),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 2)),
Text('ID', style: TextStyle(color: Colors.black, fontSize: 18)),
],
))),
body: Padding(
padding: const EdgeInsets.all(20),
child: ListView(
children: [
_MainInfoWidget(),
],
),
),
);
}

You need to set the following properties on the Row():
MainAxisAlignment.center
MainAxisSize.min
And:
centerTitle: true
On the appBar().
Also, remove your Center() widget.
Complete example:
Scaffold(
appBar: AppBar(
centerTitle: true,
leading: BackButton(color: Colors.grey),
elevation: 0,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.telegram_sharp, color: Colors.black),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 2, vertical: 2)),
Text('ID', style: TextStyle(color: Colors.black, fontSize: 18)),
],
)),
body: Padding(
padding: const EdgeInsets.all(20),
child: Container(),
),
);
Result:

Try this
AppBar(
centerTitle: true
And
mainAxisSize: MainAxisSize.min
Or if that's not helped
When the transition occurs, change
mainAxiAlignment: MainAxisAlignment.start otherwise center

Related

Why won't the border radius change?

What am I doing wrong? I can't get the border radius of my card to change. The elevation isn't working either. I'm new at this. What do I need to change? Is it because it's in ListView? I'm confused. If you need for information, just ask. Sorry it wants me to write more... too much code?
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(85),
child: AppBar(
backgroundColor: Color(),
bottom: TabBar(
tabs: <Widget>[
Tab(icon: Icon(Icons.people), text: (''),),
Tab(icon: Icon(Icons.person), text: (''),),
Tab(icon: Icon(Icons.circle), text: (''),),
],
),
),
),
body: ListView(
children: <Widget>[
Card(
margin: EdgeInsets.all(10),
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
child: Container(
color: Colors.white,
height: 120,
child: Column(
children: <Widget>[
ListTile(
leading: CircleAvatar(backgroundImage:
NetworkImage(''),backgroundColor: Color(),),
title: Text('', style: TextStyle(color: Color ()),
subtitle: Text(
'', style: TextStyle(color: Color()),),),
Divider(
height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.add, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color()),
),
],
),
Row(
children: <Widget>[
Icon(Icons.comment, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color())),
],
),
Row(
children: <Widget>[
Icon(Icons.bookmark, color: Color()),
SizedBox(width: 8.0),
Text('', style: TextStyle(color: Color()),),
],
),
],
),
SizedBox(height: 12.0,),
I believe the problem is caused by the child container in the card widget. The container is overlapping over the cards borders so it covers the border radius and the elevation. Try putting the container as the parent of the card and see it that helps. Additionally,you could set the containers decorations property to have the same border radius as the card so it does not overlap.

Flutter RenderFlex overflowed

Hi i am new in flutter and i am facing this error
A RenderFlex overflowed by 9.0 pixels on the right.
The relevant error-causing widget was Row
this is my code down below:
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
iconTheme: IconThemeData(
color: Colors.grey[600],
),
leading: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: GestureDetector(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Icon(
Icons.arrow_back_ios_outlined,
),
Text(
'Back',
style: GoogleFonts.poppins(
color: Colors.grey[600],
fontSize: 20
),
),
],
),
And here is screenshot from my device emulator
Can you help me please how to fix this error?
Wrapping the Icon with an Expanded widget will get rid of the error here.
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0.0,
iconTheme: IconThemeData(
color: Colors.grey[600],
),
leading: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: GestureDetector(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Icon(
Icons.arrow_back_ios_outlined,
),
),
Text(
'Back',
style: GoogleFonts.poppins(
color: Colors.grey[600], fontSize: 20),
),
],
),
),
),
),
);
Does this solve your problem?
I tried add leadingWidth with value 100 to AppBar and that fixed my problem

How to make a Card lies between Body in flutter

Anybody how to do the layout similar to the image? I am having difficulty on the CardView and it position is lies between the body. I am still consider quite new to Flutter, having some difficulty in UI part. Full code is as below:
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: PreferredSize(
preferredSize: Size.fromHeight(45.0),
child: AppBar(
automaticallyImplyLeading: false,
elevation: 0.0,
centerTitle: true,
backgroundColor: Color(0xFFED2849),
leading: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: const EdgeInsets.only(left: 8.0),
child: GestureDetector(
onTap: (){
Navigator.of(context).pop(null);
},
child: Image.asset('assets/ic_user_title_back.png', width: 12.0, height: 12.0,),
),
),
],
),
title: Center(
child: Container(
child: Text(
'账号中心',
style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 14),
),
),
),
actions: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: GestureDetector(
onTap: (){
//logout
},
child: Text(
'退出登陆',
style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 11),
),
),
),
],
),
)
],
)
),
body: SafeArea(
top: false,
child: Material(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 3,
child: Container(
color: Color(0xFFED2849),
),
),
Expanded(
flex: 7,
child: Container(
color: Color(0xFFF1F1F1),
),
)
],
),
),
)
);
}
You can do this using Stack
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(
// fit: StackFit.expand,
children: [
Column(
children: [
Expanded(
flex: 3,
child : Container(color: Colors.red)
),
Expanded(
flex: 7,
child: Container(
color : Colors.white)
)
]
),
Positioned(
top: MediaQuery.of(context).size.height * 0.2,
left: 20,
right: 20,
child:Card(
child: Padding(
padding : const EdgeInsets.all(16),
child: Text("Your Text here", ),
),)
)
],
)
Try using Stack() it will allow you to overlap several children in a simple way.

Column/Scrollview not showing after i made a fixed bottom bar

Apparently i tried to make a bottom button for checkout and it seems to be affecting how the body of the app is working. This only happened after i added the bottomnavbar padding etc
heres the link for the snip: https://imgur.com/a/sDhqasr
class _State extends State<CartOverviewScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Cart'),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Center(child: Text('HI!'),)
],
),
),
bottomNavigationBar: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Card(
margin: EdgeInsets.all(15),
child: Padding(
padding: EdgeInsets.all(8),
child: Row(
children: <Widget>[
Text(
'Total',
style: TextStyle(
fontSize: 20,
),
),
SizedBox(width: 10,),
Chip(label: Text('\$0.00'),)
],
),
),
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
elevation: 8,
onPressed: () {},
color: colorCustom,
textColor: Colors.white,
child: Text('Checkout'),
),
),
],
),
),
);
}
}
you can also try this
class _State extends State<stat> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Cart'),
),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Text("Hi"),
),
)
],
),
bottomNavigationBar: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Card(
margin: EdgeInsets.all(15),
child: Padding(
padding: EdgeInsets.all(8),
child: Row(
children: <Widget>[
Text(
'Total',
style: TextStyle(
fontSize: 20,
),
),
SizedBox(
width: 10,
),
Chip(
label: Text('\$0.00'),
)
],
),
),
),
ButtonTheme(
minWidth: double.infinity,
child: RaisedButton(
elevation: 8,
onPressed: () {},
color: Colors.red,
textColor: Colors.white,
child: Text('Checkout'),
),
),
],
),
),
);
}
}
Ahh i found my own answer actually, the problem was caused by bottomNavigationBar hogging the entire body of the app. i just needed to place the following code from below onto the bottomNavigationBar Column.
mainAxisSize: MainAxisSize.min

Flutter PersistentFooterButtons invisible with active keyboard

I feel like I'm not completely getting persistentFooterButtons. I thought that they'd be part of the safe area, so I can see them when the keyboard is visible. Is there a way to achieve this?
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Persisting test'),
),
body: Center(child: TextFormField()),
persistentFooterButtons: <Widget>[
IconButton(icon: Icon(Icons.map), onPressed: () {}),
IconButton(icon: Icon(Icons.view_week), onPressed: () {}),
],
);
}
You could try using a Stack and an Align widget
return Scaffold(
appBar: AppBar(
title: Text('Persisting test'),
),
body: Center(
child: Stack(
children: <Widget>[
TextFormField(),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(icon: Icon(Icons.map), onPressed: () {}),
IconButton(icon: Icon(Icons.view_week), onPressed: () {}),
],
),
)
],
)),
);
i hope this may help
Widget bodySection = new Expanded(
child: new Container (
padding: new EdgeInsets.all(8.0),
color: Colors.white70,
child: new TextFormField(
style: const TextStyle(
color: Colors.black,
),
decoration: new InputDecoration(
icon: new Icon(
Icons.lock,
color: Colors.black,
),
border: InputBorder.none,
hintText: "Enter some text here ..",
hintStyle: const TextStyle(color: Colors.black, fontSize: 12.0),
contentPadding: const EdgeInsets.only(
top: 20.0, right: 5.0, bottom: 20.0, left:30.0),
),
),
),
);
Widget fixedBottomSection = new Container (
padding: new EdgeInsets.all(8.0),
color: Colors.purpleAccent[200],
height: 48.0,
child:
new InkWell(
onTap: _continue,
child: new Center(
child: new Text('Next ' , style: TextStyle(color: Colors.white , fontWeight: FontWeight.bold),),
),
)
);
Widget content = new Column(
// This makes each child fill the full width of the screen
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
bodySection,
fixedBottomSection,
],
);
return new Scaffold(
appBar: new AppBar(
// backgroundColor: Colors.purpleAccent[200],
title: new Text("Fixed bottom action bar above keyboard"),
),
body: new Padding(
padding: new EdgeInsets.symmetric(vertical: 0.0, horizontal: 0.0),
child: content,
),
);
here is a prove that it works: