100

I have a rounded textfield. It works well, but when the user taps on it, a grey color background appears. How can I disable that splash effect?

This is my code and result:

        new Container(
          margin: const EdgeInsets.only(left: 30.0, top: 60.0, right: 
         30.0),
          height: 40.0,
          decoration: new BoxDecoration(

          color: Colors.white,

            borderRadius: new BorderRadius.all(new Radius.circular(25.7))
          ),

          child: new Directionality(

              textDirection: TextDirection.ltr,
              child: new TextField(
                controller: null,
                autofocus: false,

                style:
                    new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
                decoration: new InputDecoration(
                  filled: true,

                  fillColor: Colors.white,
                  hintText: 'Username',
                  contentPadding: const EdgeInsets.only(
                      left: 14.0, bottom: 8.0, top: 8.0),
                  focusedBorder: OutlineInputBorder(
                    borderSide: new BorderSide(color: Colors.white),
                    borderRadius: new BorderRadius.circular(25.7),
                  ),
                  enabledBorder: UnderlineInputBorder(
                    borderSide: new BorderSide(color: Colors.white),
                    borderRadius: new BorderRadius.circular(25.7),
                  ),
                ),
              ))),

enter image description here

Hesam Rasoulian
  • 1,356
  • 3
  • 12
  • 18

4 Answers4

171

It looks like it's caused by the splash effect on the textfield. I couldn't find a way to disable it for that specific widget but you can make it transparent by wrapping your TextField in a Theme widget and setting the splashColor to transparent:

Theme(
  data: Theme.of(context).copyWith(splashColor: Colors.transparent),
  child: TextField(
    autofocus: false,
    style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
    decoration: InputDecoration(
      filled: true,
      fillColor: Colors.white,
      hintText: 'Username',
      contentPadding:
          const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.0),
      focusedBorder: OutlineInputBorder(
        borderSide: BorderSide(color: Colors.white),
        borderRadius: BorderRadius.circular(25.7),
      ),
      enabledBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.white),
        borderRadius: BorderRadius.circular(25.7),
      ),
    ),
  ),
);
Jordan Davies
  • 9,925
  • 6
  • 40
  • 51
  • If it is a `TextFormField` you will want to add the `errorBorder` field also in the similar line which will show incase if the text validation fails – Sisir Jan 23 '21 at 12:52
37

“Flutter Textfield background color”

*Change border color of TextField in flutter

TextFormField(
        decoration: InputDecoration(
          labelText: "Resevior Name",
          fillColor: Colors.white,
          focusedBorder:OutlineInputBorder(
            borderSide: const BorderSide(color: Colors.white, width: 2.0),
            borderRadius: BorderRadius.circular(25.0),
          ),
        ),
      )

text fieldform color flutter

TextField(
  style: TextStyle(color: Colors.red),
  decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)

Flutter TextFormField background color

TextFormField(
    decoration: InputDecoration(
        labelText: "Resevior Name",
        fillColor: Colors.white,
        filled: true, // dont forget this line
        ...
    )
    ...
)

Flutter textfield label color

labelStyle: TextStyle(
    color: Colors.white,
)

Color textfield text flutter

TextField(
  style: TextStyle(color: Colors.white),
  ...
)
Suresh B B
  • 1,387
  • 11
  • 13
13

use BorderSide.none as:

border: OutlineInputBorder(
    borderRadius: BorderRadius.circular(10.0),
    borderSide: BorderSide.none,
),
Community
  • 1
  • 1
Replicant
  • 156
  • 1
  • 4
2

It's 4 years old question and now many things have been changed in flutter but I will answer this questino because I recently went through a requirement like this and I bet this solution will work for everybody so let's get started. So as per my understanding you are having more than 1 text fields in your screen and you want change the color when you click to enter on different text fields. So it can be done in lot a different ways I will share the most intuitive way which I liked. Steps :- 1.make Color variables for every textFields which you are having in your screen. 2. Initialize default color in the InItState() {}. (for example I want my all fields with no color so I will Colors.transparent) 3. Make filled: True in your TextFormField. 4. set filledColor to variable which you created for the color for the particular textField. 5. change the value of variable for the onTap: event. So Now your noodles are ready, just go through the code after reading these steps.

import '../flutter_flow/flutter_flow_theme.dart';
import '../flutter_flow/flutter_flow_util.dart';
import '../flutter_flow/flutter_flow_widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:mask_text_input_formatter/mask_text_input_formatter.dart';
import 'package:provider/provider.dart';
import 'personal_info2by2_component_model.dart';
export 'personal_info2by2_component_model.dart';

class PersonalInfo2by2ComponentWidget extends StatefulWidget {
  const PersonalInfo2by2ComponentWidget({Key? key}) : super(key: key);

  @override
  _PersonalInfo2by2ComponentWidgetState createState() =>
      _PersonalInfo2by2ComponentWidgetState();
}

class _PersonalInfo2by2ComponentWidgetState
    extends State<PersonalInfo2by2ComponentWidget> {
  late PersonalInfo2by2ComponentModel _model;

  late AutovalidateMode firstNameAutoValidateMode;
  late AutovalidateMode lastNameAutoValidateMode;
  late AutovalidateMode emailAutoValidateMode;
  late AutovalidateMode phoneAutoValidateMode;
  late Color firstNameFocusColor;
  late Color lastNameFocusColor;
  late Color emailFocusColor;
  late Color phoneFocusColor;

  @override
  void setState(VoidCallback callback) {
    super.setState(callback);
    _model.onUpdate();
  }

  @override
  void initState() {
    super.initState();
    _model = createModel(context, () => PersonalInfo2by2ComponentModel());

    _model.firstNameTextFieldController ??= TextEditingController();
    _model.lastNameTextFieldController ??= TextEditingController();

    firstNameFocusColor = Colors.transparent;
    lastNameFocusColor = Colors.transparent;

     WidgetsBinding.instance.addPostFrameCallback((_) => setState(() {}));
  }

  @override
  void dispose() {
    _model.maybeDispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
   return Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(),
        child: Form(
          key: _model.formKey,
          //autovalidateMode: AutovalidateMode.disabled,
          child: Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              Padding(
                padding: EdgeInsetsDirectional.fromSTEB(0, 10, 0, 30),
                child: Text(
                  'Personal Details',
                  style: FlutterFlowTheme.of(context).bodyText1.override(
                        fontFamily: 'Poppins',
                        fontSize: 22,
                      ),
                ),
              ),
              TextFormField(
                controller: _model.firstNameTextFieldController,
                autovalidateMode: firstNameAutoValidateMode,
                autofocus: true,
                textCapitalization: TextCapitalization.words,
                obscureText: false,

                onTap: () {
                  setState(() {
                    firstNameFocusColor = Colors.yellow[50]!;
                    lastNameFocusColor = Colors.transparent;
                  });
                },
                decoration: InputDecoration(
                  fillColor: firstNameFocusColor,
                  filled: true,
                ),
              ),
              TextFormField(
                controller: _model.lastNameTextFieldController,
                autovalidateMode: lastNameAutoValidateMode,
                autofocus: true,
                textCapitalization: TextCapitalization.words,
                obscureText: false,
                onTap: () {
                  setState(() {
                    lastNameAutoValidateMode = AutovalidateMode.onUserInteraction;

                    firstNameFocusColor = Colors.transparent;
                    lastNameFocusColor = Colors.yellow[50]!;
                  });
                },
                decoration: InputDecoration(
                  filled: true,
                  fillColor: lastNameFocusColor,
                ),
              ),
            ],
          ),
        ),
      );
  }
}