I'm trying to make this in flutter:
And my actual result:
My code is this:
new Container(
height: 150.0,
margin: const EdgeInsets.only(top: 16.0, bottom: 8.0),
child: new Stack(
children: <Widget>[
recantoCard,
recantoThumbnail,
],
),
)
final recantoThumbnail = new Container(
alignment: new FractionalOffset(0.0, 0.5),
margin: const EdgeInsets.only(left: 5.0, top: 10),
child: new Image(
image: new AssetImage("assets/nossos_restaurantes.png"),
height: 350.0,
),
);
final recantoCard = new Container(
margin: const EdgeInsets.only(left: 0.0, right: 48.0),
decoration: new BoxDecoration(
color: Color(getColorHexFromStr("E5E6E8")),
shape: BoxShape.rectangle,
),
child: new Container(
margin: const EdgeInsets.only(top: 10.0, left: 170.0),
constraints: new BoxConstraints.expand(),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text("text",
style: TextStyle(
color: Colors.black,
fontFamily: 'Poppins',
fontWeight: FontWeight.w600,
fontSize: 20.0)),
new Text("texto:",
style: TextStyle(
color: Colors.black,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 17.0)),
],
),
),
);
The image is an .png file and i need to overpass it into a Container and Stack, but the image always stay into 150 height container. How i can overpass the container with the image?
To make your image overpass the container you have to use Matrix4.translationValues(double x, double y, double z) class.
Use this class to whenever you need to overpass
transform: Matrix4.translationValues(0.0, 60, 0.0),
Container(
height: 150.0,
color: Colors.red,
child: Center(
child:Container(
height: 130.0,
width: 130.0,
transform: Matrix4.translationValues(0.0, 60, 0.0),
child: Image.asset('assets/image.jpg'),
)
),
)
Related
So I am trying to have an image at the top followed by a list below it. Intially, the list is contracted. When the list expands, I want it to overlap the image.
Initial Position - here I want the image to be at the top
Final Position - this is correct
The Problem is - If I position the image to the top, the list also moves to the top (in the initial position) which is not what I want. Also, if I use a column to position the image at the top (and the list below it) then the list does not expand all the way up to the top; it stays (and expands) below the image.
#override
Widget build(BuildContext context) {
double maxHeight = MediaQuery.of(context).size.height;
return Scaffold(
//resizeToAvoidBottomInset: false,
//backgroundColor: Color(0xFFd8e3e3),
body: Align(
child: SingleChildScrollView(
//to avoid bottom overflow error
child: Padding(
padding: const EdgeInsets.fromLTRB(5, 20, 5, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Stack(
//fit: StackFit.loose,
//alignment: Alignment.center,
children: [
// Positioned(
// top: 0,
// left: 0,
// right: 0,
Align(
alignment: Alignment(0, -1),
child: Hero(
tag: "imageHero",
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
),
child: Image.asset(
'assets/images/punjabi_egg_curry1.jpeg',
//height: screenHeight * 0.3,
//width: double.infinity,
alignment: Alignment.topCenter,
),
),
),
),
// ),
Center(
child: new ClipRect(
child: new BackdropFilter(
filter:
new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: new Card(
color: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: new Center(
//child: GestureDetector(
//onTap: _updateSize,
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Column(
children: [
AnimatedContainer(
constraints: BoxConstraints(
maxHeight: maxHeight * 0.85),
height: _height,
duration: Duration(milliseconds: 300),
decoration: new BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(20),
//border: Border.all(color: Colors.black),
),
child: Steps(),
),
//),
ElevatedButton(
onPressed: _updateSize,
child: Text(buttonText),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(
vertical: 10,
horizontal: 20,
),
primary: kSilver,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(20),
),
onPrimary: Colors.black,
textStyle: TextStyle(
color: Colors.black,
fontSize: 22,
),
),
),
],
),
),
),
),
),
),
),
// ),
],
),
],
),
),
),
),
//),
);
}
}
Wrap that widget with Positioned(top:5, child: // your widget ),
Try below code hope its help to you change your image on your need
Container(
height: 500,
child: Stack(
children: [
Container(
width: 150,
height: 150,
margin: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
'assets/images/cycle.png',
),
),
),
),
Positioned(
top: 120,
left: 0,
right: 0,
child: Container(
height: 100,
child: ListView.builder(
itemCount: 20,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text("List - $index"),
);
},
),
),
),
],
),
),
Your Result Screen ->
I only want the image of container blurred (line:16). This is the code:
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 40, bottom: 20),
width: 250,
height: 450,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
boxShadow: [
BoxShadow(
blurRadius: 8,
offset: Offset(0, 2),
),
],
image: DecorationImage(
image: AssetImage(
Category_list[index]["background"]), //Blur this image
fit: BoxFit.cover),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
Category_list[index]["header"],
style: TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.w800,
),
),
),
Padding(
padding: const EdgeInsets.all(12.0),
child: Container(
width: 250,
height: 50,
//color: Colors.white,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.all(Radius.circular(10)),
),
child: TextButton(
onPressed: () => {},
child: Text(
"Chat",
style: TextStyle(color: Colors.black),
),
),
),
),
],
),
),
],
);
But to use BackdropFilter you have to use the child-property from the container but this would blur everything. Does anybody know how to only blur the image? Do I have to separate the image-widget from the rest? And if so how does it still cover the complete Stack?
You can use Stack() widget to show your title or anything on top of your blurred image.
Small sample example
Container(
height: 150,
width:150,
decoration: new BoxDecoration(
color:Colors.black,
image: new DecorationImage(
image: new NetworkImage('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKgi8mXs-MtRnwuZVUKo1BwTXnKIl--6qZPzWmT4k3BV1wlN-vMgV2BdICGGHlekwnkVk&usqp=CAU'),
fit: BoxFit.cover,
),
),
child: Stack(
children:[
new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
child: new Container(
decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
),
),
Text("Dog Name",style: TextStyle(fontSize: 22,),),
],
),
);
I am trying to achieve a shadow like this,
This is my attempt, but its not working:
SliverPadding(
padding: const EdgeInsets.only(top: 20, left: 10, right: 10),
sliver: SliverToBoxAdapter(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
child: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.red,
blurRadius:
20.0, // has the effect of softening the shadow
spreadRadius:
5.0, // has the effect of extending the shadow
offset: Offset(
20.0, // horizontal, move right 10
100.0, // vertical, move down 10
),
)
],
color: Colors.black,
),
height: 150,
width: MediaQuery.of(context).size.width,
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Container(
child: Center(
child: Text(
'Withdraw Money',
style: khomeStyle.copyWith(
fontSize: 18,
color: kWhite,
),
),
),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(14.0))),
height: 30,
width: 130),
)),
),
//Container(height: 90, color: Colors.red),
],
),
),
),
);
I cannot understand why isn't it working and the entire shadow is coming behind my Stack. Hoping someone can help me with this problem, I couldn't find a solution elsewhere.
My Goal is to create like this
i want my image to show in the white big container and the background
i tried to do that
Stack(
overflow: Overflow.clip,
alignment: AlignmentDirectional.topCenter,
fit: StackFit.loose,
children: <Widget>[
Container(
height: 458.4,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)
)
),
),
GFAvatar(
backgroundImage:AssetImage(url),
shape: GFAvatarShape.standard,
radius: 70,
borderRadius: BorderRadius.circular(20),
)
],
),
]
and not working it is stacken in the container only
try to use Positioned inside the Stack and make the overflow Overflow.visible
Stack(
overflow: Overflow.visible,
alignment: AlignmentDirectional.topCenter,
fit: StackFit.loose,
children: <Widget>[
Container(
height: 400.4,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.amberAccent,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20))),
),
Positioned(
top: -50,
child: CircleAvatar(
radius: 50,
backgroundImage:
NetworkImage('https://picsum.photos/250?image=2'),
),
)
],
)
I'm trying to implement a custom AppBar using a PreferredSize and a Card widget. Here is the result:
However, when I scroll down a bit, the AppBar layout is covering the background (which is the body part of the scaffold) like this:
See second screenshot:
The custom AppBar is covering everything that goes under it. Is there a way to prevent this?
By the way, these sample images came from a StreamBuilder widget attached to the body of the Scaffold.
Here is the code:
appBar: PreferredSize(
preferredSize: Size.fromHeight(50.0),
child: SizedBox(
height: 100.0,
child: Card(
elevation: 10.0,
color: Colors.white.withOpacity(0.8),
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.only(top: 30.0, left: 10.0, right: 10.0),
child: Stack(
children: <Widget>[
GestureDetector(
onTap: () {
_key.currentState.openDrawer();
},
child: Padding(
padding: const EdgeInsets.only(top: 9.0, left: 10.0),
child: Icon(FontAwesomeIcons.bars, color: Colors.grey[800]),
),
),
Padding(
padding: const EdgeInsets.only(top: 13.0, left: 50.0),
child: TextField(
decoration: InputDecoration.collapsed(
hintText: 'Search... ',
hintStyle: TextStyle(fontFamily: 'Monospace')
),
),
),
GestureDetector(
onTap: () {
_key.currentState.openEndDrawer();
},
child: Padding(
padding: const EdgeInsets.only(top: 9.0, left: 305.0),
child: Icon(FontAwesomeIcons.slidersH, color: Colors.grey[800]),
),
)
],
),
),
)
),
Thanks for your answers!
Instead of setting your PreferredSize appbar directly to the appBar property of the Scaffold, rather Stack it within the body. This code should work for your desired outcome.
Scaffold(
body: Stack(
children: [
Container(), // this is where your main body goes
Positioned(
top: 30,
left: 10,
right: 10,
child: PreferredSize(
preferredSize: Size.fromHeight(25.0),
child: Container(
color: Colors.white.withOpacity(0.0),
height: 50.0,
child: Card(
elevation: 10.0,
color: Colors.white.withOpacity(1),
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
GestureDetector(
onTap: () {
_key.currentState.openDrawer();
},
child: Padding(
padding: const EdgeInsets.only(top: 9.0, left: 10.0),
child: Icon(Icons.menu, color: Colors.grey[800]),
),
),
Padding(
padding: const EdgeInsets.only(top: 13.0, left: 50.0),
child: TextField(
decoration: InputDecoration.collapsed(
hintText: 'Search... ',
hintStyle: TextStyle(fontFamily: 'Monospace')
),
),
),
GestureDetector(
onTap: () {
_key.currentState.openEndDrawer();
},
child: Padding(
padding: const EdgeInsets.only(top: 9.0, left: 305.0),
child: Icon(Icons.star, color: Colors.grey[800]),
),
)
],
),
),
)
),
),
]
),
);
Sample out come: