Flutter Divider is the wrong colour - flutter

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)

Related

Flutter Showing two horizontal lines either side of a text

I am trying to show two horizontal lines either side of text: Or . As shown in the image below:
I have tried to do this using a Row with two dividers and a text in it. However it is only showing the Text("Or"), on the screen.
Here is the code I am trying:
Widget showDivider() {
return Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
Text('or'),
Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
],
),
);
}
No matter which settings I try on the Dividers they are not showing.
Any help in getting this sorted would be appreciated. Many thanks.
Wrap your Both Dividers with Expanded.
Wrap both the dividers with expanded widgets
Widget showDivider() {
return Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
)
Text('or'),
Expanded(
child: Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
).
],
),
);
Use Expanded Widgets
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
),
Expanded(
flex: 1,
child: Text(
'or',
textAlign: TextAlign.center,
),
),
Expanded(
flex: 2,
child: Divider(
indent: 10,
endIndent: 10,
thickness: 5.0,
height: 5.0,
color: Colors.black87,
),
),
],
),
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
height: .3,
width: double.infinity,
color: Colors.black),
),
Text('or'),
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
height: .3,
width: double.infinity,
color: Colors.black),
),
],
),
),
);
}

Remove space in Stack

I want to place Card below the 4 icons, but why there is a big gap between?
case ConnectionState.active:
if (snapshot.hasData) {
return SingleChildScrollView(
child: Column(children: [
Stack(
children: [
Container(
height: 500,
),
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(height: 50, color: Colors.orange)),
Positioned(
top: 0,
left: 24,
right: 24,
child: Card(
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.white70, width: 1),
borderRadius: BorderRadius.circular(30),
),
margin: EdgeInsets.all(20.0),
child: _showWidget(
snapshot.data!), // this are the 4 icons code
),
),
],
),
_showBelowCard(snapshot.data!), // card below 4 icons
]));
} else {
return NoItem();
}
Widget _showBelowCard(ABC abc) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Place it below 4 icons",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
Text(
"Status",
style: TextStyle(color: Colors.grey),
),
]);
}
The reason why it is way down is due to the Container() with the height of 500 on your Stack(). The Stack() widget usually takes the size of the biggest children.
And if you want to have some space between the Card() and the Stack() just add SizedBox() with your desired height.

Flutter. How can I overlay the container with a dynamic size by another container?

I have a container that represents a card with dynamical content. So it can be about 175 pixels height, can be 300. If this card is disabled I want to overlay this card by another container with, let say, gray color with opacity 0.5. I've realized that I can use Stack for this, but how can I define the correct size for overlay container?
Widget build(BuildContext context) {
return Center(
child: Stack(children: [
_buildCard(context),
Container(
margin: EdgeInsets.only(top: 8, left: 16, right: 16, bottom: 8),
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.75),
borderRadius: BorderRadius.circular(20.0)),
child: Center(
child: Text(
AppTranslations.of(context).text("pending"),
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
)))
]),
);
}
Widget _buildCard(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 8, left: 16, right: 16, bottom: 8),
child: Container(
decoration: new BoxDecoration(
borderRadius: new BorderRadius.all(new Radius.circular(20.0)),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 10.0,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: Material(
clipBehavior: Clip.antiAlias,
color: Colors.white,
child: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildImageLogo(),
Expanded(
child: Container(
padding: EdgeInsets.only(top: 12, left: 6, right: 6),
// margin: EdgeInsetsDirectional.fromSTEB(0, 8, 0, 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
LimitedBox(
maxWidth: 135,
child: Text(
widget.serviceInfo.title == null
? ""
: widget.serviceInfo.title,
style: TextStyle(fontSize: 16),
textAlign: TextAlign.start,
),
),
LimitedBox(
maxWidth: 50,
child: Container(
margin: EdgeInsetsDirectional.fromSTEB(
0, 0, 8, 0),
child: Text(
widget.serviceInfo.price == null
? ""
: ("AED" +
widget.serviceInfo.price
.toString()),
style: Theme.of(context)
.textTheme
.title
.copyWith(
fontSize: 13,
color: Colors.black54),
textAlign: TextAlign.end,
),
),
),
],
),
SizedBox(
height: Size.fromHeight(15).height,
),
Text(
widget.serviceInfo.description == null
? ""
: widget.serviceInfo.description,
style: Theme.of(context)
.textTheme
.caption
.copyWith(fontSize: 13),
),
serviceOptions(),
],
),
)),
],
),
SizedBox(
height: Size.fromHeight(10).height,
),
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(
top: 8, bottom: 8, left: 8, right: 8),
child: _btnDecline(),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(
top: 8, bottom: 8, left: 8, right: 8),
child: _btnAccept(),
),
),
],
),
],
),
),
),
));
}
the full hierarchy looks like
Scaffold -> Consumer -> Center -> Column -> Expanded -> Consumer -> ListView -> ServiceCard
You GlobalKey to get the BuildContext and use it to find out your container's size using it's RenderBox. Then you can give this size to the overlaying container. However, this is overkill imo.
You can also define a boolean to see whether or not your container should be overlayed and adjust it's decoration conditionally.

Flutter: Divider not showing in Row Widget

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,
),
),
],
),

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,
);
}