Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to return a form widget in futureBuild in flutter

I have this code as am trying to code something to update data in firestore.

  @override
  Widget build(BuildContext context) {
    // Use the Todo to create the UI.
    return Scaffold(
      appBar: AppBar(
        title: Text(mid.toString()),
      ),
      body: FutureBuilder<Member?>(
        future: readMember(mid),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            final member = snapshot.data;


          /// return a form



          } else {
            return const Center(child: CircularProgressIndicator());
          }
        },
      ),
    );
  }

if snapshot hasData I want to return a form like this

Card(
          child: Row(
        children: <Widget>[
          TextField(
            controller: controllerName,
            decoration: decoration('name'),
          ),
          const SizedBox(height: 24),
          TextField(
            controller: controllerAge,
            decoration: decoration('Age'),
            keyboardType: TextInputType.number,
          ),
          const SizedBox(height: 24),
          ElevatedButton(
            child: const Text('Create'),
            onPressed: () {},
          ),
        ],
      ));

All my attempt yield no success please I need help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Check others state like error or if the data is null or not

builder: (context, snapshot) {
  if (snapshot.hasError) {
    return Text("Got Error");
  }
  if (snapshot.data == null) {
    return Text("No data");
  }
  if (snapshot.hasData) {
    final member = snapshot.data;
    return Card( ///here form
        child: Row(
      children: <Widget>[],
    ));
  } else {
    return const Center(child: CircularProgressIndicator());
  }
},

And provide width on TextFiled to fix overflow, TextFiled and row are trying to get infinite with.
just wrap with Expanded

Expanded(child: TextField(...)),

You can find more about unbound height& width

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading