how to blur bottom half of the screen in flutter - flutter

trying to blur the bottom half of the screen as no guideline or help available.
Requirement:-
i do not want to give specific width or height in backdrop filter child container.
what is already tried:
Stack(
fit: StackFit.expand,
children: [
Image.asset("assets/images/authpage.jpg",
height: double.infinity, width: double.infinity, fit: BoxFit.fill),
Positioned(
top: 500,
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Container(
alignment: Alignment.center,
color: Colors.black.withOpacity(0.1),
),
),
),
),
],
);
Also tried the shader mask but that will fill with colors and not the blur part.
Stack(
fit: StackFit.expand,
children: [
ShaderMask(
shaderCallback: (rect) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.white, Colors.transparent],
).createShader(Rect.fromLTRB(0, 0, rect.width, rect.height));
},
blendMode: BlendMode.dstIn,
child: Image.asset(
'assets/images/authpage.jpg',
height: 400,
fit: BoxFit.fill,
),
),
],
);

i have tried but its not the best
import 'package:flutter/material.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://images.unsplash.com/photo-1537734796389-e1fc293cf856?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=632&q=80",
))),
// color: Colors.blue,
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 2.0, sigmaY: 2.0),
child: Container(
// the size where the blurring starts
height: MediaQuery.of(context).size.height * 0.4,
color: Colors.transparent,
),
),
),
),
Positioned(child: Text("data"))
],
),
);
}
}

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%"),
),
),
)
],
),
),
),

how to make widget disappear when overflow

i have created spotify login UI by using align widget to make typing comfortable. but the image above doesn't disappear or get pushed like the align widget. is there a solution to remove the image or detect if an overflow occurs?
Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xff96979C), Color(0xff636669), Color(0xff25252D)],
stops: [0.2, 0.5, 0.8]
),
),
),
Positioned(
top: medias.viewPadding.top + medias.size.height * 0.1,
left: 0,
right: 0,
child: Container(
height: 200,
width: 200,
child: Image(
image: AssetImage('assets/spotify.png'),
fit: BoxFit.scaleDown,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: medias.size.height * 0.35,
child: Column(...),
),
),
],
),
Use column with the wrap of singleChildScrollView instead of the stack.
Something like this.
SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xff96979C), Color(0xff636669), Color(0xff25252D)],
stops: [0.2, 0.5, 0.8]
),
),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 50),
height: 200,
width: 200,
child: Image(
image: AssetImage('assets/spotify.png'),
fit: BoxFit.scaleDown,
),
),
Container(
height: medias.size.height * 0.35,
child: Column(...),
),
],
),
),
)

How to change image color?

How to change the image color?
original image :
expect :
code :
Center(
child: Container(
height: 181.0,
width: MediaQuery.of(context).size.width - 46.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFB3E2D6),
Color(0xFF18A2A5).withOpacity(0.5),
],
),
),
child: Stack(
children: [
Positioned(
right: -20,
bottom: 0,
top: 0,
child: Image.asset(
'assets/images/border_background.png',
width: 220,
height: 220,
fit: BoxFit.cover,
),
),
Positioned(
right: -5,
bottom: 0,
top: 0,
child: Image.asset(
'assets/images/lisa-removebg-preview.png',
height: 151,
width: 207,
fit: BoxFit.cover,
color: Color(0xFF7CD2CC), colorBlendMode: BlendMode.modulate,
),
)
],
),
),
),
I try to create widgets and change the image color in the widget. but, not identical to the expectation
could you help me to fix some problems with this design?
For this you can use the ColorFilitered widget.
Without ColorFilter
Image.network("https://myImage"),
output:
With ColorFilter
ColorFiltered(
colorFilter:
ColorFilter.mode(Colors.teal.withOpacity(0.7), BlendMode.color),
child: Image.network(
"https://myUrl",
),
);
output:
You can change the Color with its opacity as you can see and also the Blendmode, more on Blendmodes here

How to make the bar chart starts from the bottom to top in flutter?

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

How to do blur multiple images in a column?

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