This website will be permanently discontinued and will no longer be accessible.
FINAL DAY OF SERVICE: 26 November 2024
Thank You for Your Support
Dear valued users,
We want to inform you that this website will be permanently shutting down. After this date, all services and content will no longer be accessible.
We sincerely thank you for your support and trust throughout our journey.
Important Dates:
Last Day: 26/11/2024
Data Access:Until the last day
Dear valued users,
We want to inform you that this website will be permanently shutting down. After this date, all services and content will no longer be accessible.
We sincerely thank you for your support and trust throughout our journey. Important Dates: Last Day: 26/11/2024 Data Access:Until the last day
Flutter: Add Drop Shadow to TextField OR TextFormField [Solved]
Your designer gives you a design with a lot of text input fields for login and contact forms.
That is OK.
But the problem is there is a shadow effect below these text fields.
How can you add these TextField or TextFormField shadows in flutter?
You can use a Material widget provided by the flutter framework.
OR
You can use a Container widget that has a shadow set in the decoration parameter.
Here, you’ll understand both methods. You can use any method according to your requirement which solves your problem.
In this Article
Add Shadow Using Material
Material widget is useful when you have to add clipping behavior, elevation, and Ink effect to the children.
Material has an elevation property that takes double as an input. And add the shadow effect beneath the material based on that input value.
For changing the shadow color you use the shadowColor property of the material. Which takes the Color object as input.
For adding a drop shadow to flutter TextField or TextFormField you can use the Material widget. Just wrap TextField or TextFormField with Material widget and set elevation and shadow color.
The Container is the most common flutter layout widget. You normally use it to layout different parts of your flutter UI.
You can set padding, color, and different things using a Container. But when you go one step ahead with the Container you start using the decoration parameter for TextField elevation.
decoration property is useful when you want to paint behind the child widget. The decoration is a type of flutter painting abstract class of Decoration.
So in Decoration, you can pass different kinds of widgets like BoxDecoration, FlutterLogoDecoration, ShapeDecoration, UnderlineTableIndicator, etc.
Here in this example, your main purpose is to add shadow effect behind your TextField.
TextField visually represents a box and for that purpose, you use a BoxDecoration widget as a child. BoxDecoration supports different properties like border, color, gradient, etc.
But our concern for example is the use of the boxShadow property which will take a list of BoxShadow objects.
BoxShadow
Create a shadow that is displayed behind the box. According to docs.
This class is similar to CSS box-shadow.
You can pass color and set the offset value, blurRadius and spreadRadius.