To render a form, you need to follow a three-step process: choose a parser, provide the data, and render the components.
1. Choose a Form Manager
Decide if your form data is XML or JSON. Use XmlFormManager for XML or JsonFormManager for JSON. These managers handle parsing, state manipulation, validation, and data collection.
2. Initialize with ParsedFormProvider
Use the ParsedFormProvider widget to initialize your FormManager. It takes the raw XML/JSON content and a list of parsers. It uses the Provider package, making the manager available in the widget subtree via FormProvider.of<YourFormProvider>(context).
3. Render with FormRenderer
Use the FormRenderer widget to display the UI. You must specify the type of FormManager being used (e.g., FormRenderer<XmlFormManager>) so it can resolve the manager from the ParsedFormProvider.
import 'package:flutter/material.dart';
import 'package:dynamic_forms/dynamic_forms.dart';
import 'package:flutter_dynamic_forms/flutter_dynamic_forms.dart';
import 'package:flutter_dynamic_forms_components/flutter_dynamic_forms_components.dart';
class SimpleForm extends StatelessWidget {
final String xmlString;
const SimpleForm({Key key, this.xmlString}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: ParsedFormProvider(
create: (_) => XmlFormManager(), // Or use JsonFormManager() for JSON
content: xmlString,
parsers: getDefaultParserList(),
child: FormRenderer<XmlFormManager>(
renderers: getReactiveRenderers(),
),
),
),
);
}
}