mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-18 16:53:45 +02:00
feat: call editProfile on all updated fields
This commit is contained in:
parent
63eb1185dd
commit
b403719ce9
16 changed files with 78 additions and 123 deletions
|
@ -8,4 +8,8 @@
|
||||||
|
|
||||||
## 0.0.3
|
## 0.0.3
|
||||||
|
|
||||||
* Add support for image URL (instead of in-memory image using image parameter from User model)
|
* Add support for image URL (instead of in-memory image using image parameter from User model)
|
||||||
|
|
||||||
|
## 0.0.7
|
||||||
|
|
||||||
|
* Submit all edited fields on submit of one field
|
|
@ -4,7 +4,7 @@
|
||||||
# This file should be version controlled.
|
# This file should be version controlled.
|
||||||
|
|
||||||
version:
|
version:
|
||||||
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
channel: stable
|
channel: stable
|
||||||
|
|
||||||
project_type: app
|
project_type: app
|
||||||
|
@ -13,26 +13,23 @@ project_type: app
|
||||||
migration:
|
migration:
|
||||||
platforms:
|
platforms:
|
||||||
- platform: root
|
- platform: root
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: android
|
- platform: android
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: ios
|
- platform: ios
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: linux
|
- platform: linux
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: macos
|
- platform: macos
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: web
|
- platform: web
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57
|
||||||
- platform: windows
|
|
||||||
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
|
||||||
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
|
|
||||||
|
|
||||||
# User provided section
|
# User provided section
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.0.2"
|
version: "0.0.9"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
|
@ -58,7 +58,6 @@ flutter:
|
||||||
# included with your application, so that you can use the icons in
|
# included with your application, so that you can use the icons in
|
||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
|
|
14
example/test/widget_test.dart
Normal file
14
example/test/widget_test.dart
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// This is a basic Flutter widget test.
|
||||||
|
//
|
||||||
|
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||||
|
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||||
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||||
|
// tree, read text, and verify that the values of widget properties are correct.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('', () {
|
||||||
|
expect(true, isTrue);
|
||||||
|
});
|
||||||
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 917 B |
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
|
@ -1,58 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<!--
|
|
||||||
If you are serving your web app in a path other than the root, change the
|
|
||||||
href value below to reflect the base path you are serving from.
|
|
||||||
|
|
||||||
The path provided below has to start and end with a slash "/" in order for
|
|
||||||
it to work correctly.
|
|
||||||
|
|
||||||
For more details:
|
|
||||||
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
|
||||||
|
|
||||||
This is a placeholder for base href that will be replaced by the value of
|
|
||||||
the `--base-href` argument provided to `flutter build`.
|
|
||||||
-->
|
|
||||||
<base href="$FLUTTER_BASE_HREF">
|
|
||||||
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
|
|
||||||
<meta name="description" content="A new Flutter project.">
|
|
||||||
|
|
||||||
<!-- iOS meta tags & icons -->
|
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
||||||
<meta name="apple-mobile-web-app-title" content="example">
|
|
||||||
<link rel="apple-touch-icon" href="icons/Icon-192.png">
|
|
||||||
|
|
||||||
<!-- Favicon -->
|
|
||||||
<link rel="icon" type="image/png" href="favicon.png"/>
|
|
||||||
|
|
||||||
<title>example</title>
|
|
||||||
<link rel="manifest" href="manifest.json">
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// The value below is injected by flutter build, do not touch.
|
|
||||||
var serviceWorkerVersion = null;
|
|
||||||
</script>
|
|
||||||
<!-- This script adds the flutter initialization JS code -->
|
|
||||||
<script src="flutter.js" defer></script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script>
|
|
||||||
window.addEventListener('load', function(ev) {
|
|
||||||
// Download main.dart.js
|
|
||||||
_flutter.loader.loadEntrypoint({
|
|
||||||
serviceWorker: {
|
|
||||||
serviceWorkerVersion: serviceWorkerVersion,
|
|
||||||
}
|
|
||||||
}).then(function(engineInitializer) {
|
|
||||||
return engineInitializer.initializeEngine();
|
|
||||||
}).then(function(appRunner) {
|
|
||||||
return appRunner.runApp();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,35 +0,0 @@
|
||||||
{
|
|
||||||
"name": "example",
|
|
||||||
"short_name": "example",
|
|
||||||
"start_url": ".",
|
|
||||||
"display": "standalone",
|
|
||||||
"background_color": "#0175C2",
|
|
||||||
"theme_color": "#0175C2",
|
|
||||||
"description": "A new Flutter project.",
|
|
||||||
"orientation": "portrait-primary",
|
|
||||||
"prefer_related_applications": false,
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "icons/Icon-192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "icons/Icon-512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "icons/Icon-maskable-192.png",
|
|
||||||
"sizes": "192x192",
|
|
||||||
"type": "image/png",
|
|
||||||
"purpose": "maskable"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "icons/Icon-maskable-512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png",
|
|
||||||
"purpose": "maskable"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -15,8 +15,8 @@ class ItemBuilder {
|
||||||
|
|
||||||
final ItemBuilderOptions options;
|
final ItemBuilderOptions options;
|
||||||
|
|
||||||
Widget build(
|
Widget build(String key, dynamic value, Widget? widget,
|
||||||
String key, dynamic value, Widget? widget, Function(String) updateItem) {
|
Function(String) updateItem, Function(String) saveItem) {
|
||||||
if (widget == null) {
|
if (widget == null) {
|
||||||
var controller = TextEditingController(
|
var controller = TextEditingController(
|
||||||
text: '${value ?? ''}',
|
text: '${value ?? ''}',
|
||||||
|
@ -38,6 +38,11 @@ class ItemBuilder {
|
||||||
updateItem(value);
|
updateItem(value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onSaved: (newValue) {
|
||||||
|
if (newValue != null && newValue != value) {
|
||||||
|
saveItem(newValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
return options.validators?[key]?.call(value);
|
return options.validators?[key]?.call(value);
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,7 +11,8 @@ class ItemList extends StatefulWidget {
|
||||||
this.items,
|
this.items,
|
||||||
this.typeMap,
|
this.typeMap,
|
||||||
this.spacing,
|
this.spacing,
|
||||||
this.updateProfile, {
|
this.updateProfile,
|
||||||
|
this.saveProfile, {
|
||||||
required this.formKey,
|
required this.formKey,
|
||||||
this.itemBuilder,
|
this.itemBuilder,
|
||||||
this.itemBuilderOptions,
|
this.itemBuilderOptions,
|
||||||
|
@ -22,6 +23,7 @@ class ItemList extends StatefulWidget {
|
||||||
final Map<String, dynamic> typeMap;
|
final Map<String, dynamic> typeMap;
|
||||||
final double spacing;
|
final double spacing;
|
||||||
final Function(String, String) updateProfile;
|
final Function(String, String) updateProfile;
|
||||||
|
final Function() saveProfile;
|
||||||
final ItemBuilder? itemBuilder;
|
final ItemBuilder? itemBuilder;
|
||||||
final ItemBuilderOptions? itemBuilderOptions;
|
final ItemBuilderOptions? itemBuilderOptions;
|
||||||
final GlobalKey<FormState> formKey;
|
final GlobalKey<FormState> formKey;
|
||||||
|
@ -44,6 +46,9 @@ class _ItemListState extends State<ItemList> {
|
||||||
item.key,
|
item.key,
|
||||||
item.value,
|
item.value,
|
||||||
widget.typeMap[item.key],
|
widget.typeMap[item.key],
|
||||||
|
(value) {
|
||||||
|
widget.saveProfile();
|
||||||
|
},
|
||||||
(value) {
|
(value) {
|
||||||
widget.updateProfile(item.key, value);
|
widget.updateProfile(item.key, value);
|
||||||
},
|
},
|
||||||
|
@ -54,6 +59,9 @@ class _ItemListState extends State<ItemList> {
|
||||||
item.key,
|
item.key,
|
||||||
item.value,
|
item.value,
|
||||||
widget.typeMap[item.key],
|
widget.typeMap[item.key],
|
||||||
|
(value) {
|
||||||
|
widget.saveProfile();
|
||||||
|
},
|
||||||
(value) {
|
(value) {
|
||||||
widget.updateProfile(item.key, value);
|
widget.updateProfile(item.key, value);
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,6 @@ import 'package:flutter_profile/src/widgets/profile/profile_style.dart';
|
||||||
|
|
||||||
class ProfileWrapper extends StatefulWidget {
|
class ProfileWrapper extends StatefulWidget {
|
||||||
const ProfileWrapper({
|
const ProfileWrapper({
|
||||||
Key? key,
|
|
||||||
required this.user,
|
required this.user,
|
||||||
required this.service,
|
required this.service,
|
||||||
required this.rebuild,
|
required this.rebuild,
|
||||||
|
@ -26,7 +25,8 @@ class ProfileWrapper extends StatefulWidget {
|
||||||
this.prioritizedItems = const [],
|
this.prioritizedItems = const [],
|
||||||
this.showDefaultItems = true,
|
this.showDefaultItems = true,
|
||||||
this.wrapItemsBuilder,
|
this.wrapItemsBuilder,
|
||||||
}) : super(key: key);
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
final ProfileService service;
|
final ProfileService service;
|
||||||
|
@ -51,11 +51,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
List<Widget> defaultItems = [];
|
List<Widget> defaultItems = [];
|
||||||
|
|
||||||
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||||
|
Map<String, dynamic> formValues = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
if (widget.itemBuilder == null) {
|
if (widget.itemBuilder == null) {
|
||||||
ItemBuilder builder = ItemBuilder(
|
ItemBuilder builder = ItemBuilder(
|
||||||
options: widget.itemBuilderOptions ?? ItemBuilderOptions(),
|
options: widget.itemBuilderOptions ?? ItemBuilderOptions(),
|
||||||
|
@ -65,9 +65,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
'first_name',
|
'first_name',
|
||||||
widget.user.firstName,
|
widget.user.firstName,
|
||||||
null,
|
null,
|
||||||
|
(value) {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
(v) {
|
(v) {
|
||||||
widget.user.firstName = v;
|
widget.user.firstName = v;
|
||||||
|
|
||||||
widget.service.editProfile(widget.user, 'first_name', v);
|
widget.service.editProfile(widget.user, 'first_name', v);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -82,9 +84,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
'last_name',
|
'last_name',
|
||||||
widget.user.lastName,
|
widget.user.lastName,
|
||||||
null,
|
null,
|
||||||
|
(value) {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
(v) {
|
(v) {
|
||||||
widget.user.lastName = v;
|
widget.user.lastName = v;
|
||||||
|
|
||||||
widget.service.editProfile(widget.user, 'last_name', v);
|
widget.service.editProfile(widget.user, 'last_name', v);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -100,9 +104,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
'first_name',
|
'first_name',
|
||||||
widget.user.firstName,
|
widget.user.firstName,
|
||||||
null,
|
null,
|
||||||
|
(value) {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
(v) {
|
(v) {
|
||||||
widget.user.firstName = v;
|
widget.user.firstName = v;
|
||||||
|
|
||||||
widget.service.editProfile(widget.user, 'first_name', v);
|
widget.service.editProfile(widget.user, 'first_name', v);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -117,9 +123,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
'last_name',
|
'last_name',
|
||||||
widget.user.lastName,
|
widget.user.lastName,
|
||||||
null,
|
null,
|
||||||
|
(value) {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
(v) {
|
(v) {
|
||||||
widget.user.lastName = v;
|
widget.user.lastName = v;
|
||||||
|
|
||||||
widget.service.editProfile(widget.user, 'last_name', v);
|
widget.service.editProfile(widget.user, 'last_name', v);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -149,6 +157,9 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
(key, value) {
|
(key, value) {
|
||||||
widget.service.editProfile(widget.user, key, value);
|
widget.service.editProfile(widget.user, key, value);
|
||||||
},
|
},
|
||||||
|
() {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
itemBuilder: widget.itemBuilder,
|
itemBuilder: widget.itemBuilder,
|
||||||
itemBuilderOptions: widget.itemBuilderOptions,
|
itemBuilderOptions: widget.itemBuilderOptions,
|
||||||
formKey: formKey,
|
formKey: formKey,
|
||||||
|
@ -168,6 +179,9 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
(key, value) {
|
(key, value) {
|
||||||
widget.service.editProfile(widget.user, key, value);
|
widget.service.editProfile(widget.user, key, value);
|
||||||
},
|
},
|
||||||
|
() {
|
||||||
|
submitAllChangedFields();
|
||||||
|
},
|
||||||
itemBuilder: widget.itemBuilder,
|
itemBuilder: widget.itemBuilder,
|
||||||
itemBuilderOptions: widget.itemBuilderOptions,
|
itemBuilderOptions: widget.itemBuilderOptions,
|
||||||
formKey: formKey,
|
formKey: formKey,
|
||||||
|
@ -223,4 +237,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This calls onSaved on all the fiels which check if they have a new value
|
||||||
|
void submitAllChangedFields() {
|
||||||
|
if (formKey.currentState!.validate()) {
|
||||||
|
formKey.currentState!.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: flutter_profile
|
name: flutter_profile
|
||||||
description: Flutter profile package
|
description: Flutter profile package
|
||||||
version: 0.0.2
|
version: 0.0.9
|
||||||
repository: https://github.com/Iconica-Development/flutter_profile
|
repository: https://github.com/Iconica-Development/flutter_profile
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Reference in a new issue