How to do blur multiple images in a column? - flutter

I have tried the code from this https://medium.com/fluttervn/how-to-make-blur-effect-in-flutter-using-backdropfilter-imagefilter-559ffd8ab73. However its not having the effect I wanted.
children: <Widget>[
Card(
child: Stack(
children: <Widget>[
Stack(
children: <Widget>[
Center(
child: Image.asset(
'assets/image1.jpg',
fit: BoxFit.fill,
),
),
Container(
width: double.infinity,
height: 250,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 1.0, sigmaY: 1.0),
child: Container(
color: Colors.black.withOpacity(0.1),
),
),
)
],
),
Center(
child: Text('Image 1'),
)
],
),
),
Card(...),
Card(...),
],
I have tried wrapping each individual card into a container but the previous cards keep getting blurred even the text. I only want the images of each individual card to be blurred while the text remains clear.

I haven't test it but try to use instead of Image.asset the Container widget . As the example:
Container(
width:x,
height:y,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/image1.jpg'),
fit: BoxFit.cover,
),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 1.0, sigmaY: 1.0),
child: Container(
color: Colors.black.withOpacity(0.1),
),
),
Since every card is the same you can create a class as a constructor and u will just add CardTemplate('text 1', 'assets/image1.jpg'), when u need a card:
class CardTemplate extends StatelessWidget{
String image;
String text;
CardTemplate(this.text,this.image);
#override
Widget build(BuildContext context) {
return Card(
child:Stack(
children: <Widget>[
Stack(
children: <Widget>[
Center(
child: Container(
width: double.infinity,
height: 250,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(this.image),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 1.0, sigmaY: 1.0),
child: Container(
color: Colors.black.withOpacity(0.1),
),
),
)
),
Center(
child: Text(this.text),
)
],
),
);
}
}
Note I haven't tested the code so there will be maybe some syntax or typo errors

Related

ImageFilter.blur (BackdropFilter) Not working | Flutter

When i use BackdropFilter in Container's child, Phone screen going color black. and when i remove that coding. It shows background image. what's going wrong?
I want to blur my background image of app. No errors shows. but final render is black screen. no any image
Stack(
children: [
//background image here with blur
Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/u2.jpg'),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 10,
sigmaY: 10,
),
),
),
],),
Try to use BackdropFilter child
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/u2.jpg'),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 10,
sigmaY: 10,
),
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.0),
),
),
),
),
),
Test scaffold
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 200,
child: Stack(
children: [
Positioned.fill(
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/img.png'),
fit: BoxFit.cover,
),
),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: 10,
sigmaY: 10,
),
child: Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.0),
),
),
),
),
),
],
),
),
],
),
);

Texts visibly stacked on each other in flutter

Widget build(BuildContext context) {
return Swipable(
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * 0.57,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: Image.network(
widget.urls,
fit: BoxFit.cover,
),
),
),
),
),
Center(
child: Expanded(
child: Text(
widget.usernames,
maxLines: 1,
)),
)
],
),
//onSwipeLeft: () => _returnString(index),
);
}
}
This is my code and i've been adjusting and readjusting for over 3hrs.. I just need the text to show on the image that can be swiped. Please help me. Thanks
image:
Hello I think what you are needing is to use a Stack Widget instead of a Column widget. When using Stacks you can use a Positioned widget to indicate exactly where you want your child widgets to be displayed inside of the stack as well.
Widget build(BuildContext context) {
return Swipable(
child: Stack(
alignment: Alignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.57,
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(14),
child: Image.network(
widget.urls,
fit: BoxFit.cover,
),
),
),
),
),
Positioned(
top: 16,
right: 16,
child: Center(
child: Expanded(
child: Text(
widget.usernames,
maxLines: 1,
)),
),
)
],
),
//onSwipeLeft: () => _returnString(index),
);
}
}
Happy Coding!
You can use this way
Widget build(BuildContext context) {
return Column(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
widget.urls,
fit: BoxFit.cover,
),
),
height: MediaQuery.of(context).size.height * 0.57,
width: MediaQuery.of(context).size.height,
child: Align(
alignment: Alignment.bottomCenter,
child: Text(
widget.usernames,
style: TextStyle(color: Colors.orange),
),
),
),
],
);
//onSwipeLeft: () => _returnString(index),
}

Flutter container write text over background image

I want to make a design like following
I build the base layout with background image. Following is the code to achieve that. Now i want to put "Grocery store" Text on top of this image and other widgets. How can i do that ?
Widget build(BuildContext context) {
return Container(
height: 190.0,
width: size.width,
margin: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(https://www.exampledomain.com/images/background.jpg),
fit: BoxFit.cover,
),
),
// child: ????
),
),
],
),
),
],
),
);}
child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(https://www.exampledomain.com/images/background.jpg),
fit: BoxFit.cover,
),
),
child: Text('Grocery store'),
//padding: <-- Using to shift text position a little bit for your requirement
),
Stack/Align is your friend.
Take a look here https://api.flutter.dev/flutter/widgets/Stack-class.html
Here is a basic example (based in your code):
Widget build(BuildContext context) {
return Stack(
children: [
Align(
alignment: Alignment.center,
child: Container(
alignment: Alignment.center,
color: Colors.red,
height: 190.0,
width: size.width,
margin: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
Expanded(
child: Container(
width: size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(11.0),
image: DecorationImage(
image: NetworkImage(
"http://www.exampledomain.com/images/background.jpg"),
//fit: BoxFit.cover,
),
),
),
),
],
),
),
],
),
),
),
Align(
alignment: Alignment.center,
child: Text("Grocery store"))
]
);
}

SingleSChildScrollView moves up in IOS

I'm having a little issues with SingleChildScrollView in iOS.
the app works well on android but moves up in iphoneXr.
picture below.
Code follows.
backgroundColor: Color.fromRGBO(3, 9, 23, 13),
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
child: Container(
width: double.infinity,
child: Stack(
children: <Widget>[
Positioned(
top: -50,
left: 0,
child: Container(
width: width,
height: 1000,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/component.png'),
fit: BoxFit.fill,
),
),
child: new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 12.0, sigmaY: 12.0),
child: new Container(
decoration: new BoxDecoration(
color: Colors.white.withOpacity(0.0),
),
),
),
),
),
You should use a SafeArea to contain your SingleChildScrollView, like this:
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Container(),
),
),
);

Flutter- How to use image in container?

I am building an app and I am using a Container to design a card but here is a thing image should be 1/3 of the container and not fill up the entire container.
Here is the code for the container:
Container(
height: 240,
width: 160,
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage('images/rest.jpg'),fit: BoxFit.cover),
borderRadius: BorderRadius.all(Radius.circular(10)),
color: Color(0xFFFDEEDD),
),
child: Column(
children: <Widget>[
Text('Hello'),
Row(
children: <Widget>[
Text('World'),
Text('4.2'),
],
)
],
),
),
Card I am trying to replicate
I think it would be better to use a ClipRRect here instead. If you use material, you can also use ListTile :
return Material(
child: Center(
child: Container(
color: Colors.black12,
width: 250,
child: Column(
mainAxisSize: MainAxisSize.min,
children:[
ClipRRect(
child:Image.network("https://via.placeholder.com/250"),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
ListTile(
title: Text("The fifties"),
subtitle: Text("Subtitle"),
)
]
)
)
)
);