How do i fixed containers in Flutter? - flutter

I want to make first container fixed in center and second container fixed in right but i couldn't. I add mainAxisAlignment: MainAxisAlignment.spaceBetween in row line but it didn't work. Is there different properties to adjust position of widgets?
My Code:
new Container(
width: 360,
height: 502,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xffffffff),
Color(0x00caebfe)
],
stops: [0,1]
)
),
child:Column(
//crossAxisAlignment: CrossAxisAlignment.start,
children:<Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text("JULY 2017",
style: TextStyle(
fontFamily: 'Baloo',
color: Color(0xff181743),
fontSize: 20,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
)
)
),
Container(
alignment: Alignment.centerLeft,
//padding: EdgeInsets.only(left:90.0),
child: Column(
children: <Widget>[
new Container(
width: 14,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
],
stops: [0,1]
),
)
),
new Container(
//margin: EdgeInsets.only(top:3.0),
width: 23,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
],
stops: [0,1]
)
)
)
],)
)
]
)
]
)
),
Is there different properties to adjust position of widgets?

Following what you said you wanted to achieve, as in having the text centred and the gradients all the way to the right, I've modified your code by adding an Expanded widget around the first Container in Row and removing the width of your top Container:
Container(
height: 502,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0xffffffff),
Color(0x00caebfe)
],
stops: [0,1]
)
),
child: Column(
children:<Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Center(
child: Text("JULY 2017",
style: TextStyle(
fontFamily: 'Baloo',
color: Color(0xff181743),
fontSize: 20,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
)
),
),
),
Column(
children: <Widget>[
new Container(
width: 14,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
],
stops: [0,1]
),
)
),
new Container(
//margin: EdgeInsets.only(top:3.0),
width: 23,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
],
stops: [0,1]
)
)
)
],)
]
)
]
)
),

Are you trying to make your FirstContainer placed at the very center, and your SecondContainer at the very end?
If so, you might want to use Row, and Expanded
So it would be something like this:
Row(
mainAxisSize: MainAxisSize.max,
children: [
/// Just a placeholder container to occupy 1/3 of the Row
Expanded(child: Container()),
Expanded(child: FirstContainer()),
Expanded(child: SecondContainer()),
]
)
What this does, is add a placeholder container which occupies 1/3 of the Row, and your FirstContainer will be forced to be at the center, and SecondContainer section of the Row.

#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: SafeArea(
child: Scaffold(
body: new Container(
width: 360,
height: 502,
decoration: new BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xffffffff), Color(0x00caebfe)],
stops: [0, 1])),
child: Stack(
children: <Widget>[
Positioned(
right: 0,
child: Container(
alignment: Alignment.center,
child: Text("JULY 2017",
style: TextStyle(
fontFamily: 'Baloo',
color: Color(0xff181743),
fontSize: 20,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
))),
),
Align(
alignment: Alignment.center,
child: Container(
child: Column(
children: <Widget>[
new Container(
width: 14,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
], stops: [
0,
1
]))),
new Container(
//margin: EdgeInsets.only(top:3.0),
width: 23,
height: 5,
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(colors: [
Color(0xfffe1e9a),
Color(0xfffea64c)
], stops: [
0,
1
])))
],
))),
])),
),
),
);
}
Check out this method using stack it makes it simple later can later modify thank-you.

Related

how to give curve design inside container in flutter?

I trying to understand how can I design curves in a container like the below
can anyone help me to design this kind of container? much appreciate it if anyone provides code for this kind of design.
Thank you in advance.
use Stack and boxDecoration, play with margins and size to get best result.
SizedBox(
width: double.infinity,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: Colors.grey,
boxShadow: const [
BoxShadow(color: Colors.grey, spreadRadius: 3),
],
),
height: 50,
),
Container(
width: 200,
child: const Center(
child: Text('\$1400'),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: const Color(0xff232fac),
boxShadow: const [
BoxShadow(color: Color(0xff232fac), spreadRadius: 3),
],
),
height: 50,
),
Container(
width: 200,
margin: const EdgeInsets.only(left: 150),
child: const Center(
child: Text('\$1400'),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: const Color(0xff483395),
boxShadow: const [
BoxShadow(color: Colors.white, spreadRadius: 3),
],
),
height: 50,
),
],
),
),
read about Stack
read about boxDecoration
You cab usethe decoration property of the container to add border radius to a container
Container(
height: 25,
width: 100,
decoration: BoxDecoration (
borderRadius : BorderRadius circular(15),
color: Colors.purple
)
)
Use Stack and gradient to implement this
Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration (
borderRadius : BorderRadius.circular(50),
gradient: LinearGradient(colors: [
Colors.purple,
Colors.grey,
],
stops: [0.5, 0],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
border: Border.all(color: Colors.white, width: 2)
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("\$1400"),
Text("\$700"),
],
),
),
),
Container(
height: 50,
width: 150,
decoration: BoxDecoration (
borderRadius : BorderRadius.circular(50),
color: Colors.green,
border: Border.all(color: Colors.white, width: 2)
),
child: Center(
child: Text("\$700"),
),
),
],
Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
Container(
height: 50,
width: double.infinity,
decoration: BoxDecoration (
borderRadius : BorderRadius.circular(50),
gradient: LinearGradient(colors: [
Colors.purple,
Colors.grey,
],
stops: [0.5, 0],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
border: Border.all(color: Colors.white, width: 2)
),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text("\$1400"),
Text("\$700"),
],
),
),
),
Container(
height: 50,
width: 150,
decoration: BoxDecoration (
borderRadius : BorderRadius.circular(50),
color: Colors.green,
border: Border.all(color: Colors.white, width: 2)
),
child: Center(
child: Text("\$700"),
),
),
],
You can try something like this:
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: MyApp()));
}
class MyApp extends StatelessWidget {
final double center = 300;
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(children: [
Positioned(
left: 0,
child: Container(
width: center,
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.indigo, Colors.blue]),
borderRadius: BorderRadius.all(Radius.circular(
MediaQuery.of(context).size.height / 2.0)),
border: Border.all(color: Colors.white, width: 3)),
child: const Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'\$ 1400',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
)),
Positioned(
right: 0,
child: Container(
width: MediaQuery.of(context).size.width - center,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.all(Radius.circular(
MediaQuery.of(context).size.height / 2.0)),
border: Border.all(color: Colors.white, width: 3)),
child: const Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'\$ 900',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
),
)),
Positioned(
left: center,
child: FractionalTranslation(
translation: const Offset(-0.5, 0),
child: Container(
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.indigo, Colors.purple]),
borderRadius: BorderRadius.all(Radius.circular(
MediaQuery.of(context).size.height / 2.0)),
border: Border.all(color: Colors.white, width: 3)),
child: const Center(
child: Padding(
padding: EdgeInsets.fromLTRB(20, 8, 20, 8),
child: Text(
'\$ 700',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
),
)),
]),
);
}
}
output:
use decoration property see simple use.
Container(
height: 50,
width: 500,
decoration: BoxDecoration (
borderRadius : BorderRadius circular(40),
color: Colors.red)
child: const Center(
child: Text('\$ 1400'),),
)

Fading image in Flutter

Can anyone please explain how to get this image shading effect in Flutter.
I assume you want to get the fading out background. The best way to do it is to use a Stack, with your background image at the bottom, a gradient going from your background color to transparent above it, and then your UI elements above that. Here is a working example build:
#override
Widget build(BuildContext context) {
return Material(
child: Stack(
fit: StackFit.expand,
children: [
Image.asset('assets/background.jpg', fit: BoxFit.cover,),
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter, end: Alignment.bottomCenter,
colors: [Colors.transparent, Colors.white],
stops: [0, .4]
)
),
),
Padding(padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: const [
Icon(Icons.arrow_back),
Expanded(child: Center(child: Text('Steve Johnson',
style: TextStyle(fontSize: 18)
))),
Icon(Icons.remove_circle_outline_sharp)
],
),
const SizedBox(height: 32,),
Container(
height: 96, width: 96,
decoration: BoxDecoration(
border: Border.all(color: Colors.deepOrange, width: 4),
color: Colors.white,
),
child: Image.asset('assets/profile.jpg',
alignment: Alignment.topCenter,
fit: BoxFit.fitWidth,),
),
],
)
)
]
)
);
}

Flutter how can I fill one edge of a container ? [ Toast notificaton container]

What I want to do is following left corner in the container.
I tried to do it putting another green container in it but, it does not fit with the border radius of original container.
like this?
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
width: 10,
height: 100,
decoration: BoxDecoration(
color: Colors.green,
),
),
Container(
width: 390,
height: 100,
decoration: BoxDecoration(
color: Colors.greenAccent,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(Icons.check_circle),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("YOUR MAIN TEXT"),
Text("YOUR TEXT"),
],
),
],
),
),
],
),
)
You can achieve it by setting a BorderSide inside a Border.
Container(
height: 100,
width: 400,
decoration: BoxDecoration(
color: Colors.green[200],
border: const Border(
left: BorderSide(
width: 16.0,
color: Colors.green,
),
),
),
),

Flutter Complex Linear Gradient Not Working

Above is the expected output.
I need to implement this gradient in Flutter but it's not coming out as excepted.
Color: #6646E7
The color shift is very strict and not smooth as shown in the image.
Below is the container where I wanted to use the
Complete Code:
Stack(
alignment: Alignment.bottomRight,
children: [
Container(
margin: const EdgeInsets.only(left: 10, right: 10, top: 15),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
border: Border.all(color: Colors.white, width: 2),
// gradient: LinearGradient(
// begin: Alignment.topLeft,
// end: Alignment.bottomRight,
// stops: const [
// 0.01,
// 0.1,
// 0.9
// ],
// colors: [
// const Color(0xff6646E7).withOpacity(0.4),
// Colors.white,
// const Color(0xff6646E7).withOpacity(0.4),
// ]),
// boxShadow: [
// const BoxShadow(
// color: Color.fromRGBO(0, 0, 0, 0.25),
// blurRadius: 3,
// spreadRadius: 1,
// offset: Offset(0, 4))
// ]),
),
child: Column(
children: [
Row(
children: [
SvgPicture.asset('assets/profile/$icon.svg'),
const SizedBox(
width: 10,
),
Text(
title,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
fontFamily: GoogleFonts.poppins().fontFamily),
)
],
),
const SizedBox(
height: 20,
),
child
],
),
),
Positioned(
right: 10,
child: GestureDetector(
onTap: onEditPressed,
child: SvgPicture.asset('assets/profile/edit_pen.svg')),
)
],
);
Thanks for your help
Try this,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.black38,
Colors.black12,
Colors.black12,
Colors.black38,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
Change Colors.black38 & Colors.black12 with your desired colors.

Flutter Stack's child is transparent while using linear gradient

I am using a stack, where the save 60% off widget is on top of the container with white background. I am using gradient on the discount container. I want the gradient to be solid , but as you can see in the image, it is semi-transparent and we can see the white background under it.
My stack code is:
Container(
width: width * 0.38,
height: 250,
child: Stack(
children: [
Positioned(
top: 20,
child: InkWell(
onTap: () {},
child: Container(
width: width * 0.38,
height: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 35.h),
buildProductPrice(product, _intros),
buildCheckMark(product),
],
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: buildDiscountText(product, _intros)),
],
),
);
buildDiscountText widget:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue.withOpacity(0.8),
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);
To get solid background I could wrap buildDiscountTextWidget with Container and provide same gradient and do this 2,3 times but I don't think that is the proper way.
here is the screen shot of the widget
You just need to remove .withOpacity(0.8) from the end of Colors.lightBlue.withOpacity(0.8)
Change buildDiscountText widget as follows:
return Container(
height: 40,
width: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.lightBlue, //remove opacity
Color(0xffCE41FD),
],
end: Alignment.centerRight,
begin: Alignment.centerLeft,
),
borderRadius: BorderRadius.circular(20)),
child: Text(
'SAVE $_rounded %',
style: _saveTextStyle,
),
);