dynamic_form_builder1 0.0.3
dynamic_form_builder1: ^0.0.3 copied to clipboard
A reusable dynamic TextFormField builder package.
import 'package:flutter/material.dart';
import 'package:dynamic_form_builder1/dynamic_form_builder1.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const FormExample(),
debugShowCheckedModeBanner: false,
);
}
}
class FormExample extends StatefulWidget {
const FormExample({super.key});
@override
State<FormExample> createState() => _FormExampleState();
}
class _FormExampleState extends State<FormExample> {
final _formKey = GlobalKey<FormState>();
final TextEditingController nameController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Dynamic Form Builder')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Form(
key: _formKey,
child: Column(
children: [
DynamicTextFormField(
config: TextFieldConfig(
name: 'name',
label: 'Full Name',
hint: 'Enter your name',
required: true,
),
controller: nameController,
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(nameController.text)),
);
}
},
child: const Text('Submit'),
),
],
),
),
),
);
}
}