Skip to content

Commit 005f361

Browse files
committed
feat: add generic form for proxy settings (apidash_design_system)
1 parent 830800f commit 005f361

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'package:flutter/material.dart';
2+
3+
/// A generic field configuration for the [GenericForm].
4+
class GenericFormField {
5+
final TextEditingController controller;
6+
7+
final String labelText;
8+
9+
final String? hintText;
10+
11+
final bool obscureText;
12+
13+
final bool required;
14+
15+
final String? Function(String?)? validator;
16+
17+
GenericFormField({
18+
required this.controller,
19+
required this.labelText,
20+
this.hintText,
21+
this.obscureText = false,
22+
this.required = false,
23+
this.validator,
24+
});
25+
}
26+
27+
/// A generic form that can be used throughout the application.
28+
class GenericForm extends StatelessWidget {
29+
final List<GenericFormField> fields;
30+
31+
final double fieldSpacing;
32+
33+
const GenericForm({
34+
super.key,
35+
required this.fields,
36+
this.fieldSpacing = 8.0,
37+
});
38+
39+
@override
40+
Widget build(BuildContext context) {
41+
return Column(
42+
mainAxisSize: MainAxisSize.min,
43+
crossAxisAlignment: CrossAxisAlignment.stretch,
44+
children: _buildFormFields(),
45+
);
46+
}
47+
48+
List<Widget> _buildFormFields() {
49+
final List<Widget> formFields = [];
50+
51+
for (int i = 0; i < fields.length; i++) {
52+
final field = fields[i];
53+
54+
formFields.add(
55+
TextField(
56+
controller: field.controller,
57+
decoration: InputDecoration(
58+
labelText: field.labelText + (field.required ? ' *' : ''),
59+
hintText: field.hintText,
60+
),
61+
obscureText: field.obscureText,
62+
),
63+
);
64+
65+
// Add spacing between fields (except after the last one)
66+
if (i < fields.length - 1) {
67+
formFields.add(SizedBox(height: fieldSpacing));
68+
}
69+
}
70+
71+
return formFields;
72+
}
73+
}

0 commit comments

Comments
 (0)