How to create a button in Neumorphism which is clickable? - flutter

So far I can only get the design part but not implement the onPressed or clicked part. When it is pressed I want it to behave live a normal Elevated or raised button.
I can use GestureDetecter and use the onTap function, but how to animate it like its been actually pressed ?
Here is the code so far
Container(
width: 200,
height: 50,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.grey[400],
blurRadius: 20,
offset: Offset(0, 10),
),
BoxShadow(
color: Colors.white,
blurRadius: 20,
offset: Offset(0, -10),
),
],
),
child: Center(
child: Text('Button'),
),
onPressed: () {
// Show the text panel here
},
)

You can use TextButton widget wrap with your Container widget. just like this.
Container(
width: 200,
height: 50,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.grey[400]!,
blurRadius: 20,
offset: const Offset(0, 10),
),
const BoxShadow(
color: Colors.white,
blurRadius: 20,
offset: Offset(0, -10),
),
],
),
child: TextButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Colors.white)),
onPressed: () {
// Button tap action.
},
child: const Text('Elevated Button'),
),
)

There is a package that contains all the Neumorphism widgets in it "flutter_neumorphic"(https://pub.dev/packages/flutter_neumorphic)
First, install and import the package then you should use NeumorphicButton(there are many properties in this widget with which you can modify and get the effect you want, To learn more about it visit "flutter_neumorphic" offical website) : -
NeumorphicButton(
onPressed: () {},
child: const Text("Click me"),
),
Output :-

Related

I want button like a this. but I can not set border or width

I want like a this button
but I can not make it
Please tell me that how to make about
I did tryed code
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
backgroundColor: Colors.lightBlue[400],
side:BorderSide(width: 2, color: Colors.black)),
result
Container(
height: 50,
width: 200,
decoration: BoxDecoration(
color: Color(0xff92fcd1),
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(100),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black,
offset: Offset(2.5, 2.5),
spreadRadius: 0.1
)
],
),
child: Center(
child: Text('LOGIN'),
)
),
Container(
width: 100,
height: 30,
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Colors.black,
),
color: const Color(0xff93fbd1),
borderRadius: BorderRadius.circular(15),
boxShadow: const [
BoxShadow(
color: Colors.black,
blurRadius: 1,
offset: Offset(1, 2), // Shadow position
),
],
),
child: TextButton(
child: const Text(
'LOGIN',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.black,
fontWeight: FontWeight.bold),
),
onPressed: () {
// TODO: button onTap events
},
),
);
I usually create the buttons myself, you can add more features
Card(
elevation: 8,
color: Color.fromARGB(255, 132, 255, 199),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(width: 2)),
child: InkWell(
borderRadius: BorderRadius.circular(15),
onTap: () {},
child: Container(
padding:
EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
child: Text(
"LOGIN",
style: TextStyle(fontWeight: FontWeight.w700),
))),
)
I create this button with complete all of your need, having the box shadow, italic login, responsive design base on device width.
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {},
child: Container(
width: MediaQuery.of(context).size.width * 0.4,
height: MediaQuery.of(context).size.height * 0.05,
decoration: BoxDecoration(
color: const Color(0xff92fcd1),
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(100),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.7),
spreadRadius: 2,
offset:
const Offset(2, 2), // changes position of shadow
),
],
),
child: const Center(
child: Text("Login",
style: TextStyle(
fontStyle: FontStyle.italic, color: Colors.black)),
),
),
)
and here is the result

Design this Button in Flutter?

How can I design this kind of button in flutter?
You can use elevated button with transparent color and white border and shadow
Try below code hope its help to you.
Container(
padding: EdgeInsets.all(10),
height: 80,
width: 200,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(80),
),
child: InkWell(
onTap: () {
//Write your onPressed function here
print('Button Pressed');
},
child: Card(
color: Colors.teal[100],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(70),
),
child: Center(
child: Text(
'Sign In',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
),
),
Your result screen->
Here you go, adjust to your needs:
Container(
color: Color.fromRGBO(133,208,212,1),
padding: const EdgeInsets.all(15),
child: Container(
padding: EdgeInsets.all(8),
decoration: ShapeDecoration(
shape: StadiumBorder(),
color: Color.fromRGBO(133,208,212,1),
shadows: <BoxShadow>[
BoxShadow(
color: Colors.white,
spreadRadius: 8,
blurRadius: 3,
offset: Offset(0, 0),
),
BoxShadow(
color: Colors.grey.shade300,
spreadRadius: 3,
blurRadius: 3,
offset: Offset(5, 2),
),
],
),
child: Text(
'Sign in',
style: TextStyle(color: Colors.white),
),
),
),
The first Container is there just to highlight it's child, so it's not important

Flutter how to add box-shadow or drop-shadow onto text input field?

I don't think this is possible but thought I would ask and see if anyone has a solution for this I want to add box-shadow or drop-shadow onto the text input field but I don't want it to get messed up when using error text or hint text. Attached screenshot showing the issue. I tried Material, Physical Mode, Container still getts messed I don't think there is a way as error text is inside the input widget, and once it shows the height grows.
Maybe You Could Try This One
Padding(
padding: const EdgeInsets.only(
left: 16, right: 16, bottom: 16, top: 8),
child: Container(
height: 48,
decoration: BoxDecoration(
color: Colors.red.shade300,
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.withOpacity(0.6),
blurRadius: 8,
offset: const Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
yourfunction();
},
child: Center(
child: loadingButton
? SizedBox(
height: 30.0,
width: 30.0,
child: CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation(Colors.white),
),
)
: Text(
'Apply',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 18,
color: Colors.white),
),
),
),
),
),
)
This is probably not the most elegant way, but you could tinker with something like this:
Stack(
children: [
Container(
height: 40.0,
width: 200.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
spreadRadius: 4,
blurRadius: 12,
offset: Offset(0, 8),
),
],
),
),
Container(
width: 200.0,
child: TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Name',
errorText: 'Field cannot be empty',
),
),
),
],
);

Best way to add a shadow and colored border to ClipRRect using flutter

I have a simple ClipRRect widget as the below one:
#override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: GridTile(
child: Image.network(
imageUrl,
fit: BoxFit.cover,
),
footer: GridTileBar(
backgroundColor: Colors.black87,
leading: IconButton(
icon: Icon(Icons.favorite),
color: Theme.of(context).accentColor,
onPressed: () {},
),
title: Text(
title,
textAlign: TextAlign.center,
),
trailing: IconButton(
icon: Icon(Icons.shopping_cart),
onPressed: () {},
color: Theme.of(context).accentColor,
),
),
),
);
}
I tried to add a shadow by wrapping this widget with another Card widget to add a shadow with an elevation as the below code:
#override
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 5,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: GridTile(
child: Image.network(
imageUrl,
fit: BoxFit.cover,
),
footer: GridTileBar(
backgroundColor: Colors.black87,
leading: IconButton(
icon: Icon(Icons.favorite),
color: Theme.of(context).accentColor,
onPressed: () {},
),
title: Text(
title,
textAlign: TextAlign.center,
),
trailing: IconButton(
icon: Icon(Icons.shopping_cart),
onPressed: () {},
color: Theme.of(context).accentColor,
),
),
),
),
);
}
but I think it's not logical at all because it shows the grid item a bit smaller, and also I need add a border in this grid..
I hope this would be clear enough..
you can create your widget to take in a shadow and border colors as follows
since ClipRRect cant take in shadow or border color we use a container
clipRRect constructor
ClipRRect({Key key, BorderRadius borderRadius: BorderRadius.zero, CustomClipper<RRect> clipper, Clip clipBehavior: Clip.antiAlias, Widget child})
.
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
height: 200,
width: 200,
child: Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(10),
topRight: Radius.circular(10)),
side: BorderSide(width: 2, color: Colors.green)),
child: Center(
child: Icon(
Icons.movie,
size: 150.0,
),
),
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.white54,
blurRadius: 5.0,
offset: Offset(0, 10),
spreadRadius: 0.5,
),
],
borderRadius: BorderRadius.circular(12),
),
);
}
}
Here's another solution which worked for me.
Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: SizedBox(
child: ImageWidget(imageUrl),
width: 100,
height: 100,
),
),
width: 100,
height: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.15),
blurRadius: 8,
spreadRadius: 6,
offset: const Offset(0, 0),
),
],
),
)
I implemented it like below
Stack(alignment: Alignment.center, children: [
Container(
width: DeviceUtils.getScaledHeight(context, 0.072),
height: DeviceUtils.getScaledHeight(context, 0.072),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(8),
boxShadow: [
BoxShadow(
color: Colors.white54,
blurRadius: 5.0,
offset: Offset(0, 10),
spreadRadius: 0.5,
),
],
),
),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: ImageFromURL(
url: "https://i.pinimg.com/originals/63/81/a7/6381a77565b51a541d0d85cb145e7d94.jpg",
width: DeviceUtils.getScaledHeight(context, 0.07),
height: DeviceUtils.getScaledHeight(context, 0.07)),
),
])

How to rotate material icon in flutter without animation?

I want the icon details to point upward like as shown in the image.
but the list of material icon has icon details points to downward,
so how can I rotate the material icon in my flutter project, without downloading the icon image.
Column(
children: <Widget>[
Container(
height: 48,
decoration: BoxDecoration(
color: Color(0xFFFBBC05),
borderRadius: BorderRadius.circular(48),
boxShadow: [
BoxShadow(
blurRadius: 16,
offset: Offset(0, 8),
color: Color(0XFFFBBC05),
spreadRadius: -10)
]),
child: IconButton(
icon: Icon(
Icons.details,
color: Colors.white,
),
onPressed: null,
),
),
SizedBox(
height: 8,
),
Text(
"Historical",
style: TextStyle(fontFamily: 'AirbnbCerealMedium', fontSize: 12),
),
],
)
You can wrap your IconButton in a Transform widget using the rotate constructor:
import 'dart:math' as math;
Transform.rotate(
angle: 180 * math.pi / 180,
child: IconButton(
icon: Icon(
Icons.details,
color: Colors.white,
),
onPressed: null,
),
),
Another solution is:
RotatedBox(
quarterTurns: 2,
child: IconButton(
icon: Icon(
Icons.details,
color: Colors.white,
),
onPressed: null,
),
),
Transform.rotate(
angle: 180 * pi / 180,
child: IconButton(
icon: Icon(
Icons.details,
color: Colors.white,
),
onPressed: null,
),
),
If you want to rotate icons like arrow_forward_ios, could help following code.
icon: Transform.rotate(
angle: 90 *math.pi /180,
child: Icon(Icons.arrow_forward_ios,
color: Colors.white,size: 18,),,
One solution could be to use the Transform widget.
Column(children: <Widget>[
Container(
height: 48,
decoration: BoxDecoration(
color: Color(0xFFFBBC05),
borderRadius: BorderRadius.circular(48),
boxShadow: [
BoxShadow(
blurRadius: 16,
offset: Offset(0, 8),
color: Color(0XFFFBBC05),
spreadRadius: -10)
]),
child: Transform( //<--- This changed
transform: Matrix4.rotationX(90),
child: IconButton(icon: Icon(Icons.details), onPressed: () {})),
),
SizedBox(
height: 8,
),
Text(
"Historical",
style: TextStyle(fontFamily: 'AirbnbCerealMedium', fontSize: 12),
),
])