Search code examples
flutterdartflutter-layout

How to make the text above the textformfield?


This is the design I want to make

enter image description here

This is my current design

enter image description here

I'm new to flutter. My question is how to make the text above the textformfield. I have searched on the internet and tried to do it but still no success. I don't know where else to go to solve my problem. I hope overflow is willing to help me.

This is my code:

Container(
                        width: double.infinity,
                        margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
                        padding: EdgeInsets.all(15),
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: Colors.transparent,
                            width: 1.0,
                          ),
                        ),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                SizedBox(
                                  height: 100,
                                  width: 100,
                                  child: Text('First Name'),
                                ),
                                SizedBox(
                                  width: 200,
                                  child: TextFormField(
                                    style: TextStyle(color: Colors.black),
                                    controller: firstName,
                                    onSaved: (String? value) {
                                      firstName.text = value!;
                                    },
                                    decoration: InputDecoration(
                                      border: OutlineInputBorder(),
                                      hintText: 'First Name',
                                      hintStyle: TextStyle(
                                          color: Colors.black, fontSize: 16),
                                    ),
                                  ),
                                ),
                              ],
                            )
                          ],
                        ),
                      )

Solution

  • 200px is too big and structure I will prefer

    Row
     -Expanded
       - Column (CrossAxisAlignment.startMainAxisSize.min,)
         - Text
         - TextFormField
      -Expanded
       - Column (CrossAxisAlignment.startMainAxisSize.min,)
         - Text
         - TextFormField
      -Expanded
       - Column (CrossAxisAlignment.startMainAxisSize.min,)
         - Text
         - TextFormField
    
     @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Column(
            children: [
              Container(
                padding: EdgeInsets.all(15),
                decoration: BoxDecoration(
                  border: Border.all(
                    color: Colors.transparent,
                    width: 1.0,
                  ),
                ),
                child: Row(
                  children: [
                    filed(),
                    filed(),
                    filed(),
                  ],
                ),
              )
            ],
          ),
        );
      }
    
      Expanded filed() {
        return Expanded(
          child: Padding(
            padding: EdgeInsets.all(8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Padding(
                  padding: EdgeInsets.only(bottom: 20),
                  child: Text('First Name'),
                ),
                TextFormField(
                  style: TextStyle(color: Colors.black),
                  onSaved: (String? value) {},
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: 'First Name',
                    hintStyle: TextStyle(color: Colors.black, fontSize: 16),
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    

    enter image description here