enter code hereenter image description herehow to reduce the vertical distance between widgets, I even haven't used any sizebox or padding then why this spacing happened, and also if I tried using "crossAxisAlignment" to start only text moved up but not image. why?
Wrap(
alignment: WrapAlignment.start,
children: [
Image.asset("assets/images/bline.png",
color: Colors.white, width: 150),
Text(
"or login with",
style: TextStyle(
fontFamily: GoogleFonts.oregano().fontFamily,
fontSize: 25,
color: Colors.white,
),
),
Image.asset("assets/images/bline.png",
color: Colors.white, width: 150),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SocialCard(
icon: "assets/icons/google.svg",
press: () {},
),
SocialCard(
icon: "assets/icons/facebook.svg",
press: () {},
),
SocialCard(
icon: "assets/icons/phone.svg",
press: () {},
),
],
),
Have you used Column as a parent of your Row widgets?
if yes, you should set:
mainAxisAlignment: MainAxisAlignment. //use different formats to find one that best suits for your purpose
In general, you should use mainAxisAlignment and crossAxisAlignment for each Row and Column to align their children in each direction.
see this Flutter crossAxisAlignment vs mainAxisAlignment.
If you've used Column.
maybe you should set the parameter
mainAxisSize и mainAxisAlignment
To change the spacing between widgets you can use SizedBox for fixed margins or Spacer to fill the remaining free space.
You can also wrap your widgets in Expanded.
And set Flex option for Expanded and Spacer
Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
children: [
widget_1,
SizedBox(
height: 10,
),
widget_2,
Spacer(),
widget_3,
],
);
You just replace your Column with wrap
EDITED
Wrap(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assets/images/bline.png",
color: Colors.green,width: 120,),
SizedBox(height: 10,),
Text(
"or login with",
style: TextStyle(
// fontFamily: GoogleFonts.oregano().fontFamily,
fontSize: 25,
color: Colors.black,
),
),
SizedBox(height: 10,),
Image.asset("assets/images/bline.png",
color: Colors.green,width: 120,),
],),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SocialCard(
icon: "assets/icons/google.svg",
press: () {},
),
SocialCard(
icon: "assets/icons/facebook.svg",
press: () {},
),
SocialCard(
icon: "assets/icons/phone.svg",
press: () {},
),
],
),
],
)
Related
So I have a BottomAppBar and i'm trying to have a text right below the icon button, I have tried using Column with mainaxissize set to min and I have also tried to use wrap with the lowest spacing i can do but none of these methods put the text right below the icon, there seems to be some type of gap or padding between the icon and the text that I would like to remove, how can i make the text right below the Icon?
here is the code:
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 4.0,
child: new Row(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Wrap(
direction: Axis.vertical,
children: [
IconButton(
icon: Icon(
Icons.home_outlined,
color: Colors.grey,
),
onPressed: () => screenIndex(0)),
Text("Home")
]),
IconButton(
icon: Icon(
Icons.history,
color: Colors.grey,
),
onPressed: () => screenIndex(1)),
SizedBox(width: 10),
IconButton(
icon: Icon(
Icons.message,
color: Colors.grey,
),
onPressed: () => screenIndex(3)),
IconButton(
icon: Icon(
Icons.person_outline,
color: Colors.grey,
),
onPressed: () => screenIndex(4)),
],
),
),
This is what it is currently showing:
and I would like to have the text right underneath the icon
Change the IconButton widget as follows
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
direction: Axis.vertical,
children: [
IconButton(
icon: Icon(
Icons.home_outlined,
color: Colors.grey,
),
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
onPressed: () => screenIndex(0)),
Text("Home")
]),
The iconbutton has a default padding. You cab use an icon and wrap it with inkwell or gesture detector like shown below
InkWell(
onTap: () => screenIndex(0),
Column(
mainAxisSize: MainAxisSize.min,
children:[
Icon(Icons.home_outlined, color: Colors.grey),
Text("Home")
]
)
)
I am using a row, inside it, each text is a column and I want that whenever my text overflows, it should automatically go to next line, I tried everything, but it won't work. When I tried to use expanded or flexible, it gave error. I tried to make maxlines 2 and then use expanded/flexible, I also gave it a container as a parent widget and made it's height big enough, still error.
Here is the code snippet -
class RouteItems extends StatelessWidget {
final int index;
final NodeElement data;
RouteItems({required this.index, required this.data});
#override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
children: [
SvgPicture.asset(
'assets/icons/road-straight-line-top-view.svg',
height: 15,
width: 80,
),
SvgPicture.asset(
filterRoutesIcon("${data.node?.type}"),
height: 30,
width: 30,
),
SvgPicture.asset(
'assets/icons/road-straight-line-top-view.svg',
height: 15,
width: 80,
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Container(
//height: 60,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
Text(
data.eta!.getFormattedDate('hh:mm a, d MMM'),
style: TextStyle(fontSize: 10.0, color: colorDarkGrey),
)
],
),
),
),
],
),
Align(
alignment: Alignment.centerRight,
child: Icon(
Icons.timer,
),
),
],
);
}
}
This Row can be removed, what is the purpose of it ?
Row(
children: [
Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
)
You can try removing the maxLines: 1, and adding width constraints to your Text e.g wrapping it with a SizedBox, this way the text will wrap to the next line :
SizedBox(
width: 200,
child: Text(
'${data.node?.name}',
style: TextStyle(fontSize: 12.0),
),
)
Try below code hope its helpful to you. Just wrap your Text widget inside Expanded of Flexible
Refer Expanded here
Refer Flexible here
Or
Try to add your Inside Row widgets wrap it with Expanded or Flexible refer my answer here or here or here hope its helpful to you
Row(
children: [
Expanded(
child: Text(
'{data.node?.name}{data.node?.name}{data.node?.name}{data.node?.name}'
'{data.node?.name}{data.node?.name}{data.node?.name}{data.node?.name}'
'{data.node?.name}{data.node?.name}{data.node?.name}{data.node?.name}'
'{data.node?.name}{data.node?.name}',
style: TextStyle(fontSize: 12.0),
),
),
],
),
Your result Screen->
Try wrapping the text you want to not overflow in a Flexible() widget. That will make sure it doesn't take up more space in the row than is available.
You can also add or replace width paramater of SizedBox widget with
width: MediaQuery.of(context).size.width,
to constraint the Text child to the device screen width.
You can try this aproach
Expanded(
Row(
children: [
Card(
child: Text(" My awseome no overflow text"),),
..Other Widgets
]
),
);
im making a app using flutter how do I add a another Text widget in left side
(Im new to Flutter)
Try below answer hope its helpful to you. you can used ListTile and Row Widget refer ListTile here and Row here
Using ListTile
ListTile(
leading: CircleAvatar(),
title: Text(
'Make a word using letter \'a\'',
),
),
Your Result Screen using ListTile ->
Using Row
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
CircleAvatar(),
Text(
'Make a word using letter \'a\' ',
),
],
),
Your result screen using Row->
Use Row Widget.
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text('Hello Flutter'),
const Icon(
Icons.schedule,
size: 18,
color: Colors.white54,
),
const SizedBox(
width: 4,
),
const Text(
' min',
style: TextStyle(
fontSize: 11,
color: Color(0xfff1f1f1),
fontWeight: FontWeight.w700,
),
),
],
);
image link since i'm not allowed to post images yet
I'm trying to create an app but the two texts 'hello and mr '' are in the center even when I've not added the center widget and why do they have that amount of space between them. the app title had a massive bottom padding that i had to remove it.' the app sample is in the image above.
I just want the two to stack above each other in the top left corner, and the space between them to reduce, Here's my code:
Container(
child: SingleChildScrollView(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Text(
'Hello,',
style: Theme.of(context)
.textTheme.headline4
.apply( color: Colors.grey),
),
Text(
"Mr. Udeinya",
style: Theme.of(context)
.textTheme
.headline4
.apply(color: Colors.deepOrange, fontWeightDelta: 2),
),
Container(
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.deepOrange,
border: Border.all(
width: 3,
color: Colors.white,
)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Wallet Balance :',
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(
height: 10.0,
),
Container(
width: double.infinity,
)
],
),
),
],
),
),
),
and the image
image link since i'm not allowed to post images yet
One solution to your problem would be to change the crossAxisAlignment property of your column to CrossAxisAlignment.start
I would also recommend, if you intend to group them together, to put your two text widgets together in a column themselves.
Container(
child: SingleChildScrollView(
padding: EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Hello,',
style: Theme.of(context)
.textTheme
.headline4
.apply(color: Colors.grey),
),
Text(
"Mr. Udeinya",
style: Theme.of(context)
.textTheme
.headline4
.apply(color: Colors.deepOrange, fontWeightDelta: 2),
),
],
),
Container(
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.deepOrange,
border: Border.all(
width: 3,
color: Colors.white,
)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Wallet Balance :',
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(
height: 10.0,
),
Container(
width: double.infinity,
)
],
),
),
],
),
),
)
Something like This ? Hope that it helped.
Try to use text align property of Text widget you can find more in the link. Text widget documentation
Example:
Text("data,",textAlign: TextAlign.left,)
The problem is you are not giving a crossAxisAlignment to the top-most column, so by default, it is centred.Add this to the top-most Column
crossAxisAlignment: CrossAxisAlignment.start,
I'm building a flutter app with a Login Screen. On focus on the text field(s), the screen is overflowed and i cannot scroll. I've tried using a ListView.builder, but that just gives a renderBox error, and the regular ListView doesn't work
The widget structure is like this
-scafold
- body
- container
- column
- form
- column
- textInput
- textInput
- container
- container
- row
- raisedButton
Thank You in advance !!
The ListView solution should work, but at the time of writing, it suffers from the crash listed here. Another way to achieve the same thing without this crash is to use a SingleChildScrollView:
return new Container(
child: new SingleChildScrollView(
child: new Column(
children: <Widget>[
_showChild1(),
_showChild2(),
...
_showChildN()
]
)
)
);
try this Code: Its Using ListView
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Center(
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.all(15.0),
children: <Widget>[
Center(
child: Card(
elevation: 8.0,
child: Container(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.person),
labelText: "Username or Email",
),
),
SizedBox(
height: 15.0,
),
TextField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock),
labelText: "Password",
),
),
SizedBox(
height: 15.0,
),
Material(
borderRadius: BorderRadius.circular(30.0),
//elevation: 5.0,
child: MaterialButton(
onPressed: () => {},
minWidth: 150.0,
height: 50.0,
color: Color(0xFF179CDF),
child: Text(
"LOGIN",
style: TextStyle(
fontSize: 16.0,
color: Colors.white,
),
),
),
)
],
),
),
),
),
SizedBox(
height: 25.0,
),
Row(
children: <Widget>[
Expanded(child: Text("Don't Have a Account?")),
Text("Sign Up",
style: TextStyle(
color: Colors.blue,
)),
],
),
],
),
),
bottomNavigationBar: Padding(
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: RaisedButton(
padding: EdgeInsets.all(15.0),
onPressed: () {},
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
32.0,
),
side: BorderSide(color: Color(0xFF179CDF))),
child: Text(
"SKIP SIGN UP FOR NOW",
style:
TextStyle(fontSize: 18.0, color: Color(0xFF179CDF)),
),
)),
],
),
),
);
}
}
There are two easy ways of doing it.
Wrap your Column in a SingleChildScrollView
SingleChildScrollView(
child: Column(
children: [
Text('First'),
//... other children
Text('Last'),
],
),
)
Use ListView instead of Column.
ListView(
children: [
Text('First'),
//... other children
Text('Last'),
],
)
This approach is simple to use, but you lose features like crossAxisAlignment and other benefits provided by Column, in that case, you can wrap your children widget inside Align and set alignment property.
Now you may have nested children which are further scrollable, in that case, you need to provide a fixed height to your children, you may use SizedBox for that, that's it.
For example:
ListView(
children: [
Text('First'),
SizedBox(
height: 100,
child: ListView(...), // nested ScrollView
),
Text('Last'),
],
)
We can use the Expanded widget. It will add scrolling.
return new Expanded(
child: new SingleChildScrollView(
child: new Column(
children: <Widget>[
_showChild1(),
_showChild2(),
...
_showChildN()
]
)
)
);
Wrap your column in SingleChildScrollView and then wrap SingleChildScrollView in a Center widget to center the widgets in the column.
Center(
child: SingleChildScrollView(
child: Column(
children: [
Text('First'),
//... other children
Text('Last'),
],
),
)