this is my code... it says errorerror
SingleChildScrollView(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
weightIndicator(
0,
'0,2 kg',
),
weightIndicator(
0,
'0,4 kg',
),
weightIndicator(
0,
'0,6 kg',
),
weightIndicator(
0,
'0,8 kg',
),
weightIndicator(
0,
'1,0 kg',
),
],
),
),
how to fix the error?
Instead of using this Row with SingleChildScrollView , you can either use Wrap or use the ListView with the axisDirection as Axis.horizontal
Use this property inside "SingleChildScrollView",
-scrollDirection: Axis.horizontal
Related
Whenever I am writing Text(email.toString()), it gives the error of RenderFlex overflowed, please help me how to fix it. I am using SharedPreferences.
Add your Text widget inside Expanded or Flexible widget,
try below code:
Row(
children: [
Text('Email'),
SizedBox(
width: 10,
),
Expanded(
child: Text(
'putyouremailaddress#gmail.computyouremailaddress#gmail.com'),
),
],
),
Result:
replace your Row with this one...
Row(
children: [
const Text("Email"),
Expanded(
child: Text(email.toString()),
),
],
),
I want to make the ListView have a same height with its content,
but always got Horizontal viewport was given unbounded height Errors
I tried to defined a SizedBox with a height as parent of the ListView, but it seems weird
All of the items was going strecth down
How can i defined this ListView without defined a height (dynamically following the content height)?
The result before using listview
After using ListView(Weird look)
There is the code :
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...OTHER CHILD,
ListView(
scrollDirection: Axis.horizontal,
children: [
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
],
),
],
),
There is the Child Component :
Container(
width: 260,
height: 210,
decoration: BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.all(Radius.circular(14)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 5,
offset: Offset(0, 0),
),
],
),
child: Column(
children: [
...OTHER CHILD,
],
),
);
I think if you use this
crossAxisAlignment: CrossAxisAlignment.stretch,
instead of this
crossAxisAlignment: CrossAxisAlignment.start
then it will work.
Set shrinkWrap: true in ListView and wrap ListView with Flexible widget.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...OTHER CHILD,
Flexible(
child: ListView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: [
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
],
),
),
],
),
This way ListView will only take as much space as it's children need.
ListView will take all the available space.
if scrollDirection set to Axis.horizontal it will take all the available height or if it set to verticle then it will take all available width.
It's the default behavior.
You can use SingleChildScrollView with Row.
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
...OTHER CHILD,
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
SizedBox(width: 10),
HorizontalList(),
],
),
)
],
),
I'm building an app in flutter and I finally got the app to run, but for some reason, the DraggableScrollableSheet doesn't expand nor collapse.
I added a SingleChildScrollView, but it only makes whatever is inside the sheet scrollable but the sheet itself is basically "frozen".
Solutions I tried:
Using a ScrollView but it also didn't work as expected.
Removing the Expanded widget but I get a constraints error.
My code:
Sacffold(
///....
body: column (
children: [
SizedBox(
height: 128,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
child: Text(
//...
),
),
Text(
//...
),
],
),
),
Expanded(
child: DraggableScrollableSheet(
initialChildSize: 0.6,
minChildSize: 0.2,
maxChildSize: 1.0,
builder: (context, scrollController) {
return Expanded(
child: SingleChildScrollView(
controller: scrollController,
child: Container(
decoration: const BoxDecoration(
//...
),
child: Column(
children: [
Container(
height: 82,
decoration: const BoxDecoration(
//...
),
child: Row(
children: [
Expanded(
flex: 1,
child:
Padding(
padding: const EdgeInsets.fromLTRB(
0, 10, 0, 15),
child: Column(
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(5),
child: Text(
//...
),
),
),
Text(
//...
),
],
),
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.fromLTRB(
0, 10, 0, 15),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(5),
child: Text(
//...
),
),
Text(
//...
),
],
),
),
),
],
),
),
Container(
//...
),
],
),
),
),
);
},
),
),
],
)
I was trying to run the app on windows, but after doing a lot of research and testing, I found out the DraggableScrollableSheet doesn't work on windows, it only works on android/ios. I ran the app on an android emulator and it worked perfectly fine.
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
]
),
);
I'm trying to place a text countdown timer in the center of a CircularProgressIndicator. This is the code for the layout of the body:
return new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Stack(
children: <Widget>[
Container(
width: 200,
height: 200,
child: new CircularProgressIndicator(
strokeWidth: 15,
value: value,
),
),
Align(
alignment: FractionalOffset.center,
child: Text("Test")
)
],
),
...
],
);
Adding the Align() widget changes the layout from this:
to this:
I've also tried
Align(
alignment: Alignment.center,
child: Text("Test")
)
and
Center(
child: Text("Test"),
)
instead of the Align() widget, but they all produce the same result
That's because your Stack doesn't have size, so to fix your issue, wrap your Stack inside SizedBox, set a height, and Center the Text.
Column(
children: <Widget>[
SizedBox(
height: 200.0,
child: Stack(
children: <Widget>[
Center(
child: Container(
width: 200,
height: 200,
child: new CircularProgressIndicator(
strokeWidth: 15,
value: 1.0,
),
),
),
Center(child: Text("Test")),
],
),
),
],
)
Use Positioned They are meant to be used with Stacks.
As per documentation:
A Positioned widget must be a descendant of a Stack, and the path from the Positioned widget to its enclosing Stack must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).
Also, don't forget to wrap your Stack inside a Container or Center so as to put constraints to the box.
Column(
children: <Widget>[
SizedBox(
height: 40,
child: Stack(
children: <Widget>[
Container(
width: 40,
height: 40,
child:
new CircularProgressIndicator(
value: 10,
color: Colors.red,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
top: 15,
child: Text(
bytesDownload!,
textAlign:
TextAlign.center,
style: TextStyle(
fontSize: 10,
),
)),
],
),
),
],
)
Just Wrap it inside a SizedBox()
https://i.stack.imgur.com/fJfaL.png