fluttertextfield

How to create a Textfield with filled color and different border?


I need to create a text file in Flutter with a filled color. However, it should have a border in the editing area and a white suffix icon. See the attached screenshot of the Figma design.

In the textfiled's fillColor property it fill whole textfiled.

Someone, please help to achieve this in flutter

enter image description here


Solution

  • As you required suffixIcon and Icon in same Row use Container like below

    Use FocusNode for change border color of Container while focus on TextField

    Color borderColorContainer = Colors.grey;
    final FocusNode focusNode = FocusNode();
    
      @override
      void initState() {
        super.initState();
        focusNode.addListener(() {
          setState(() {
            borderColorContainer = Colors.red;
          });
        });
      }
    
      @override
      void dispose() {
        focusNode.dispose();
        super.dispose();
      }
    

    Here is the Container

              Container(
                 decoration: BoxDecoration(
                 color: Colors.white,
                 border: Border.all(color: borderColorContainer, width: 0.5),
                            borderRadius: BorderRadius.circular(5)),
                  child: Row(
                         children: [
                            Expanded(
                              child: Padding(
                                padding: const EdgeInsets.all(3.0),
                                child: TextField(
                                  focusNode: focusNode,
                                  decoration: InputDecoration(
                                    suffixIcon: Icon(Icons.arrow_downward_outlined),
                                    focusedBorder: OutlineInputBorder(
                                      borderSide:
                                          BorderSide(color: Color(0xfff8f8f8)),
                                      borderRadius: BorderRadius.circular(5),
                                    ),
                                    enabledBorder: OutlineInputBorder(
                                      borderSide:
                                          BorderSide(color: Color(0xfff8f8f8)),
                                      borderRadius: BorderRadius.circular(5),
                                    ),
                                    filled: true, // Enables filled color
                                    fillColor: Color(0xfff8f8f8), // Background color
    
                                    hintText: 'Enter text',
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(width: 10),
                            Container(
                              padding: EdgeInsets.all(12), // Add padding if needed
    
                              child: Icon(
                                Icons.add,
                                color: Colors.blue, // Color of the icon
                              ),
                            ),
                            SizedBox(width: 10),
                          ],
                        ),
                      ),