mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-19 01:03:45 +02:00
fix: inconsistent saving
This commit is contained in:
parent
a1e00e0980
commit
ad22c1011c
9 changed files with 51 additions and 29 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -12,4 +12,12 @@
|
|||
|
||||
## 0.0.7
|
||||
|
||||
* Submit all edited fields on submit of one field
|
||||
* Submit all edited fields on submit of one field
|
||||
|
||||
## 0.0.10
|
||||
|
||||
* Fixed bug where keyboard would close on selecting custom input fields.
|
||||
|
||||
## 0.0.11
|
||||
|
||||
* Fixed bug where some field wouldn't update when submitted.
|
|
@ -17,7 +17,7 @@ class ExampleProfileService extends ProfileService {
|
|||
void editProfile(
|
||||
User user,
|
||||
String key,
|
||||
String value,
|
||||
String? value,
|
||||
) {
|
||||
debugPrint('Editing key: $key with $value');
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class User {
|
|||
'last_name': lastName,
|
||||
'image': image,
|
||||
'image_url': image,
|
||||
'profile_data': profileData,
|
||||
'profile_data': profileData?.toMap(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ abstract class ProfileService {
|
|||
|
||||
FutureOr<void> pageBottomAction();
|
||||
|
||||
FutureOr<void> editProfile(User user, String key, String value);
|
||||
FutureOr<void> editProfile(User user, String key, String? value);
|
||||
|
||||
FutureOr<void> uploadImage(BuildContext context);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class ItemBuilder {
|
|||
final ItemBuilderOptions options;
|
||||
|
||||
Widget build(String key, dynamic value, Widget? widget,
|
||||
Function(String) updateItem, Function(String) saveItem) {
|
||||
Function(String) updateItem, Function(String?) saveItem) {
|
||||
if (widget == null) {
|
||||
var controller = TextEditingController(
|
||||
text: '${value ?? ''}',
|
||||
|
@ -34,14 +34,10 @@ class ItemBuilder {
|
|||
decoration: inputDecoration,
|
||||
readOnly: options.readOnly,
|
||||
onFieldSubmitted: (value) {
|
||||
if (formFieldKey.currentState!.validate()) {
|
||||
updateItem(value);
|
||||
}
|
||||
updateItem(value);
|
||||
},
|
||||
onSaved: (newValue) {
|
||||
if (newValue != null && newValue != value) {
|
||||
saveItem(newValue);
|
||||
}
|
||||
saveItem(newValue);
|
||||
},
|
||||
validator: (value) {
|
||||
return options.validators?[key]?.call(value);
|
||||
|
|
|
@ -22,7 +22,7 @@ class ItemList extends StatefulWidget {
|
|||
final Map<String, dynamic> items;
|
||||
final Map<String, dynamic> typeMap;
|
||||
final double spacing;
|
||||
final Function(String, String) updateProfile;
|
||||
final Function(String, String?) updateProfile;
|
||||
final Function() saveProfile;
|
||||
final ItemBuilder? itemBuilder;
|
||||
final ItemBuilderOptions? itemBuilderOptions;
|
||||
|
|
|
@ -52,6 +52,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
|
||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
Map<String, dynamic> formValues = {};
|
||||
late final Widget child;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -69,8 +70,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
submitAllChangedFields();
|
||||
},
|
||||
(v) {
|
||||
widget.user.firstName = v;
|
||||
widget.service.editProfile(widget.user, 'first_name', v);
|
||||
if (widget.user.firstName != v) {
|
||||
widget.user.firstName = v;
|
||||
widget.service.editProfile(widget.user, 'first_name', v);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -88,8 +91,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
submitAllChangedFields();
|
||||
},
|
||||
(v) {
|
||||
widget.user.lastName = v;
|
||||
widget.service.editProfile(widget.user, 'last_name', v);
|
||||
if (widget.user.lastName != v) {
|
||||
widget.user.lastName = v;
|
||||
widget.service.editProfile(widget.user, 'last_name', v);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -108,8 +113,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
submitAllChangedFields();
|
||||
},
|
||||
(v) {
|
||||
widget.user.firstName = v;
|
||||
widget.service.editProfile(widget.user, 'first_name', v);
|
||||
if (widget.user.firstName != v) {
|
||||
widget.user.firstName = v;
|
||||
widget.service.editProfile(widget.user, 'first_name', v);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -127,8 +134,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
submitAllChangedFields();
|
||||
},
|
||||
(v) {
|
||||
widget.user.lastName = v;
|
||||
widget.service.editProfile(widget.user, 'last_name', v);
|
||||
if (widget.user.lastName != v) {
|
||||
widget.user.lastName = v;
|
||||
widget.service.editProfile(widget.user, 'last_name', v);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -138,10 +147,6 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var items = Column(
|
||||
children: [
|
||||
ItemList(
|
||||
|
@ -155,7 +160,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
),
|
||||
widget.style.betweenDefaultItemPadding,
|
||||
(key, value) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
if (widget.user.toMap()['profile_data'][key] == null) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
} else if (widget.user.toMap()['profile_data'][key] != value) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
}
|
||||
},
|
||||
() {
|
||||
submitAllChangedFields();
|
||||
|
@ -177,7 +186,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
),
|
||||
widget.style.betweenDefaultItemPadding,
|
||||
(key, value) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
if (widget.user.toMap()['profile_data'][key] == null) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
} else if (widget.user.toMap()['profile_data'][key] != value) {
|
||||
widget.service.editProfile(widget.user, key, value);
|
||||
}
|
||||
},
|
||||
() {
|
||||
submitAllChangedFields();
|
||||
|
@ -188,7 +201,12 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
),
|
||||
],
|
||||
);
|
||||
var child = widget.wrapItemsBuilder?.call(context, items) ?? items;
|
||||
|
||||
child = widget.wrapItemsBuilder?.call(context, items) ?? items;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: Padding(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_profile
|
||||
description: Flutter profile package
|
||||
version: 0.0.9
|
||||
version: 0.0.11
|
||||
repository: https://github.com/Iconica-Development/flutter_profile
|
||||
|
||||
environment:
|
||||
|
|
|
@ -15,7 +15,7 @@ class TestProfileService extends ProfileService {
|
|||
void editProfile(
|
||||
User user,
|
||||
String key,
|
||||
String value,
|
||||
String? value,
|
||||
) {}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in a new issue