From d320075d570bff8e693a89cc3e95eede1eb0a5c4 Mon Sep 17 00:00:00 2001 From: Joons van Stuijvenberg Date: Thu, 1 Dec 2022 15:11:15 +0100 Subject: [PATCH] now with wrap! --- CHANGELOG.md | 6 +- example/.metadata | 29 ++-- example/lib/main.dart | 130 ++++++++++++------ example/pubspec.lock | 2 +- example/pubspec.yaml | 9 +- .../item_builder/item_builder_options.dart | 3 +- lib/src/widgets/profile/profile_page.dart | 14 ++ lib/src/widgets/profile/profile_wrapper.dart | 9 +- pubspec.yaml | 4 +- 9 files changed, 139 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b986b5..035da9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,4 +20,8 @@ ## 0.0.11 -* Fixed bug where some field wouldn't update when submitted. \ No newline at end of file +* Fixed bug where some field wouldn't update when submitted. + +## 1.0.1 + +* Added a default wrap instead of column \ No newline at end of file diff --git a/example/.metadata b/example/.metadata index 02bbd38..3fdf532 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,7 @@ # This file should be version controlled. version: - revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 channel: stable project_type: app @@ -13,23 +13,26 @@ project_type: app migration: platforms: - platform: root - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 - platform: android - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 - platform: ios - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 - platform: linux - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 - platform: macos - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 - platform: web - create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 - base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + - platform: windows + create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 + base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849 # User provided section diff --git a/example/lib/main.dart b/example/lib/main.dart index d784224..f070c17 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -6,6 +6,7 @@ import 'dart:typed_data'; import 'package:example/utils/example_profile_service.dart'; import 'package:flutter/material.dart'; + import 'package:flutter_profile/flutter_profile.dart'; import 'utils/example_profile_data.dart'; @@ -53,53 +54,98 @@ class _ProfileExampleState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: ProfilePage( - bottomActionText: 'Log out', - itemBuilderOptions: ItemBuilderOptions( - inputDecorationField: { - 'first_name': const InputDecoration( - label: Text('First name'), - ), - 'last_name': const InputDecoration( - label: Text('Last name'), - ), - 'email': const InputDecoration( - label: Text('E-mail'), - ), - }, - validators: { - 'first_name': (String? value) { - if (value == null || value.isEmpty) { - return 'Field empty'; - } - return null; + body: Center( + child: ProfilePage( + wrapViewOptions: + WrapViewOptions(direction: Axis.vertical, spacing: 16), + bottomActionText: 'Log out', + itemBuilderOptions: ItemBuilderOptions( + inputDecorationField: { + 'first_name': const InputDecoration( + constraints: BoxConstraints(maxHeight: 70, maxWidth: 200), + label: Text('First name'), + ), + 'last_name': const InputDecoration( + constraints: BoxConstraints(maxHeight: 70, maxWidth: 150), + label: Text('First name'), + ), }, - 'last_name': (String? value) { - if (value == null || value.isEmpty) { - return 'Field empty'; - } - return null; + validators: { + 'first_name': (String? value) { + if (value == null || value.isEmpty) { + return 'Field empty'; + } + return null; + }, + 'last_name': (String? value) { + if (value == null || value.isEmpty) { + return 'Field empty'; + } + return null; + }, + 'email': (String? value) { + if (value == null || value.isEmpty) { + return 'Field empty'; + } + return null; + }, }, - 'email': (String? value) { - if (value == null || value.isEmpty) { - return 'Field empty'; - } - return null; - }, - }, - ), - user: _user, - service: ExampleProfileService(), - style: ProfileStyle( - avatarTextStyle: const TextStyle(fontSize: 20), - pagePadding: EdgeInsets.only( - top: 50, - bottom: 50, - left: MediaQuery.of(context).size.width * 0.35, - right: MediaQuery.of(context).size.width * 0.35, + ), + user: _user, + service: ExampleProfileService(), + style: ProfileStyle( + avatarTextStyle: const TextStyle(fontSize: 20), + pagePadding: EdgeInsets.only( + top: 50, + bottom: 50, + left: MediaQuery.of(context).size.width * 0.1, + right: MediaQuery.of(context).size.width * 0.1, + ), ), ), ), ); } } + +class CustomItemBuilderExample extends ItemBuilder { + CustomItemBuilderExample({ + required super.options, + }); + + @override + Widget build(String key, dynamic value, Widget? widget, + Function(String) updateItem, Function(String?) saveItem) { + if (widget == null) { + var controller = TextEditingController( + text: '${value ?? ''}', + ); + + late InputDecoration inputDecoration; + + inputDecoration = + options.inputDecorationField?[key] ?? options.inputDecoration; + var formFieldKey = GlobalKey(); + return SizedBox( + width: 300, + child: TextFormField( + keyboardType: options.keyboardType?[key], + key: formFieldKey, + controller: controller, + decoration: inputDecoration, + readOnly: options.readOnly, + onFieldSubmitted: (value) { + updateItem(value); + }, + onSaved: (newValue) { + saveItem(newValue); + }, + validator: (value) { + return options.validators?[key]?.call(value); + }, + ), + ); + } + return widget; + } +} diff --git a/example/pubspec.lock b/example/pubspec.lock index d2d7cfd..0baa99e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -124,7 +124,7 @@ packages: path: ".." relative: true source: path - version: "0.0.11" + version: "1.0.1" flutter_test: dependency: "direct dev" description: flutter diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 40fb165..aac0575 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -30,7 +30,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 @@ -53,10 +52,8 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. + assets: + - image/ uses-material-design: true # To add assets to your application, add an assets section, like this: # assets: diff --git a/lib/src/widgets/item_builder/item_builder_options.dart b/lib/src/widgets/item_builder/item_builder_options.dart index fc507c8..467e605 100644 --- a/lib/src/widgets/item_builder/item_builder_options.dart +++ b/lib/src/widgets/item_builder/item_builder_options.dart @@ -13,7 +13,8 @@ import 'package:flutter/material.dart'; /// Validator can be used to set a validator for the standard textfield. class ItemBuilderOptions { ItemBuilderOptions({ - this.inputDecoration = const InputDecoration(), + this.inputDecoration = const InputDecoration( + constraints: BoxConstraints(maxWidth: 200, maxHeight: 40)), this.inputDecorationField, this.readOnly = false, this.validators, diff --git a/lib/src/widgets/profile/profile_page.dart b/lib/src/widgets/profile/profile_page.dart index cc98558..c1c691a 100644 --- a/lib/src/widgets/profile/profile_page.dart +++ b/lib/src/widgets/profile/profile_page.dart @@ -41,6 +41,7 @@ class ProfilePage extends StatefulWidget { this.prioritizedItems = const [], this.showDefaultItems = true, this.wrapItemsBuilder, + this.wrapViewOptions, }) : super(key: key); /// User containing all the user data. @@ -76,6 +77,9 @@ class ProfilePage extends StatefulWidget { /// Shows textfields for firstname and lastname if is set to true final bool showDefaultItems; + /// Edit the direction and spacing between every item + final WrapViewOptions? wrapViewOptions; + @override State createState() => _ProfilePageState(); } @@ -98,6 +102,16 @@ class _ProfilePageState extends State { prioritizedItems: widget.prioritizedItems, showDefaultItems: widget.showDefaultItems, wrapItemsBuilder: widget.wrapItemsBuilder, + wrapViewOptions: widget.wrapViewOptions, ); } } + +class WrapViewOptions { + WrapViewOptions( + {this.direction, this.spacing, this.runSpacing, this.clipBehavior}); + Axis? direction; + double? spacing; + double? runSpacing; + Clip? clipBehavior; +} diff --git a/lib/src/widgets/profile/profile_wrapper.dart b/lib/src/widgets/profile/profile_wrapper.dart index 391eda2..3ec9fcb 100644 --- a/lib/src/widgets/profile/profile_wrapper.dart +++ b/lib/src/widgets/profile/profile_wrapper.dart @@ -9,6 +9,7 @@ import 'package:flutter_profile/src/widgets/avatar/avatar_wrapper.dart'; import 'package:flutter_profile/src/widgets/item_builder/item_builder.dart'; import 'package:flutter_profile/src/widgets/item_builder/item_builder_options.dart'; import 'package:flutter_profile/src/widgets/item_builder/item_list.dart'; +import 'package:flutter_profile/src/widgets/profile/profile_page.dart'; import 'package:flutter_profile/src/widgets/profile/profile_style.dart'; class ProfileWrapper extends StatefulWidget { @@ -21,6 +22,7 @@ class ProfileWrapper extends StatefulWidget { this.showAvatar = true, this.itemBuilder, this.itemBuilderOptions, + this.wrapViewOptions, this.bottomActionText, this.prioritizedItems = const [], this.showDefaultItems = true, @@ -35,6 +37,7 @@ class ProfileWrapper extends StatefulWidget { final bool showAvatar; final String? bottomActionText; final ItemBuilder? itemBuilder; + final WrapViewOptions? wrapViewOptions; final Function rebuild; final ItemBuilderOptions? itemBuilderOptions; final bool showDefaultItems; @@ -147,7 +150,11 @@ class _ProfileWrapperState extends State { ), ); } - var items = Column( + var items = Wrap( + direction: widget.wrapViewOptions?.direction ?? Axis.vertical, + spacing: widget.wrapViewOptions?.spacing ?? 0, + runSpacing: widget.wrapViewOptions?.runSpacing ?? 0, + clipBehavior: widget.wrapViewOptions?.clipBehavior ?? Clip.none, children: [ ItemList( Map.fromEntries(widget.user.profileData!.toMap().entries.where( diff --git a/pubspec.yaml b/pubspec.yaml index f59b421..b270ab8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_profile description: Flutter profile package -version: 0.0.11 +version: 1.0.1 repository: https://github.com/Iconica-Development/flutter_profile environment: @@ -17,4 +17,4 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.0 -flutter: \ No newline at end of file +flutter: