feat: added prioritizedItems

This commit is contained in:
Freek van de Ven 2022-10-14 15:54:50 +02:00
parent 723d4d0c23
commit e00c4dcfcc
11 changed files with 61 additions and 70 deletions

9
.gitignore vendored
View file

@ -19,7 +19,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/
# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
@ -28,3 +28,10 @@ migrate_working_dir/
.dart_tool/
.packages
build/
example/android/
example/ios/
example/linux/
example/macos/
example/windows/
example/web/

View file

@ -1,3 +1,7 @@
## 0.0.1
* TODO: Describe initial release.
* Initial release.
## 0.0.2
* Add prioritizedItems option to display items at the top of the page.

View file

@ -1 +0,0 @@
TODO: Add your license here.

View file

@ -29,6 +29,8 @@ Underneath are all paramters, of the 'ProfilePage' widget, listed with an explan
| showAvatar | The ability to disable/enable the avatar. |
| itemBuilder | The way to override the standard textfield for each standard piece of user data. |
| itemBuilderOptions | The options used by the standard itemBuilder to alter the function and style of the textfields |
| prioritizedItems | The items that are displayed at the top of the page. Before all the other items in the list and the default items |
## Issues
@ -36,8 +38,8 @@ Please file any issues, bugs or feature request as an issue on our [GitHub](http
## Want to contribute
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](URL TO PULL REQUEST TAB IN REPO).
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](../CONTRIBUTING.md) and send us your [pull request](https://github.com/Iconica-Development/flutter_profile/pulls).
## Author
This `flutter-image-picker` for Flutter is developed by [Iconica](https://iconica.nl). You can contact us at <support@iconica.nl>
This `flutter_profile` for Flutter is developed by [Iconica](https://iconica.nl). You can contact us at <support@iconica.nl>

2
example/.gitignore vendored
View file

@ -19,7 +19,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/
# Flutter/Dart/Pub related
**/doc/api/

View file

@ -1,16 +0,0 @@
# example
A new Flutter project.
## Getting Started
This project is a starting point for a Flutter application.
A few resources to get you started if this is your first Flutter project:
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

View file

@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.0.2"
flutter_test:
dependency: "direct dev"
description: flutter

View file

@ -2,6 +2,7 @@ library flutter_profile;
export 'src/widgets/profile/profile_page.dart';
export 'src/widgets/profile/profile_style.dart';
export 'src/widgets/avatar/avatar.dart';
export 'src/widgets/avatar/avatar_style.dart';
export 'src/services/profile_service.dart';
export 'src/widgets/item_builder/item_builder.dart';

View file

@ -34,6 +34,7 @@ class ProfilePage extends StatefulWidget {
this.itemBuilder,
this.itemBuilderOptions,
this.bottomActionText,
this.prioritizedItems = const [],
}) : super(key: key);
/// User containing all the user data.
@ -57,9 +58,12 @@ class ProfilePage extends StatefulWidget {
/// Itembuilder is used the build each field in the user.
final ItemBuilder? itemBuilder;
/// Used to set settings of eacht field in user.
/// Used to set settings of each field in user.
final ItemBuilderOptions? itemBuilderOptions;
/// Map keys of items that should be shown first before the default items and the rest of the items.
final List<String> prioritizedItems;
@override
State<ProfilePage> createState() => _ProfilePageState();
}
@ -79,7 +83,7 @@ class _ProfilePageState extends State<ProfilePage> {
bottomActionText: widget.bottomActionText,
itemBuilder: widget.itemBuilder,
itemBuilderOptions: widget.itemBuilderOptions,
key: UniqueKey(),
prioritizedItems: widget.prioritizedItems,
);
}
}

View file

@ -19,6 +19,7 @@ class ProfileWrapper extends StatefulWidget {
this.itemBuilder,
this.itemBuilderOptions,
this.bottomActionText,
this.prioritizedItems = const [],
}) : super(key: key);
final User user;
@ -31,6 +32,9 @@ class ProfileWrapper extends StatefulWidget {
final Function rebuild;
final ItemBuilderOptions? itemBuilderOptions;
/// Map keys of items that should be shown first before the default items and the rest of the items.
final List<String> prioritizedItems;
@override
State<ProfileWrapper> createState() => _ProfileWrapperState();
}
@ -134,7 +138,7 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
padding: widget.style.pagePadding,
child: Column(
children: [
if (widget.showAvatar)
if (widget.showAvatar) ...[
InkWell(
onTap: () async {
await widget.service.uploadImage(context);
@ -147,13 +151,14 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
image: widget.user.image,
),
),
if (widget.showAvatar)
SizedBox(
height: widget.style.betweenDefaultItemPadding,
),
...defaultItems,
],
// all the items that have priority above the default items
ItemList(
widget.user.profileData!.toMap(),
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
(element) => widget.prioritizedItems.contains(element.key))),
widget.user.profileData!.mapWidget(
() {
widget.rebuild();
@ -167,12 +172,29 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
itemBuilder: widget.itemBuilder,
itemBuilderOptions: widget.itemBuilderOptions,
),
if (widget.bottomActionText != null)
...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) ...[
SizedBox(
height: widget.style.betweenDefaultItemPadding,
),
const Spacer(),
if (widget.bottomActionText != null)
const Spacer(),
InkWell(
onTap: () {
widget.service.pageBottomAction();
@ -182,6 +204,9 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
child: Text(widget.bottomActionText!),
),
),
] else ...[
const Spacer(),
],
],
),
),

View file

@ -1,7 +1,7 @@
name: flutter_profile
description: A new Flutter package project.
version: 0.0.1
homepage:
description: Flutter profile package
version: 0.0.2
repository: https://github.com/Iconica-Development/flutter_profile
environment:
sdk: ">=2.17.6 <3.0.0"
@ -16,39 +16,4 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages