-1

This is my backend data

This is my form screen

how can I get the control value of these dynamic fields

class DyDataList with ChangeNotifier {
  final List<DyData> _dyDataList = [
    DyData(
      filedName: "Full Name",
      control: "TextBox",
      source: "",
      hintText: "e.g John ",
      contolValue: "",
    ),
DyData(
  filedName: "Age",
  control: "TextBox",
  source: "",
  hintText: "e.g 18",
  contolValue: "",
),

This is my FormScreen

    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text("Form"),
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Form(
          key: _formKey,
          child: ListView.builder(
            itemCount: dyData.length,
            itemBuilder: (ctx, i) => ChangeNotifierProvider.value(
              value: dyData[i],
              child: WidControls(
              ),
            ),
          ),
        ),
      ),
    );

I need these controller values on submit button

semwal rj
  • 1
  • 1

1 Answers1

-1

You must create TextEditingController for each TextFormField and after that when you receive data from your back you can put your data on your TextFormField something like this:

first create this:

  TextEditingController nameController = TextEditingController();

After that put your TextEditingController into the your

    TextFormField(
      controller: nameController,
    )

finally when you got your data from your back, put your data into the TextEditingController like this:

nameController.text = "your data";
aminjafari-dev
  • 264
  • 1
  • 17
  • I think this solution is for a simple textfiled but in my case how I can use this TextEditingController dynamically for each TextField – semwal rj Oct 22 '22 at 05:54