Compare commits

..

No commits in common. "master" and "1.6.0" have entirely different histories.

5 changed files with 43 additions and 33 deletions

View file

@ -17,7 +17,7 @@ class ExampleProfileData extends ProfileData {
String? remarks;
@override
Map<String, Widget?> mapWidget(
Map<String, dynamic> mapWidget(
VoidCallback update,
BuildContext context,
) {
@ -38,7 +38,7 @@ class ExampleProfileData extends ProfileData {
}
@override
Map<String, String?> toMap() {
Map<String, dynamic> toMap() {
return {'email': email, 'about': about, 'remarks': remarks};
}

View file

@ -76,9 +76,9 @@ abstract class ProfileData {
ProfileData fromMap(Map<String, dynamic> data);
Map<String, String?> toMap();
Map<String, dynamic> toMap();
Map<String, Widget?> mapWidget(VoidCallback update, BuildContext context);
Map<String, dynamic> mapWidget(VoidCallback update, BuildContext context);
ProfileData create();
}

View file

@ -19,14 +19,14 @@ class ItemBuilder {
Widget build(
String key,
String? value,
value,
Widget? widget,
void Function(String) updateItem,
void Function(String?) saveItem,
Function(String) updateItem,
Function(String?) saveItem,
) {
if (widget == null) {
var controller = TextEditingController(
text: value ?? '',
text: '${value ?? ''}',
);
var inputDecoration =
@ -55,7 +55,7 @@ class ItemBuilder {
Widget buildPassword(
String key,
TextEditingController controller,
void Function(String?) onChanged,
Function(String?) onChanged,
String? Function(String?) validator,
) {
var inputDecoration =

View file

@ -16,39 +16,49 @@ class ItemList {
this.itemBuilder,
this.itemBuilderOptions,
}) {
var itemBuilder = this.itemBuilder ?? builder;
widgets = {
for (var item in items.entries) ...{
item.key: itemBuilder.build(
item.key,
item.value,
typeMap[item.key],
(value) {
saveProfile();
},
(value) {
updateProfile(item.key, value);
},
),
},
};
for (var item in items.entries) {
widgets.addAll({
item.key: itemBuilder == null
? builder.build(
item.key,
item.value,
typeMap[item.key],
(value) {
saveProfile();
},
(value) {
updateProfile(item.key, value);
},
)
: itemBuilder!.build(
item.key,
item.value,
typeMap[item.key],
(value) {
saveProfile();
},
(value) {
updateProfile(item.key, value);
},
),
});
}
}
/// Gets the map of item keys and their corresponding widgets.
Map<String, Widget> getItemList() => widgets;
/// Map containing item keys and their values.
final Map<String, String?> items;
final Map<String, dynamic> items;
/// Map containing item keys and their types.
final Map<String, Widget?> typeMap;
final Map<String, dynamic> typeMap;
/// Function to update the profile with a specific item's value.
final void Function(String, String?) updateProfile;
final Function(String, String?) updateProfile;
/// Function to save the profile after an item value is updated.
final void Function() saveProfile;
final Function() saveProfile;
/// Builder for custom item widgets.
final ItemBuilder? itemBuilder;
@ -60,7 +70,7 @@ class ItemList {
final GlobalKey<FormState> formKey;
/// Map containing item keys and their corresponding widgets.
late final Map<String, Widget> widgets;
Map<String, Widget> widgets = {};
/// `builder` is an instance of `ItemBuilder` which is used
/// to build the items in the list.

View file

@ -13,7 +13,7 @@ class TestProfileData extends ProfileData {
String? email;
@override
Map<String, Widget?> mapWidget(
Map<String, dynamic> mapWidget(
VoidCallback update,
BuildContext context,
) =>
@ -27,7 +27,7 @@ class TestProfileData extends ProfileData {
);
@override
Map<String, String?> toMap() => {
Map<String, dynamic> toMap() => {
'email': email,
};