How can i set the outer blur like this? - flutter

So i want to achieve this transition color with flutter
There is a container that contain Text tile with blue color () that changing to transparent. Here is what i do so far. I'm trying to use stack and LinearGradient
return Stack(
children: [
InkWell(
onTap: () {},
child: AspectRatio(
aspectRatio: 16 / 9,
child: pageData.thumbnail == ""
? ThumnailError()
: CachedNetworkImage(
imageUrl: "https://via.placeholder.com/200x100",
placeholder: (context, url) => MyLoader(),
errorWidget: (context, url, error) => ThumnailError(),
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
),
),
),
Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(10.h),
decoration: BoxDecoration(
color: Colors.white,
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
AppColors.primary,
Colors.transparent,
],
stops: [
0.2,
0.33
]),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
color: AppColors.primary,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextLarge(
label: "Title",
color: Colors.white,
fontWeight: FontWeight.bold,
),
Row(
children: [
TextMedium(
label: "Category",
color: Colors.white,
),
SizedBox(
width: 10.w,
),
TextMedium(
label: pageData.duration ?? "",
color: Colors.white,
)
],
),
],
),
),
),
],
);
and here is the result
So how can i achieve the first image that i put above ? thanks in advance and sorry for my english

You can try ShaderMask to achieve the desired result.
Stack(
children: [
ClipRRect(
child: ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black
]
).createShader(bounds);
},
blendMode: BlendMode.darken,
child: Container(
width: 300,
height: 250,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/someimage.jpg'),
fit: BoxFit.cover,
),
)
))
)
]
);
ShaderMask Widget

Related

perform action when image is loaded while using CachedNetworkImage in flutter

Here, by action i mean, Loading other widgets aswell
I am using CachedNetworkImage package. And it takes some time for the image to load from the network. I want to exactly know when the image is totally loaded so that i can show my other widgets.
Problem: Image takes time to load but the text already gets displayed which looks unprofessional.
So is there any way to know when the image is completely loaded from network. i.e change from placeholder to image.
child: Stack(
children: [
CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 300),
imageUrl: image,
height: double.infinity,
fit: BoxFit.cover,
imageBuilder: (context, imageProvider) => Stack(children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: imageProvider, fit: BoxFit.cover))),
Container(
color: Colors.black.withOpacity(0.4),
)
]),
),
Padding(
padding: const EdgeInsets.only(left: 2.0, bottom: 2),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(title), <-- This gets displayed before image is loaded
),
Visibility(
visible: discount != 0,
child: Align(
alignment: Alignment.topRight,
child: Container(
margin: const EdgeInsets.only(top: 2, right: 2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(
begin: Alignment(-1.238, -1.313),
end: Alignment(3.464, 3.196),
colors: <Color>[
Color(0xfff9d423),
Color(0xfffc8e3a),
Color(0xffff4e50)
],
stops: <double>[0.038, 0.5, 0.928],
),
),
child: Text("$discount%"), <-- This gets displayed before image is loaded
),
),
)
],
),
You can put the Stack inside the imageBuilder of a CachedNetworkImage, so everything will be displayed only after the image is loaded.
SizedBox(
height: 100,
width: 100,
child: CachedNetworkImage(
fadeInDuration: const Duration(milliseconds: 300),
imageUrl: image,
height: double.infinity,
fit: BoxFit.cover,
imageBuilder: (context, imageProvider) => Stack(
children: [
Stack(children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(image: imageProvider, fit: BoxFit.cover))),
Container(
color: Colors.black.withOpacity(0.4),
)
]),
Padding(
padding: const EdgeInsets.only(left: 2.0, bottom: 2),
child: Align(
alignment: Alignment.bottomLeft,
child: Text(title),
),
),
Visibility(
visible: discount != 0,
child: Align(
alignment: Alignment.topRight,
child: Container(
margin: const EdgeInsets.only(top: 2, right: 2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: const LinearGradient(
begin: Alignment(-1.238, -1.313),
end: Alignment(3.464, 3.196),
colors: <Color>[Color(0xfff9d423), Color(0xfffc8e3a), Color(0xffff4e50)],
stops: <double>[0.038, 0.5, 0.928],
),
),
child: Text("$discount%"),
),
),
)
],
),
),
),

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

How to align circleAvatar over a background image

Here is my code..
Here I want CircleAvatar over that background image.
body: SingleChildScrollView(
child: Stack(
children: [
Column(
children: [
CircleAvatar(
backgroundImage: AssetImage('images/images.jpg'),
),
Image(
image: AssetImage('images/flutter.jpg'),
),
label('First Name'),
label('Second name'),
label('Email-id'),
label('Passowrd'),
label('Confirm passowrd'),
],
),
],
),
),
backgroundColor: Colors.white,
);
}
}
And one more thing how to give gradient to appBar.
Thanks in advance.!
Try
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/flutter.jpg'),
fit: BoxFit.cover,
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundImage: AssetImage('images/images.jpg'),
),
),
),
instead of
CircleAvatar(
backgroundImage: AssetImage('images/images.jpg'),
),
Image(
image: AssetImage('images/flutter.jpg'),
),
And for gredient app bar you can use https://pub.dev/packages/new_gradient_app_bar
Appbar widget doesn't have gradient option yet but you can add it like this:
appBar: AppBar(
centerTitle: true,
title: Text('title'),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Colors.red,
Colors.blue
])
),
),
)
You didn't use the stack as you need. you need to build stack under column with using position
SingleChildScrollView(
child: Column(
children: [
Stack(
children: [
SizedBox(
height: 200,
width: double.infinity,
child: Image(
image: AssetImage('images/profile.png'),
),
),
Positioned(
bottom: 0,
left: MediaQuery.of(context).size.width / 2 - 20,
child: CircleAvatar(
backgroundImage: AssetImage('images/profile.png'),
),
),
],
),
Text('First Name'),
Text('Second name'),
Text('Email-id'),
Text('Passowrd'),
Text('Confirm passowrd')
],
),
)

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"))
]
);
}

is it possible to make this method reusable for other classes if possible then let me know in flutter

i have implemented this in other statefull class but is show error as class display widget function but i want to display this function and make it reuseable for other classes aswell....................................................................
_openCustomDialog() {
showGeneralDialog(
transitionBuilder: (context, a1, a2, widget) {
return Transform.scale(
scale: a1.value,
child: Opacity(
opacity: a1.value,
child: AlertDialog(
backgroundColor: Colors.transparent,
actions: [
Column(
children: [
Container(
height: 310,
width: MediaQuery.of(context).size.width - 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
image: DecorationImage(
image: NetworkImage(img),
fit: BoxFit.fill,
)),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.blue[900],
Colors.blue[700],
Colors.transparent,
Colors.transparent,
// Colors.transparent
],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
child: Row(
children: [
Icon(
Icons.favorite_border_outlined,
color: Colors.white,
),
SizedBox(width: 12),
Icon(
Icons.download_outlined,
color: Colors.white,
)
],
),
),
],
),
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
gradient: LinearGradient(colors: [
Colors.blue[200],
Colors.blue[500],
Colors.blue[800]
])),
child: TextButton(
child: Text('back',
style: TextStyle(
fontSize: 13,
fontFamily: 'LobsterTwo Bold',
color: Colors.white)),
onPressed: () async {
Navigator.of(context).pop();
},
),
),
],
),
],
),
],
),
),
);
},
transitionDuration: Duration(milliseconds: 300),
barrierDismissible: true,
barrierLabel: '',
context: context,
pageBuilder: (context, animation1, animation2) {});
}
.......................................................................................................
3 options that requires renaming the function to not have the _ in the beginning
1- put it in a file by itself
2- put it at the end of the file (or outside your classes)
3- make it static (my least favorite solution)
You will need pass context as a parameter
openCustomDialog(BuildContext context) {