I have a Column of 3 Containers, with the middle one transformed by rotating it back a bit.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 100,
width: 100,
color: Colors.green,
),
Transform(
alignment: Alignment.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..rotateX(pi / 3),
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
Container(
height: 100,
width: 100,
color: Colors.green,
)
],
),
Since Transform will use the height of its child, the middle item is now left with some top and bottom space. Is there any way to get rid of it?
One way I figured out is to use a SizedOverflowBox.
A widget that is a specific size but passes its original constraints
through to its child, which may then overflow.
By using this, the Column will think that the middle Container's size is smaller than it actually is.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 100,
width: 100,
color: Colors.green,
),
SizedOverflowBox(
size: Size(100, cos(pi/3) * 100),
child: Transform(
alignment: Alignment.center,
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..rotateX(pi / 3),
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
),
Container(
height: 100,
width: 100,
color: Colors.green,
)
],
),
Related
I want to clip a container in such a way like below image
I have read about a couple of clip but don't know how to achieve this.
I have tried implementing clipping using..
Container(
width: 300,
height: 300,
color: Colors.white,
child: ClipRRect(
child: Stack(
///clipBehavior: Clip.hardEdge,
children: [
Positioned(
left: 0,
top: 0,
child: Transform.rotate(
angle: 1,
child: Container(
color: Colors.red,
width: 250,
height: 250,
),
),
),
],
),
),
);
I have found a way to do this using CustomClipper
This is the screen that I want to create:
As you can see I have got two photo in the center, how can I move this background pink image in the top left corner?
Here's a link to my full code https://pastebin.com/CwgsPx4a
children: <Widget> [
SizedBox(
height: 250,
child: Image.asset(
"assets/logo.png",
fit: BoxFit.contain,
)
),
SizedBox(
child: Image.asset(
"assets/top.png",
fit: BoxFit.contain,
)
),
Code:
Column(
children: [
// fake top image
Align(
alignment: Alignment.topLeft,
child: Container(
width: 100,
height: 100,
color: Colors.red,
),
),
const SizedBox(height: 50),
// fake logo
Container(
width: 100,
height: 100,
color: Colors.blue,
),
// fake other widgets
const SizedBox(height: 16),
Container(
width: 200,
height: 30,
color: Colors.green,
),
const SizedBox(height: 16),
Container(
width: 200,
height: 30,
color: Colors.green,
),
],
);
Result:
Probably not the best question title but I would like to get some feedback on whether or not my layout could/should be simplified.
I want to get the following layout in Flutter (see image)
in a Container (light green)
I want a a centered central row (dark green) containing 80% of the width and 20% of the height
the row contains three spaced elements (red, blue and orange)
the red one contains a red centered 80% Container
The following code works but feels pretty complicated. Are there more elegant ways to achieve the same thing?
Container(
color: Colors.white,
child: Column(children: [
Expanded(
child: SizedBox.expand(
child: FractionallySizedBox(
widthFactor: 0.8,
heightFactor: 0.2,
alignment: FractionalOffset.center,
child: Container(
child: Row(
children: [
Flexible(
flex:2,
child: SizedBox.expand(child: Container(
color: Colors.red,
child: FractionallySizedBox(
widthFactor: 0.8,
heightFactor: 0.8,
child: Container(color:Colors.yellow),
)
)
),
),
Spacer(),
Flexible(flex:2, child: Container(color: Colors.blue)),
Spacer(),
Flexible(flex:2, child: Container(color: Colors.orange)),
],
))),
),
)
])),
It is not much change but it is something simpler:
Size size = MediaQuery.of(context).size;
return Container(
color: Colors.white,
child: Center(
child: Container(
height: size.height * 0.2,
width: size.width * 0.8,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width: size.width * 0.2,
color: Colors.red,
child: FractionallySizedBox(
widthFactor: 0.8,
heightFactor: 0.8,
child: Container(color: Colors.yellow),
)),
Container( width: size.width * 0.2, color: Colors.blue),
Container( width: size.width * 0.2, color: Colors.orange),
],
),
),
));
I have tried to achieve the effect shown in the highlighted portion of the image with the following code, but this produces counter-intuitive and wrong results.
Just to avoid confusion, I am talking about the effect of the middle of the smaller containers being aligned with the bottom of the large orange-ish container
My code is as follows:
Size size = MediaQuery.of(context).size;
double height = size.height;
double width = size.width;
return Column(
children: [
Expanded(
flex: 3,
child: Container(color: Colors.white),
),
Positioned(
top: height * (3 / 5) - height * 0.15 / 2,
child: Container(
color: Colors.green,
height: height * 0.15,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: height * 0.15,
width: width * 0.45,
color: Colors.red,
),
Container(
height: height * 0.15,
width: width * 0.45,
color: Colors.blue,
)
],
),
),
),
Expanded(
flex: 5,
child: Container(color: Colors.black),
),
],
);
How can I improve upon my code?
You will need to use the Stack widget to achieve this result.
Stack(children: [
Container(
height: 230,
decoration: BoxDecoration(
color: Colors.orange,
)),
Column(children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(22))),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(22))),
Container(
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(22))),
]),
),
])
])
I would like to make the bar chart starts from bottom to top in flutter because my bar chart is starting from top to down and this is leaving a bad impact for the users. So, how to can I make the bar chart starts from the bottom to top in flutter?
Bellow are two widgets of the bar chart, I just spread them into two different files.
print('build() ChartBar');
return LayoutBuilder(builder: (ctx, constraints) {
return
Column(
children: <Widget>[
Container(
height: constraints.maxHeight * 0.15,
child: FittedBox(
child: Text('\$${spendingAmount.toStringAsFixed(0)}'),
),
),
SizedBox(
height: constraints.maxHeight * 0.05,
),
Container(
height: constraints.maxHeight * 0.6,
width: 10,
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey, width: 1.0),
color: Color.fromRGBO(220, 220, 220, 1),
borderRadius: BorderRadius.circular(10),
),
),
FractionallySizedBox(
heightFactor: spendingPercentageOfTotal,
alignment: Alignment.bottomCenter,
child: Container(
decoration: BoxDecoration(
color: Colors.purple,
borderRadius: BorderRadius.circular(10),
),
)),
],
),
),
SizedBox(
height: constraints.maxHeight * 0.05,
),
Container(
height: constraints.maxHeight * 0.15,
child: FittedBox(
child: Text(label),
),
)
],
);
});
}
}
Widget build(BuildContext context) {
print('build() Chart');
return Card(
elevation: 6,
margin: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: groupedTransactionValues.map(
(data) {
return Flexible(
fit: FlexFit.tight,
child: ChartBar(
data['day'],
data['amount'],
totaLSpending == 0.0
? 0.0
: (data['amount'] as double) / totaLSpending));
},
).toList(),
),
),
);
}
}
you can use this code below. Flutter default is from top to bottom. You can change this by using Align widget.
Align(
alignment: Alignment.bottomCenter,
child: FractionallySizedBox(....),
)
add this into Stack widget
alignment: AlignmentDirectional.bottomStart,
the easy way is to use dependencies
https://pub.dev/packages/fl_chart