Flutter: Divider not showing in Row Widget - flutter

The question says itself what is the problem
Code Snippet:
Below code working fine for Column, but when I replaced it with Row, it's not showing Divider on the screen.
Column(
children: <Widget>[
Divider(
thickness: 1,
color: Colors.black,
),
SizedBox(
width: 50,
),
Divider(
thickness: 1,
color: Colors.black,
),
],
),

Row Widget required to be used Divider with Expanded/Flexible Widget
Row(
children: <Widget>[
Flexible(
child: Divider(
thickness: 1,
color: Colors.black,
),
),
SizedBox(
width: 10,
),
Flexible(
child: Divider(
thickness: 1,
color: Colors.black,
),
),
],
),

Related

How do I make a widget that makes the text wrap

I have a container that is sized relative to the window size. I need my text widget, which is nested in this container to fill the size of the container, which I can do except the text all stays on one line. I want the text to wrap to that it fills the height of the container and not just its width.
This is my current code,
Container(
width: width * 2.5,
height: height,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: EdgeInsets.fromLTRB(width / 2, 0, width / 2, 0),
child: Opacity(
opacity: 0.2,
child: Image.asset(
'assets/images/${model?.imageName}',
height: centerIconHeight,
),
),
),
Flexible(
flex: 1,
child: FittedBox(
fit: BoxFit.contain,
child: Expanded(
child: Text(
model?.title ?? '',
softWrap: true,
maxLines: 10,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
color: Colors.cyan),
),
),
),
),
],
),
),
And this is what it looks like when I run it. Notice the text is too small because it is only on one line and matching the containers width.
FittedBox tries to fit the text in no matter of its size. Just remove it and text will be wrapped.
UPDATE:
Container(
width: width * 2.5,
height: height,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: EdgeInsets.fromLTRB(width / 2, 0, width / 2, 0),
child: Opacity(
opacity: 0.2,
child: Image.asset(
'assets/images/${model?.imageName}',
height: centerIconHeight,
),
),
),
Flexible(
flex: 1,
child: Text(
model?.title ?? '',
softWrap: true,
maxLines: 10,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30,
color: Colors.cyan),
),
),
],
),
),

Flutter Radio button text "kg" align problem?

As you can see in above picture "kg" text has huge gap.
but the height text field widget is perfect.
And it shows the following error.
Exception caught by widgets library
Incorrect use of ParentDataWidget.
Kindly let me know what is the problem
(I'm new to flutter)
Material(
elevation: 30.0,
shadowColor: Colors.grey,
child: Container(
height: 100,
width: 375,
decoration: BoxDecoration(
border: Border.all(
color: Colors.blue,
),
),
alignment: Alignment.topCenter,
child: SizedBox(
height: 300,
width: 500,
child: Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 300,
child: SingleChildScrollView(
child: TextField(
controller: weightcon,
style: TextStyle(
color: Colors.black,
fontSize: 30,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Weight',
focusedBorder: OutlineInputBorder(
borderRadius:
BorderRadius.circular(0.0),
borderSide: BorderSide(
color: Colors.black,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius:
BorderRadius.circular(0.0),
borderSide: BorderSide(
// color: Colors.redAccent[100],
color: Colors.black54,
width: 2.0,
),
),
),
onChanged: (weightval) {
print('First text field: $weightval');
globals.weightvalue =
double.parse(weightval);
},
),
),
),
SizedBox(
width: 5,
),
Container(
height: 130,
width: 30,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 30,
height: 50,
child: Flexible(
child: SizedBox(
child: Radio(
value: 0,
groupValue: 1,
onChanged: (value) {},
)),
)),
SizedBox(
width: 30,
),
SizedBox(
child: Flexible(
child: Text("KG"),
),),
Flexible(
child: SizedBox(
width: 30,
height: 25,
child: Radio(
value: 1,
groupValue: 1,
onChanged: (value) {},
)),
),
SizedBox(
width: 30,
),
SizedBox(
child: Flexible(
child: Text("LB"),
),),
],
),
),
],
),
),
),
),
),
Remove the height for sizedbox of radioButton, height takes the extra space
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 30,
child: Flexible(
child: SizedBox(
child: Radio(
value: 0,
groupValue: 1,
onChanged: (value) {},
)),
)),
SizedBox(
width: 30,
),
SizedBox(
child: Flexible(
child: Text("KG"),
),),
Flexible(
child: SizedBox(
width: 30,
child: Radio(
value: 1,
groupValue: 1,
onChanged: (value) {},
)),
),
SizedBox(
width: 30,
),
SizedBox(
child: Flexible(
child: Text("LB"),
),),
],
),
),
],
),
Output
You used the Expanded Widget the wrong way! It must be the children of a Flex Widget (Row, Column, ListView, GridView, Wrap,...). As you can see, you wrote:
Expanded(
child: Row( // this is where the error pointing at
),
),
So to fix it, remove that Expanded Widget and use it as parent of the widgets in side the Row Widget. This is an example:
Row(
children: [
Expanded( // Expanded Widget inside children parameter of Row Widget
child: Widget1(),
),
Expanded(
child: Widget2(),
),
],
),

Flutter Divider is the wrong colour

I want to use the Divider widget but for some reason the colour is coming out wrong. Notice now both views in the column use Colors.red, but the Divider comes out faded. What is going on here?
Widget buildSpacer() {
return Column(
children: [
Padding(
padding:
const EdgeInsets.only(top: 8, bottom: 16.0, left: 16, right: 16),
child: Row(
children: <Widget>[
Expanded(
child:
Container(color: Colors.red, height: 1)),
],
),
),
Container(height: 3),
Divider(height: 1, indent: 16, color: Colors.red, endIndent: 16, ),
],
);
}
It's because the default thickness is 0 (??)
If you set it to 1, they look the same
Divider(thickness: 1, color: Colors.red)

How to resolve A RenderFlex overflowed by 8.5 pixels on the bottom. in GridView

I need help with a problem that's driving me crazy.
Basically, I would like to make a GridView.count that will display my different objects. So far it's all working perfectly except for one problem.
Indeed, I have the error A RenderFlex overflowed by 8.5 pixels on the bottom. in my GridView.count. I tried to add a childAspectRatio but it displays differently depending on the screen size. And I want the size of my GridView.count to stay the same on every screen.
Does anyone have a solution to this puzzle ??
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: PreferredSize(
preferredSize: Size.fromHeight(120.0),
child: GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 10.0,
mainAxisSpacing: 10.0,
children: List.generate(
nearbySpaces.length,
(index) {
return Column(
children: [
Container(
padding: EdgeInsets.all(10),
height: 110,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(nearbySpaces[index]['coverImage']),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
),
child: Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
CupertinoIcons.heart_fill,
color: HexColor('#FF2D55'),
)
],
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: EdgeInsets.only(
left: 10, right: 10, top: 7, bottom: 7),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.7),
borderRadius: BorderRadius.circular(5)),
child: Text(
'€ ' +
nearbySpaces[index]['price'] +
'/hr',
style: TextStyle(
fontWeight: FontWeight.w500,
color: Colors.white,
fontSize: 13,
),
),
),
],
)
],
)
],
),
),
SizedBox(
height: 5,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
nearbySpaces[index]['name'],
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w600),
),
SizedBox(
height: 5,
),
Row(
children: [
SvgPicture.asset(
'assets/images/icons/map_marker.svg',
width: 12,
),
SizedBox(
width: 5,
),
Text(
nearbySpaces[index]['distance'] + ' km away',
style:
TextStyle(color: Colors.grey, fontSize: 13),
)
],
),
SizedBox(
height: 5,
),
Row(
children: [
SmoothStarRating(
rating:
double.parse(nearbySpaces[index]['average']),
isReadOnly: true,
size: 15,
filledIconData: Icons.star,
color: Colors.amber,
borderColor: Colors.grey,
halfFilledIconData: Icons.star_half,
defaultIconData: Icons.star_border,
starCount: 5,
allowHalfRating: false,
spacing: 1.0,
onRated: (value) {
print("rating value -> $value");
// print("rating value dd -> ${value.truncate()}");
},
),
SizedBox(
width: 5,
),
Text(
nearbySpaces[index]['average'].toString(),
style:
TextStyle(color: Colors.grey, fontSize: 13),
)
],
)
],
),
],
);
},
),
),
),
),
Warp the children's with a Flexible widget, check:https://www.youtube.com/watch?v=CI7x0mAZiY0.

Flutter divider widget not appearing

I'm currently learning how to build apps using the Flutter SDK and Android Studio. My problem is that I need to add a Divider widget between the 'Administrative' text and the rest of the Card but as you can see in the screenshot below, the divider isn't showing up. I've tried changing the size (In which case the space between the two texts just increases) and I've tried setting the color to see if it was defaulting to transparent on my phone. Nothing works!
Here's my code for the Card Widget State:
class BBSCardState extends State<BBSCard>{
#override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Row(
children: <Widget>[
new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative", style: new TextStyle(color: new Color.fromARGB(255, 117, 117, 117), fontSize: 32.0, fontWeight: FontWeight.bold)),
),
new Divider(),
new Text("text")
],
),
],
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
)
)
);
}
}
And here's the screenshot of what the card looks like:
Also:
Is there any way to increase the size of the actual line from the Divider? (Not just the spacing)
Thanks!
You could remove Row, then Column would take all available space and Divider would have width.
#override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(
top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative",
style: new TextStyle(
color: new Color.fromARGB(255, 117, 117, 117),
fontSize: 32.0,
fontWeight: FontWeight.bold)),
),
new Divider(
color: Colors.red,
),
new Text("text")
],
),
),
);
}
To make custom divider you could check implementation of Divider and adjust it. E.g. replace Divider with
new SizedBox(
height: 10.0,
child: new Center(
child: new Container(
margin: new EdgeInsetsDirectional.only(start: 1.0, end: 1.0),
height: 5.0,
color: Colors.red,
),
),
)
it was happening to me but I found out that this property solves it: thickness
child: Divider(
color: Colors.teal.shade100,
thickness: 1.0,
),
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.lightGreen,width: 3.0),
),
),
)
Instead of using divider you can use a customized container...
I had the same issue, but by putting my Divider inside an Expanded Widget fixed my problem.
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
SizedBox(width: 10),
Text(
'Login using Social Media',
style: TextStyle(color: Color(0xff818181), fontWeight: FontWeight.w500),
),
SizedBox(width: 10),
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
],
),
In Column, use Divider() and in Row, use VerticalDivider()
Container(
width: 200,
child: Divider(
thickness: 10,
color: Colors.red,
),
),
or
Expanded(
child: Divider(
thickness: 10,
color: Colors.red,
),
),
If you want to draw line for the Widget Views, Try using the BoxDecoration as like in below example
child: new Container(
decoration: new BoxDecoration(
border: Border(
top: BorderSide(width: 1.0, color: Colors.grey),
left: BorderSide(width: 1.0, color: Colors.grey),
right: BorderSide(width: 1.0, color: Colors.grey),
bottom: BorderSide(width: 1.0, color: Colors.grey),),
);
child: new Row(
....
),
)
Horizontal divider
Container(
width: double.infinity,
height: 2, // Thickness
color: Colors.grey,
)
Vertical divider
Container(
width: 2, // Thickness
height: double.infinity,
color: Colors.grey,
)
Recently I have to archive divider which have circular corner. but if I'm using container with border side it's not give accurate output. So you can use this code if you want circular corner.
ClipRRect(
borderRadius: BorderRadius.circular(6.33.r),
child: Container(
width: 100.w,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(196, 196, 196, 0.6),
width: 5.0.w),
),
),
),
),
I tried with expanded widget but not worked. But only this way it works for me
SizedBox(
height: 50,
child: VerticalDivider(
thickness: 3,
width: 4,
indent: 0,
color: ColorConstants.silverColor,
),
),
This way also worked for me, when I wrapped parent (Row) with IntrinsicHeight
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Padding(
padding: EdgeInsets.symmetric(horizontal: 15.0),
child: VerticalDivider(
thickness: 3,
width: 4,
indent: 0,
color: ColorConstants.silverColor,
),
),
HighTrendWidget(
trendValue: 'HIGH',
trendDifference: '1743.88',
)
],
),
)
If you want to use it inside row like you have multiple widgets to show inside row and also a divider then you can use Sizedbox with height and width . pasting code
SizedBox(
width: 60,
height: 30,
child: Divider(
height: 20,
color: defaultColor,
thickness: 5,
),
),
Add the thickness:
Divider(
thickness: 1,
color: Colors.teal.shade100,
)
Just adding the thickness parameter to 1 or above will solve the issue.
Working sample:
const Divider(
height: 1,
thickness: 1),
Padding(
padding: const EdgeInsets.only(right:20),
child:Divider(
color: Color(0xfff8a9c5),
thickness: 2,
),
),
Just Use this function for wherever you want
Divider verticalDivider() {
return Divider(
height: 2,
color: Colors.greenAccent,
);
}