Search code examples
formsfluttertextinput

Textinputfield background shape and floating hint in flutter


I have a TextFormField with background shape as shown in image. But the problem I am having is, the hint is floating on top of field because I have used enabled border(OutlineInputBorder) to provide bg shape and color.

But I need to design the hint just above the text as shown in image. The code I wrote is as below...

new Theme(
  data: new ThemeData(
    primaryColor: Colors.green,
  ),
  child: new TextFormField(
    style: new TextStyle(
      color: Color(0xff651515),
    ),
    autofocus: false,
    obscureText: false,
    controller: date_picker,
    decoration: InputDecoration(
      suffixIcon: new Image.asset(
        'assets/calendar_ic.png',
      ),
      enabledBorder: new OutlineInputBorder(
        borderSide: BorderSide(color: Colors.black38),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(10),
          bottomLeft: Radius.circular(10),
          bottomRight: Radius.circular(10),
          topRight: Radius.circular(0)),
      ),
      filled: true,
      fillColor: Colors.black12,
      labelText: TextDisplayConstants.ENTER_DATE,
      labelStyle: TextStyle(
        color: Colors.black45,
        fontSize: 14,
      ),
    ),
  ),
),

https://i.sstatic.net/Qh4ie.png Image for reference

https://i.sstatic.net/zocff.png My result


Solution

  • Finally got the solution as expected using the below code:

                    Material(
                      color: Color(0xFFF8F8F8),
                      shape: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.transparent),
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(10),
                            bottomLeft: Radius.circular(10),
                            bottomRight: Radius.circular(10),
                            topRight: Radius.circular(0)),
                      ),
                      child: Padding(
                        padding: const EdgeInsets.fromLTRB(15, 0, 0, 0),
                        child: FormBuilderDropdown(
                          isExpanded: false,
                          decoration: InputDecoration(
                            labelText: TextDisplayConstants.SELECT_SUBJECT,
                            labelStyle: TextStyle(
                                fontFamily: 'BasisGrotesquePro',
                                fontWeight: FontWeight.w200,
                                color: Color(0xffb7b7b7)),
                            suffixIcon: new Image.asset(
                              'assets/subject_ic.png',
                            ),
                            hintStyle: new TextStyle(color: Colors.grey),
                            border: InputBorder.none,
                          ),
                          initialValue: _subjectList[0],
                          onChanged: (val) {
                            model.subject = val.id;
                          },
                          validators: [FormBuilderValidators.required()],
                          items: _subjectList.map((SubjectResponse subject) {
                            return new DropdownMenuItem<SubjectResponse>(
                              value: subject,
                              child: new Text(
                                subject.subject,
                                style: new TextStyle(
                                  fontFamily: 'BasisGrotesquePro',
                                  fontWeight: FontWeight.w400,
                                  color: Color(0xff651515),
                                ),
                              ),
                            );
                          }).toList(),
                        ),
                      ),
                    ),
    

    Thanks for all those who responded. If anyone founds helped by this solution, its my pleasure...