mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-19 01:03:45 +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.bottomActionText,
|
||||
this.prioritizedItems = const [],
|
||||
this.showDefaultItems = true,
|
||||
this.wrapItemsBuilder,
|
||||
}) : super(key: key);
|
||||
|
||||
/// User containing all the user data.
|
||||
|
@ -61,9 +63,15 @@ class ProfilePage extends StatefulWidget {
|
|||
/// Used to set settings of each field in user.
|
||||
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.
|
||||
final List<String> prioritizedItems;
|
||||
|
||||
/// Shows textfields for firstname and lastname if is set to true
|
||||
final bool showDefaultItems;
|
||||
|
||||
@override
|
||||
State<ProfilePage> createState() => _ProfilePageState();
|
||||
}
|
||||
|
@ -84,6 +92,8 @@ class _ProfilePageState extends State<ProfilePage> {
|
|||
itemBuilder: widget.itemBuilder,
|
||||
itemBuilderOptions: widget.itemBuilderOptions,
|
||||
prioritizedItems: widget.prioritizedItems,
|
||||
showDefaultItems: widget.showDefaultItems,
|
||||
wrapItemsBuilder: widget.wrapItemsBuilder,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class ProfileStyle {
|
|||
this.avatarStyle = const AvatarStyle(),
|
||||
this.betweenDefaultItemPadding = 10,
|
||||
this.pagePadding = EdgeInsets.zero,
|
||||
this.bottomActionTextStyle,
|
||||
});
|
||||
|
||||
/// AvatarStyle can be used to set some avatar styling parameters.
|
||||
|
@ -23,4 +24,7 @@ class ProfileStyle {
|
|||
|
||||
/// BetweenDefaultItemPadding sets the
|
||||
final double betweenDefaultItemPadding;
|
||||
|
||||
/// Bottom action text style
|
||||
final TextStyle? bottomActionTextStyle;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ class ProfileWrapper extends StatefulWidget {
|
|||
this.itemBuilderOptions,
|
||||
this.bottomActionText,
|
||||
this.prioritizedItems = const [],
|
||||
this.showDefaultItems = true,
|
||||
this.wrapItemsBuilder,
|
||||
}) : super(key: key);
|
||||
|
||||
final User user;
|
||||
|
@ -31,6 +33,8 @@ class ProfileWrapper extends StatefulWidget {
|
|||
final ItemBuilder? itemBuilder;
|
||||
final Function rebuild;
|
||||
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.
|
||||
final List<String> prioritizedItems;
|
||||
|
@ -132,6 +136,45 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
|
||||
@override
|
||||
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(
|
||||
color: Colors.transparent,
|
||||
child: Padding(
|
||||
|
@ -154,40 +197,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
),
|
||||
],
|
||||
// all the items that have priority above the default items
|
||||
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,
|
||||
),
|
||||
...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,
|
||||
),
|
||||
child,
|
||||
if (widget.bottomActionText != null) ...[
|
||||
SizedBox(
|
||||
height: widget.style.betweenDefaultItemPadding,
|
||||
|
@ -199,7 +209,10 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
|
|||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(widget.bottomActionText!),
|
||||
child: Text(
|
||||
widget.bottomActionText!,
|
||||
style: widget.style.bottomActionTextStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
|
|
Loading…
Reference in a new issue