diff --git a/lib/src/widgets/profile/profile_page.dart b/lib/src/widgets/profile/profile_page.dart index 5cff392..54cc5c6 100644 --- a/lib/src/widgets/profile/profile_page.dart +++ b/lib/src/widgets/profile/profile_page.dart @@ -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 prioritizedItems; + /// Shows textfields for firstname and lastname if is set to true + final bool showDefaultItems; + @override State createState() => _ProfilePageState(); } @@ -84,6 +92,8 @@ class _ProfilePageState extends State { itemBuilder: widget.itemBuilder, itemBuilderOptions: widget.itemBuilderOptions, prioritizedItems: widget.prioritizedItems, + showDefaultItems: widget.showDefaultItems, + wrapItemsBuilder: widget.wrapItemsBuilder, ); } } diff --git a/lib/src/widgets/profile/profile_style.dart b/lib/src/widgets/profile/profile_style.dart index 5d09954..a85ab7f 100644 --- a/lib/src/widgets/profile/profile_style.dart +++ b/lib/src/widgets/profile/profile_style.dart @@ -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; } diff --git a/lib/src/widgets/profile/proifle_wrapper.dart b/lib/src/widgets/profile/proifle_wrapper.dart index da722a4..9eb927f 100644 --- a/lib/src/widgets/profile/proifle_wrapper.dart +++ b/lib/src/widgets/profile/proifle_wrapper.dart @@ -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 prioritizedItems; @@ -132,6 +136,45 @@ class _ProfileWrapperState extends State { @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 { ), ], // 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 { }, child: Padding( padding: const EdgeInsets.all(8.0), - child: Text(widget.bottomActionText!), + child: Text( + widget.bottomActionText!, + style: widget.style.bottomActionTextStyle, + ), ), ), ] else ...[