i want to build a blur effect on my modal bottom screen with bottomNavigationBar property, i already set the LinearGradient color with 0.5 opacity and extendBody: true in scaffold but nothing works, the blur in the modal just won't go transparent
this is the build widget
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kWhiteGreyColor,
extendBody: true,
bottomNavigationBar:_buildSeeMore(),
);
}
this is the blur widget
Widget _buildSeeMore() {
return Container(
width: double.infinity,
height: 315,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
kWhiteColor.withOpacity(0.5),
kWhiteColor,
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {},
child: Text(
'See More',
style: TextStyle(
color: kBlueColor,
fontSize: 16,
fontWeight: semiBold,
),
),
),
],
),
);
}
if you want to do blur effect please use backDropFilter widget and in container give color transparent
Related
I want the first widget to be transparent and display the colors of the third widget. on the third widget there is an animation with changing colors
You can use a ColorFiltered for that.
Stack(
alignment: Alignment.center,
children: [
Container(
width: 300,
height: 300,
color: Colors.green,
),
Material(
clipBehavior: Clip.antiAlias, // make sure the filter is restricted
color: Colors.transparent,
child: SizedBox(
width: 150,
height: 150,
child: ColorFiltered(
colorFilter: ColorFilter.mode(
Colors.black, // Color of the box, must be same color as text color used below
BlendMode.xor,
),
child: Center(
child: Text(
'test',
style: TextStyle(
fontSize: 32,
color: Colors.black, // Same color as filter color used above
),
),
),
),
),
),
],
);
The BlendMode.xor will cut out everything with the same color within the current canvas, which is the Material widget above it.
Try the opacity widget: https://api.flutter.dev/flutter/widgets/Opacity-class.html
Opacity(
opacity: 0.5,
child: ...,
)
Widget build(BuildContext context){
var height2 = AppBar().preferredSize.height;
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: <Widget>[
Image(
image: AssetImage("assets/oral_structure.png"),
fit: BoxFit.fill
),
Padding(
padding: EdgeInsets.only(top:100, left: 100),
child: Container(
height: 60,
width: 60,
child: FlatButton(
child: Text('ㅂ', style: TextStyle(fontSize: 30,fontWeight: FontWeight.bold)),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => B()),);
},
)
),
),
Above is part of my code. The app I'm making is where the appropriate button is placed on top of the background image. However, if you make the code above, the position of the button and the position of the image are different depending on the screen size of the smartphone. The same goes for fixing the height and width. How come there is no way?
#override
Widget build(BuildContext context) {
return Scaffold(
key: v.scaffoldKey,
body: Stack(
children: [
getBackgroundLight(),
],
),
);
}
Widget getBackgroundLight() {
return Stack(
children: [
Image.asset('assets/background.jpg', width: double.infinity),
Transform.rotate(
angle: -SizeConfig.calculateBlockVertical(180) *
(math.pi / SizeConfig.calculateBlockVertical(180)),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.center,
end: Alignment.bottomCenter,
colors: [
Get.theme.scaffoldBackgroundColor,
Get.theme.scaffoldBackgroundColor.withOpacity(0.5),
],
),
),
),
),
],
);
}
I trying to create a gradient button in flutter but in ElevatedButton shows some shadow or its strucuture there even when the color was set to transparent.
Here I have used DecoratedBox for applying gradient color is there any way to apply gradient in ElevatedButton?
The Code I have used
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.red,
Colors.blue,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)),
child: ElevatedButton(
onPressed: () {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (BuildContext context) => RegisterScreen()));
},
style: ElevatedButton.styleFrom(
primary: Colors.transparent,
onPrimary: Colors.transparent),
child: Text(
"Register",
style: TextManager.btnText,
)),
),
by setting elevation to 0 resolved but when I click the button the thing is also visible. Setting splash color to transparent also didn't work.
The output button is here
You can simply wrap your child property with an Ink widget. By doing so you will be able to apply a gradient and keep the elevated effect from the button.
Code Sample
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(0.0),
elevation: 5,
),
onPressed: () {},
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.blue, Colors.cyan]),
),
child: Container(
padding: const EdgeInsets.all(10),
constraints: const BoxConstraints(minWidth: 88.0),
child: const Text('OK', textAlign: TextAlign.center),
),
),
);
}
}
Screenshot
Try the full test code on DartPad
How to make soft keyboard covers/overlaps other widgets instead of pushing them up which causes the UI to go crazy and pixels overflow?
I tried with and without Stack()
I tried with and without resizeToAvoidBottomInset: false,
But still no result!
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Stack(
children: <Widget>[
ClipPath(
clipper: CustomBackgroundClipper(),
child: Container(
height: 220.0,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
gradientStart,
gradientEnd
],
),
),
),
),
Container(
height: MediaQuery.of(context).size.height,
child: HomeTopContainer(),
),
],
),
),
);
}
}
Just add this in Scaffold :
resizeToAvoidBottomInset: false,
I don´t know what is inside your HomeTopContainer, but like this way, its working to me:
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
children: <Widget>[
ClipPath(
child: Container(
height: 220.0,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.green, Colors.blue],
),
),
),
),
Container(
height: MediaQuery.of(context).size.height,
child: Align(
alignment: Alignment.bottomCenter,
child: Column(
children: <Widget>[
Spacer(),
Container(
height: 30,
color: Colors.red,
),
TextField()
],
),
),
),
],
),
);
}
}
I would suggest removing the Align widget completely and adding mainAxisAlignment and crossAxisAlignment properties to your Column widget.
How can i apply a gradient like here to the app background? Can you see the gradient moving down on that the app bar and the scaffold body just like they were one widget and not 2 widgets that each has his own color?
You need to use container as background to your scaffold to add a gradient. You can use Opacity widget as well to make container or any widget transparent. But here is the exact solution what you are looking for:
Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF282a57), Colors.black],
begin: Alignment.topCenter,
end: Alignment.bottomCenter),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(20, 50, 20, 0),
child: Container(
child: Row(
children: <Widget>[
Icon(Icons.menu,color: Colors.white,),
Spacer(),
Text("Expense",style: TextStyle(color: Colors.white,fontSize: 18,)),
Spacer(),
Icon(Icons.clear, color: Colors.white,)
],
),
),
),
],
),
)