OndrejKunc / flutter_dynamic_forms

A collection of flutter and dart libraries allowing you to consume complex external forms at runtime.
MIT License
204 stars 60 forks source link

How to add submit button and send data ? #83

Open dufontes opened 4 years ago

dufontes commented 4 years ago
body: Center(
        child: SingleChildScrollView(
          child: isLoading
              ? CircularProgressIndicator()
              : ParsedFormProvider(
                  create: (_) => JsonFormManager(),
                  content: json,
                  parsers: components.getDefaultParserList(),
                  child: FormRenderer<JsonFormManager>(
                    renderers: components.getReactiveRenderers(),

                  ),
                ),
        ),
      ),
OndrejKunc commented 4 years ago

Hi, for example like this:

body: Center(
  child: SingleChildScrollView(
    child: isLoading
        ? CircularProgressIndicator()
        : ParsedFormProvider(
            create: (_) => JsonFormManager(),
            content: fileContent,
            parsers: components.getDefaultParserList(),
            child: Column(
              children: [
                FormRenderer<JsonFormManager>(
                  renderers: components.getReactiveRenderers(),
                ),
                // Using Builder to obtain a BuildContext already containg JsonFormManager
                Builder(
                  builder: (context) {
                    return RaisedButton(
                      child: Text('Submit'),
                      onPressed: () {
                        var formProperties =
                            FormProvider.of<JsonFormManager>(context)
                                .getFormProperties();
                        // send data to server:
                        for (var property in formProperties) {
                          // Print to console for demonstration purposes
                          print(
                              '${property.id} ${property.property} ${property.value}');
                        }
                      },
                    );
                  },
                ),
              ],
            ),
          ),
  ),
),

I just also implemented a working example here: https://github.com/OndrejKunc/flutter_dynamic_forms/blob/master/packages/flutter_dynamic_forms_components/example/lib/simple_submit_form/simple_submit_form.dart