flutter Error: Two TextField in a single Row Getting Error

Issue

I want two TextField in row then I am getting error.When I am using Row

I want two TextField in row then I am getting error.I want two TextField in row then I am getting error.I want two TextField in row then I am getting error.
I want two TextField in row then I am getting error.I want two TextField in row then I am getting error.
This is my code.

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

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

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

class _EnterDetailsState extends State<EnterDetails> {
  TextEditingController nameController =  TextEditingController();
  TextEditingController zipCodeController =  TextEditingController();
  TextEditingController cityController =  TextEditingController();
  TextEditingController stateController =  TextEditingController();
  TextEditingController countryController = TextEditingController();
  var _formKey = GlobalKey<FormState>();
  var CountryList = ["India", "USA", "Africa","England"];
  final focus = FocusNode();

  @override
  void initState() {
    _formKey = GlobalKey<FormState>();
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: MediaQuery.of(context).size.height,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/bg.png"),
            fit: BoxFit.cover,
          ),
        ),
        width: double.infinity,
        child: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: 80,
                ),
                Center(
                  child: Image.asset(
                    'assets/logo.png',
                    width: 115,
                    height: 80,
                  ),
                ),
                SizedBox(
                  height: 37,
                ),
                Center(
                  child: Text(
                    "We are keen to know\nabout you",
                    style: GoogleFonts.poppins(
                      fontSize: 26,
                      fontWeight: FontWeight.w600,
                      color: Colors.white,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),

                Padding(
                  padding: const EdgeInsets.fromLTRB(36, 0, 36, 0),
                  child: Form(
                    key: _formKey,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          height: 43,
                        ),

                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "Enter Full Name",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),
                        Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)),
                          child: TextFormField(
                            controller: nameController,
                            textAlign: TextAlign.left,
                            keyboardType: TextInputType.text,
                            decoration: const InputDecoration(
                              fillColor: Colors.white,
                              hintText: 'Enter your Full Name',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius:
                                BorderRadius.all(Radius.circular(8.0)),
                                borderSide: BorderSide.none,
                              ),
                              filled: false,
                              contentPadding: EdgeInsets.all(16),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "Zip Code",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),
                        Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)),
                          child: TextFormField(
                            controller: zipCodeController,
                            obscureText: true,
                            textAlign: TextAlign.left,
                            keyboardType: TextInputType.number,
                            decoration: const InputDecoration(
                              fillColor: Colors.white,
                              hintText: 'Enter your Zip Code',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius:
                                BorderRadius.all(Radius.circular(8.0)),
                                borderSide: BorderSide.none,
                              ),
                              filled: false,
                              contentPadding: EdgeInsets.all(16),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "City",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),
                        Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)),
                          child: TextFormField(
                            controller: cityController,
                            textAlign: TextAlign.left,
                            keyboardType: TextInputType.text,
                            decoration: const InputDecoration(
                              fillColor: Colors.white,
                              hintText: 'Enter your city',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius:
                                BorderRadius.all(Radius.circular(8.0)),
                                borderSide: BorderSide.none,
                              ),
                              filled: false,
                              contentPadding: EdgeInsets.all(16),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "State",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),
                        Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)),
                          child: TextFormField(
                            controller: cityController,
                            textAlign: TextAlign.left,
                            keyboardType: TextInputType.text,
                            decoration: const InputDecoration(
                              fillColor: Colors.white,
                              hintText: 'Enter your state',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius:
                                BorderRadius.all(Radius.circular(8.0)),
                                borderSide: BorderSide.none,
                              ),
                              filled: false,
                              contentPadding: EdgeInsets.all(16),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "Country",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),

                        Container(
                          height: 50,
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)
                          ),
                          child: Padding(
                            padding: const EdgeInsets.only(left: 16.0, right: 8,top: 2),
                            child: Stack(
                              children: [
                                TextFormField(
                                  cursorColor: Colors.white,
                                  controller: countryController,
                                  enabled: true,
                                  validator: (value) {
                                    if (value!.length != 0) {
                                      return null;
                                    }
                                    return "please select country";
                                  },
                                  decoration: const InputDecoration(
                                      suffixIcon: Icon(Icons.keyboard_arrow_down),
                                      hintText: 'Country',
                                      hintStyle: TextStyle(fontSize: 16),
                                      border: UnderlineInputBorder(borderSide: BorderSide.none)),
                                  style: TextStyle(
                                      fontSize: 16,
                                      color: Colors.grey[900],),
                                ),
                                Container(
                                  color: Colors.transparent,
                                  width: MediaQuery.of(context).size.width,
                                  child: PopupMenuButton<String>(
                                    icon: const Icon(
                                      Icons.arrow_drop_down,
                                      color: Colors.transparent,
                                    ),
                                    onSelected: (String value) {
                                      setState(() {
                                        countryController.text = value;
                                      });
                                    },
                                    itemBuilder: (BuildContext context) {
                                      return CountryList
                                          .map<PopupMenuItem<String>>((String value) {
                                        FocusScope.of(context).unfocus();
                                        return new PopupMenuItem(
                                            child: Container(
                                                width: MediaQuery.of(context).size.width,
                                                child: new Text(value)),
                                            value: value);
                                      }).toList();
                                    },
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                        SizedBox(height: 16,),
                        SizedBox(
                          height: 48,
                          width: double.infinity,
                          child: ElevatedButton(
                            style: ButtonStyle(
                              elevation: MaterialStateProperty.all(0),
                              foregroundColor:
                              MaterialStateProperty.all<Color>(Colors.white),
                              backgroundColor: MaterialStateProperty.all<Color>(
                                  Color(0xFFF2A6A4)),
                              shape: MaterialStateProperty.all<
                                  RoundedRectangleBorder>(
                                RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(10),
                                  side: BorderSide(color: Color(0xFFF2A6A4)),
                                ),
                              ),
                            ),
                            onPressed: () {

                            },
                            child: Text(
                              'Sign Up',
                              style: GoogleFonts.poppins(
                                  fontSize: 14, color: Colors.white),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 42,
                        ),
                      ],
                    ),
                  ),
                ),
                
              ],
            ),
          ),
        ),
      ),
      bottomNavigationBar: Container(
        color: Color(0xff3a99a4),
        child: Container(
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(topLeft: Radius.circular(60))),
          width: double.infinity,
          height: 57,
          child: Center(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Already have an account? ',
                    style: GoogleFonts.poppins(fontSize: 14, color: Colors.black),
                  ),
                  GestureDetector(
                      onTap: () {

                        // Navigator.pushReplacement(
                        //   context,
                        //   MaterialPageRoute(
                        //     builder: (context) => LoginPage(),
                        //   ),
                        // );
                      },
                      child: Text(
                        "Let's Go",
                        style: GoogleFonts.poppins(
                            fontSize: 14, color: Color(0xFF158998)),
                      ))
                ],
              )),
        ),
      ),
    );
  }
}

In actuall i want to make like this enter image description here

but it is becoming

enter image description here

Solution

To have multiple items in a row you need to use Row() widget inside your Column and after that to get equal width for your inline widgets you need to use Expanded widget inside Row and then you can add another widget as child of Expanded. I have made changes in your code just copy and paste below code and observe the changes for next time.

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

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

class _EnterDetailsState extends State<EnterDetails> {
  TextEditingController nameController = TextEditingController();
  TextEditingController zipCodeController = TextEditingController();
  TextEditingController cityController = TextEditingController();
  TextEditingController stateController = TextEditingController();
  TextEditingController countryController = TextEditingController();
  var _formKey = GlobalKey<FormState>();
  var CountryList = ["India", "USA", "Africa", "England"];
  final focus = FocusNode();

  @override
  void initState() {
    _formKey = GlobalKey<FormState>();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: MediaQuery.of(context).size.height,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/bg.png"),
            fit: BoxFit.cover,
          ),
        ),
        width: double.infinity,
        child: SafeArea(
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: 80,
                ),
                Center(
                  child: Image.asset(
                    'assets/logo.png',
                    width: 115,
                    height: 80,
                  ),
                ),
                SizedBox(
                  height: 37,
                ),
                Center(
                  child: Text(
                    "We are keen to know\nabout you",
                    style: GoogleFonts.poppins(
                      fontSize: 26,
                      fontWeight: FontWeight.w600,
                      color: Colors.white,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.fromLTRB(36, 0, 36, 0),
                  child: Form(
                    key: _formKey,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          height: 43,
                        ),
                        Padding(
                          padding: const EdgeInsets.all(1.0),
                          child: Text(
                            "Enter Full Name",
                            style: GoogleFonts.poppins(
                              fontSize: 14,
                              color: Colors.white,
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 3.7,
                        ),
                        Container(
                          decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.circular(8)),
                          child: TextFormField(
                            controller: nameController,
                            textAlign: TextAlign.left,
                            keyboardType: TextInputType.text,
                            decoration: const InputDecoration(
                              fillColor: Colors.white,
                              hintText: 'Enter your Full Name',
                              hintStyle: TextStyle(fontSize: 16),
                              border: OutlineInputBorder(
                                borderRadius:
                                    BorderRadius.all(Radius.circular(8.0)),
                                borderSide: BorderSide.none,
                              ),
                              filled: false,
                              contentPadding: EdgeInsets.all(16),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Row(
                          children: [
                            Expanded(
                                child: Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(1.0),
                                  child: Text(
                                    "Zip Code",
                                    style: GoogleFonts.poppins(
                                      fontSize: 14,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 3.7,
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius: BorderRadius.circular(8)),
                                  child: TextFormField(
                                    controller: zipCodeController,
                                    obscureText: true,
                                    textAlign: TextAlign.left,
                                    keyboardType: TextInputType.number,
                                    decoration: const InputDecoration(
                                      fillColor: Colors.white,
                                      hintText: 'Enter your Zip Code',
                                      hintStyle: TextStyle(fontSize: 16),
                                      border: OutlineInputBorder(
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(8.0)),
                                        borderSide: BorderSide.none,
                                      ),
                                      filled: false,
                                      contentPadding: EdgeInsets.all(16),
                                    ),
                                  ),
                                ),
                              ],
                            )),
                            VerticalDivider(),
                            Expanded(
                                child: Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(1.0),
                                  child: Text(
                                    "City",
                                    style: GoogleFonts.poppins(
                                      fontSize: 14,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 3.7,
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius: BorderRadius.circular(8)),
                                  child: TextFormField(
                                    controller: cityController,
                                    textAlign: TextAlign.left,
                                    keyboardType: TextInputType.text,
                                    decoration: const InputDecoration(
                                      fillColor: Colors.white,
                                      hintText: 'Enter your city',
                                      hintStyle: TextStyle(fontSize: 16),
                                      border: OutlineInputBorder(
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(8.0)),
                                        borderSide: BorderSide.none,
                                      ),
                                      filled: false,
                                      contentPadding: EdgeInsets.all(16),
                                    ),
                                  ),
                                ),
                              ],
                            ))
                          ],
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        Row(
                          children: [
                            Expanded(
                                child: Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(1.0),
                                  child: Text(
                                    "State",
                                    style: GoogleFonts.poppins(
                                      fontSize: 14,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 3.7,
                                ),
                                Container(
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius: BorderRadius.circular(8)),
                                  child: TextFormField(
                                    controller: cityController,
                                    textAlign: TextAlign.left,
                                    keyboardType: TextInputType.text,
                                    decoration: const InputDecoration(
                                      fillColor: Colors.white,
                                      hintText: 'Enter your state',
                                      hintStyle: TextStyle(fontSize: 16),
                                      border: OutlineInputBorder(
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(8.0)),
                                        borderSide: BorderSide.none,
                                      ),
                                      filled: false,
                                      contentPadding: EdgeInsets.all(16),
                                    ),
                                  ),
                                ),
                              ],
                            )),
                            VerticalDivider(),
                            Expanded(
                                child: Column(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(1.0),
                                  child: Text(
                                    "Country",
                                    style: GoogleFonts.poppins(
                                      fontSize: 14,
                                      color: Colors.white,
                                    ),
                                  ),
                                ),
                                SizedBox(
                                  height: 3.7,
                                ),
                                Container(
                                  height: 50,
                                  decoration: BoxDecoration(
                                      color: Colors.white,
                                      borderRadius: BorderRadius.circular(8)),
                                  child: Padding(
                                    padding: const EdgeInsets.only(
                                        left: 16.0, right: 8, top: 2),
                                    child: Stack(
                                      children: [
                                        TextFormField(
                                          cursorColor: Colors.white,
                                          controller: countryController,
                                          enabled: true,
                                          validator: (value) {
                                            if (value!.length != 0) {
                                              return null;
                                            }
                                            return "please select country";
                                          },
                                          decoration: const InputDecoration(
                                              suffixIcon: Icon(
                                                  Icons.keyboard_arrow_down),
                                              hintText: 'Country',
                                              hintStyle:
                                                  TextStyle(fontSize: 16),
                                              border: UnderlineInputBorder(
                                                  borderSide: BorderSide.none)),
                                          style: TextStyle(
                                            fontSize: 16,
                                            color: Colors.grey[900],
                                          ),
                                        ),
                                        Container(
                                          color: Colors.transparent,
                                          width:
                                              MediaQuery.of(context).size.width,
                                          child: PopupMenuButton<String>(
                                            icon: const Icon(
                                              Icons.arrow_drop_down,
                                              color: Colors.transparent,
                                            ),
                                            onSelected: (String value) {
                                              setState(() {
                                                countryController.text = value;
                                              });
                                            },
                                            itemBuilder:
                                                (BuildContext context) {
                                              return CountryList.map<
                                                      PopupMenuItem<String>>(
                                                  (String value) {
                                                FocusScope.of(context)
                                                    .unfocus();
                                                return new PopupMenuItem(
                                                    child: Container(
                                                        width: MediaQuery.of(
                                                                context)
                                                            .size
                                                            .width,
                                                        child: new Text(value)),
                                                    value: value);
                                              }).toList();
                                            },
                                          ),
                                        )
                                      ],
                                    ),
                                  ),
                                )
                              ],
                            )),
                          ],
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        SizedBox(
                          height: 16,
                        ),
                        SizedBox(
                          height: 48,
                          width: double.infinity,
                          child: ElevatedButton(
                            style: ButtonStyle(
                              elevation: MaterialStateProperty.all(0),
                              foregroundColor: MaterialStateProperty.all<Color>(
                                  Colors.white),
                              backgroundColor: MaterialStateProperty.all<Color>(
                                  Color(0xFFF2A6A4)),
                              shape: MaterialStateProperty.all<
                                  RoundedRectangleBorder>(
                                RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(10),
                                  side: BorderSide(color: Color(0xFFF2A6A4)),
                                ),
                              ),
                            ),
                            onPressed: () {},
                            child: Text(
                              'Sign Up',
                              style: GoogleFonts.poppins(
                                  fontSize: 14, color: Colors.white),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 42,
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
      bottomNavigationBar: Container(
        color: Color(0xff3a99a4),
        child: Container(
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.only(topLeft: Radius.circular(60))),
          width: double.infinity,
          height: 57,
          child: Center(
              child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Already have an account? ',
                style: GoogleFonts.poppins(fontSize: 14, color: Colors.black),
              ),
              GestureDetector(
                  onTap: () {
                    // Navigator.pushReplacement(
                    //   context,
                    //   MaterialPageRoute(
                    //     builder: (context) => LoginPage(),
                    //   ),
                    // );
                  },
                  child: Text(
                    "Let's Go",
                    style: GoogleFonts.poppins(
                        fontSize: 14, color: Color(0xFF158998)),
                  ))
            ],
          )),
        ),
      ),
    );
  }
}

Answered By – Diwyansh

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *