mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-19 09:13:44 +02:00
added options: show defaults, wrap items, bottom action style
This commit is contained in:
parent
a910c4d381
commit
cb55361fac
3 changed files with 62 additions and 35 deletions
|
@ -35,6 +35,8 @@ class ProfilePage extends StatefulWidget {
|
||||||
this.itemBuilderOptions,
|
this.itemBuilderOptions,
|
||||||
this.bottomActionText,
|
this.bottomActionText,
|
||||||
this.prioritizedItems = const [],
|
this.prioritizedItems = const [],
|
||||||
|
this.showDefaultItems = true,
|
||||||
|
this.wrapItemsBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// User containing all the user data.
|
/// User containing all the user data.
|
||||||
|
@ -61,9 +63,15 @@ class ProfilePage extends StatefulWidget {
|
||||||
/// Used to set settings of each field in user.
|
/// Used to set settings of each field in user.
|
||||||
final ItemBuilderOptions? itemBuilderOptions;
|
final ItemBuilderOptions? itemBuilderOptions;
|
||||||
|
|
||||||
|
/// Customize the parent widget for all fields
|
||||||
|
final Widget Function(BuildContext context, Widget child)? wrapItemsBuilder;
|
||||||
|
|
||||||
/// Map keys of items that should be shown first before the default items and the rest of the items.
|
/// Map keys of items that should be shown first before the default items and the rest of the items.
|
||||||
final List<String> prioritizedItems;
|
final List<String> prioritizedItems;
|
||||||
|
|
||||||
|
/// Shows textfields for firstname and lastname if is set to true
|
||||||
|
final bool showDefaultItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ProfilePage> createState() => _ProfilePageState();
|
State<ProfilePage> createState() => _ProfilePageState();
|
||||||
}
|
}
|
||||||
|
@ -84,6 +92,8 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
itemBuilder: widget.itemBuilder,
|
itemBuilder: widget.itemBuilder,
|
||||||
itemBuilderOptions: widget.itemBuilderOptions,
|
itemBuilderOptions: widget.itemBuilderOptions,
|
||||||
prioritizedItems: widget.prioritizedItems,
|
prioritizedItems: widget.prioritizedItems,
|
||||||
|
showDefaultItems: widget.showDefaultItems,
|
||||||
|
wrapItemsBuilder: widget.wrapItemsBuilder,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ class ProfileStyle {
|
||||||
this.avatarStyle = const AvatarStyle(),
|
this.avatarStyle = const AvatarStyle(),
|
||||||
this.betweenDefaultItemPadding = 10,
|
this.betweenDefaultItemPadding = 10,
|
||||||
this.pagePadding = EdgeInsets.zero,
|
this.pagePadding = EdgeInsets.zero,
|
||||||
|
this.bottomActionTextStyle,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// AvatarStyle can be used to set some avatar styling parameters.
|
/// AvatarStyle can be used to set some avatar styling parameters.
|
||||||
|
@ -23,4 +24,7 @@ class ProfileStyle {
|
||||||
|
|
||||||
/// BetweenDefaultItemPadding sets the
|
/// BetweenDefaultItemPadding sets the
|
||||||
final double betweenDefaultItemPadding;
|
final double betweenDefaultItemPadding;
|
||||||
|
|
||||||
|
/// Bottom action text style
|
||||||
|
final TextStyle? bottomActionTextStyle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ class ProfileWrapper extends StatefulWidget {
|
||||||
this.itemBuilderOptions,
|
this.itemBuilderOptions,
|
||||||
this.bottomActionText,
|
this.bottomActionText,
|
||||||
this.prioritizedItems = const [],
|
this.prioritizedItems = const [],
|
||||||
|
this.showDefaultItems = true,
|
||||||
|
this.wrapItemsBuilder,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
|
@ -31,6 +33,8 @@ class ProfileWrapper extends StatefulWidget {
|
||||||
final ItemBuilder? itemBuilder;
|
final ItemBuilder? itemBuilder;
|
||||||
final Function rebuild;
|
final Function rebuild;
|
||||||
final ItemBuilderOptions? itemBuilderOptions;
|
final ItemBuilderOptions? itemBuilderOptions;
|
||||||
|
final bool showDefaultItems;
|
||||||
|
final Widget Function(BuildContext context, Widget child)? wrapItemsBuilder;
|
||||||
|
|
||||||
/// Map keys of items that should be shown first before the default items and the rest of the items.
|
/// Map keys of items that should be shown first before the default items and the rest of the items.
|
||||||
final List<String> prioritizedItems;
|
final List<String> prioritizedItems;
|
||||||
|
@ -132,6 +136,45 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var items = Column(
|
||||||
|
children: [
|
||||||
|
ItemList(
|
||||||
|
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
|
||||||
|
(element) => widget.prioritizedItems.contains(element.key))),
|
||||||
|
widget.user.profileData!.mapWidget(
|
||||||
|
() {
|
||||||
|
widget.rebuild();
|
||||||
|
},
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
widget.style.betweenDefaultItemPadding,
|
||||||
|
(key, value) {
|
||||||
|
widget.service.editProfile(widget.user, key, value);
|
||||||
|
},
|
||||||
|
itemBuilder: widget.itemBuilder,
|
||||||
|
itemBuilderOptions: widget.itemBuilderOptions,
|
||||||
|
),
|
||||||
|
if (widget.showDefaultItems) ...defaultItems,
|
||||||
|
// remove all the items that have priority from the widget.user.profileData!.toMap()
|
||||||
|
ItemList(
|
||||||
|
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
|
||||||
|
(element) => !widget.prioritizedItems.contains(element.key))),
|
||||||
|
widget.user.profileData!.mapWidget(
|
||||||
|
() {
|
||||||
|
widget.rebuild();
|
||||||
|
},
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
widget.style.betweenDefaultItemPadding,
|
||||||
|
(key, value) {
|
||||||
|
widget.service.editProfile(widget.user, key, value);
|
||||||
|
},
|
||||||
|
itemBuilder: widget.itemBuilder,
|
||||||
|
itemBuilderOptions: widget.itemBuilderOptions,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
var child = widget.wrapItemsBuilder?.call(context, items) ?? items;
|
||||||
return Material(
|
return Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -154,40 +197,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
// all the items that have priority above the default items
|
// all the items that have priority above the default items
|
||||||
ItemList(
|
child,
|
||||||
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
|
|
||||||
(element) => widget.prioritizedItems.contains(element.key))),
|
|
||||||
widget.user.profileData!.mapWidget(
|
|
||||||
() {
|
|
||||||
widget.rebuild();
|
|
||||||
},
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
widget.style.betweenDefaultItemPadding,
|
|
||||||
(key, value) {
|
|
||||||
widget.service.editProfile(widget.user, key, value);
|
|
||||||
},
|
|
||||||
itemBuilder: widget.itemBuilder,
|
|
||||||
itemBuilderOptions: widget.itemBuilderOptions,
|
|
||||||
),
|
|
||||||
...defaultItems,
|
|
||||||
// remove all the items that have priority from the widget.user.profileData!.toMap()
|
|
||||||
ItemList(
|
|
||||||
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
|
|
||||||
(element) => !widget.prioritizedItems.contains(element.key))),
|
|
||||||
widget.user.profileData!.mapWidget(
|
|
||||||
() {
|
|
||||||
widget.rebuild();
|
|
||||||
},
|
|
||||||
context,
|
|
||||||
),
|
|
||||||
widget.style.betweenDefaultItemPadding,
|
|
||||||
(key, value) {
|
|
||||||
widget.service.editProfile(widget.user, key, value);
|
|
||||||
},
|
|
||||||
itemBuilder: widget.itemBuilder,
|
|
||||||
itemBuilderOptions: widget.itemBuilderOptions,
|
|
||||||
),
|
|
||||||
if (widget.bottomActionText != null) ...[
|
if (widget.bottomActionText != null) ...[
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: widget.style.betweenDefaultItemPadding,
|
height: widget.style.betweenDefaultItemPadding,
|
||||||
|
@ -199,7 +209,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(widget.bottomActionText!),
|
child: Text(
|
||||||
|
widget.bottomActionText!,
|
||||||
|
style: widget.style.bottomActionTextStyle,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
] else ...[
|
] else ...[
|
||||||
|
|
Loading…
Reference in a new issue