Related
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
]
),
);
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: () {},
),
],
),
],
)
So im trying to make an icon button with 2x3 stuff, where there are 2 rows of 3 elements across a screen. However when im implementing this with row the text is on the right side of the icon, I would like to make the text below the icon
Currently What is have is this
Widget build(BuildContext context) {
return new Scaffold(
body: Column (children: <Widget>[
Row(
//row1
children: [
IconButton(
iconSize: 70.0,
icon: const Icon(Icons.add_chart, color: Colors.greenAccent),
tooltip: 'My Learning',
),
Text('My Learning',
style: TextStyle(color: Colors.orange)
),
IconButton(
iconSize: 60.0,
icon: const Icon(Icons.lightbulb_outline, color: Colors.greenAccent),
tooltip: 'Deep 46',
),
Text('Deep 46',
style: TextStyle(color: Colors.orange)
),
IconButton(
iconSize: 60.0,
icon: const Icon(Icons.flight, color: Colors.greenAccent),
tooltip: 'unleashed',
),
Text('More Unleashed',
style: TextStyle(color: Colors.orange)
),
],
),
Row(
children: [
IconButton(
iconSize: 60.0,
icon: const Icon(Icons.videogame_asset_outlined, color: Colors.greenAccent),
tooltip: 'learning game',
),
Text('Learning Game',
style: TextStyle(color: Colors.orange)
),
IconButton(
iconSize: 60.0,
icon: const Icon(Icons.access_time, color: Colors.greenAccent),
tooltip: 'absen',
),
Text('Absen',
style: TextStyle(color: Colors.orange)
),
IconButton(
iconSize: 60.0,
icon: const Icon(Icons.calendar_today, color: Colors.greenAccent),
tooltip: 'event',
),
Text('Event',
style: TextStyle(color: Colors.orange),
textAlign: TextAlign.end
),
],
),
]
)
);
}
Which outputs something that looks like:
How can i make the text below the icons, also if anyone knows how do i make the row or icon start at the bottom of the screen.
Thank you!
Wrap icon and text with Column:
[EDITED]
Column(
children[
Expanded(child: Container()),
Row(
children: [
Column(
children: [
IconButton(
iconSize: 70.0,
icon: const Icon(Icons.add_chart, color: Colors.greenAccent),
tooltip: 'My Learning',
),
Text('My Learning',
style: TextStyle(color: Colors.orange)
),
So you can use "Column" widget that will solve your problem.
For example,
column(
children: <widget>[
IconButton(
iconSize: 70.0,
icon: const Icon(Icons.add_chart, color: Colors.greenAccent),
tooltip: 'My Learning',
),
Text('My Learning',
style: TextStyle(color: Colors.orange)
)
]
)
Note: Inside your row widget you can make this Column widget as your direct children then wrap your IconButton and text into the Column widget.
I hope it will help you. Thanks!
Hello new to flutter here. I am trying to open phone dialer with a predefined phone number after pressing Call button that is Flatbutton inside Positioned, but it is not working and does not show any error either. I tried printing some values on onpressed as well but it did not print any. I have called this widget in another dart file.
Here i am using url_launcher package to launch the phone dialog.
If any other alternative way please help.
(Removed some unimportant design codes below)
class CallCard extends StatefulWidget {
#override
_CallCardState createState() => _CallCardState();
}
class _CallCardState extends State<CallCard> {
#override
Widget build(BuildContext context) {
return Positioned(
bottom: -170,
child: Container(
child: Column(
children: <Widget>[
SizedBox(
height: 15,
),
Text(
'Are you feeling well today?',
style: TextStyle(
fontSize: 24.0,
),
),
Text(
'Give us a call or visit our website.',
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w300,
),
),
SizedBox(
height: 23.0,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
color: Color(0xff9ce47c),
onPressed: () {
final String phone = "01-4441577";
launch(phone);
print('here');
},
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(50),
),
child: Row(
children: <Widget>[
Icon(
LineAwesomeIcons.phone,
size: 22,
),
SizedBox(
width: 5.0,
),
Text(
'Call Now',
style: TextStyle(
fontSize: 16,
),
),
],
),
),
SizedBox(
width: 1.0,
),
],
),
),
],
)
],
),
));
}
}
This is the code where I have called this widget (inside Stack)
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
overflow: Overflow.visible,
children: <Widget>[
_backgroundCover(),
//content inside header
Positioned(
top: 80,
left: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
//crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Hello User',
style: TextStyle(
fontSize: 36,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
SizedBox(width: 10.0,),
// Padding(padding: EdgeInsets.only(right: 200.0)),
IconButton(
icon: Icon(
LineAwesomeIcons.power_off,
size: 40.0,
),
onPressed: () {
DialogHelper.exit(context);
// await _auth.signOut();
}),
],
),
),
CallCard(),
],
),
],
),
),
);
Did you try putting the print before launch? It could be that launch is getting stuck and then the print never gets reached (this has happened to me with certain packages).
I am not sure how launch works with phone numbers but you may want to look into if youre using it properly.
I'm ok with this code.
launch('tel:$yourPhoneNo');
More often than not, the icons I select to display will not show up (or will show up incorrectly) throughout my entire application. I'm not importing any new icons, all of the ones I use are selected from Flutter's default library.
On Android devices it is pretty much hit-or-miss; either all of the icons show up correctly, or they all give the same error placeholder. Like I said its much more often that they do not show.
iOS is a different story, while they still usually don't work correctly, it sometimes gives random emojis instead of the correct icon or error boxes. As you can see in the second picture, it placed a forward arrow emoji in place of what should have been the list-like icon to open the Drawer. Previously, the Close icon inside the Drawer was displaying as the strong arm emoji.
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.format_align_center),
onPressed: () => _scaffoldKey.currentState.openDrawer(),
),
title: Text(
"INFORMATION",
style: TextStyle(
fontFamily: 'Titillium SemiBold',
fontSize: 37.0,
),
),
centerTitle: false,
backgroundColor: Colors.white,
elevation: 0.5,
),
drawer: Drawer(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 150.0,
color: Colors.white.withRed(191).withGreen(194).withBlue(200),
child: FittedBox(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 8.0),
child: Text(
"VITALITY PRO",
style: TextStyle(
color: Colors.white
),
),
)
)
),
SizedBox(height: 10.0),
ListTile(
title: Text(
"TERMS & CONDITIONS",
style: TextStyle(
fontSize: 18.0,
),
),
onTap: () => Navigator.pushNamed(context, '/terms'),
),
Divider(),
ListTile(
title: Text(
"PRIVACY POLICY",
style: TextStyle(
fontSize: 18.0
),
),
onTap: () => Navigator.pushNamed(context, '/privacy'),
),
Divider(),
SizedBox(height: 10.0),
ListTile(
title: Text(
"CLOSE",
style: TextStyle(
fontSize: 18.0
),
),
trailing: Icon(Icons.clear),
onTap: () => Navigator.pop(context),
),
SizedBox(height: 10.0),
Divider(),
Flexible(
fit: FlexFit.loose,
child: Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text(
"LOGOUT",
style: TextStyle(
color: Colors.black38,
),
),
onPressed: () => Navigator.pushNamed(context, '/origin'),
),
Text("#Copyright 2018, ISPA Technology, LLC"),
],
),
),
),
],
),
),
),
That's a known issue that was fixed since.
Run
flutter upgrade
to get a newer Flutter version where this fix is included.