Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
913 views
in Technique[技术] by (71.8m points)

user interface - Flutter TextField add box shadow

I tried create TextField with shadow effect using Container like this:

enter image description here

Code:

Container(
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: new BorderRadius.circular(5.0),
    boxShadow: [
      BoxShadow(
        color: Colors.black12,
        spreadRadius: 1,
        blurRadius: 3,
      ),
    ],
  ),
  child: TextFormField(
    validator: (value) {
      if (value.isEmpty) {
        return 'Product title required';
      }
      return null;
    },
    decoration: InputDecoration(
      isDense: true,
      hintText: 'Product title',
      contentPadding: EdgeInsets.all(18.0),
      filled: true,
      fillColor: Colors.white,
      border: OutlineInputBorder(
        borderRadius: new BorderRadius.circular(10.0),
        borderSide: BorderSide.none,
      ),
    ),
    textAlign: TextAlign.start,
    maxLines: 1,
  ),
)

But when validation has error then error message shows inside Container which is incorrect in my case:

enter image description here

How I can create TextField like this shadow with correctly displaying error message and error border colors like this but with shadow:

enter image description here

question from:https://stackoverflow.com/questions/65879043/flutter-textfield-add-box-shadow

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to wrap it with "Material" widget

Material(
 elevation: 5,
 child: TextFormField(
    validator: (value) {
      if (value.isEmpty) {
        return 'Product title required';
      }
      return null;
    },
    decoration: InputDecoration(
      isDense: true,
      hintText: 'Product title',
      contentPadding: EdgeInsets.all(18.0),
      filled: true,
      fillColor: Colors.white,
      border: OutlineInputBorder(
        borderRadius: new BorderRadius.circular(10.0),
        borderSide: BorderSide.none,
      ),
    ),
    textAlign: TextAlign.start,
    maxLines: 1,
  ),
),

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...