Merge pull request #16 from Iconica-Development/feat/wrap

now with wrap!
This commit is contained in:
joonsv 2022-12-01 15:35:19 +01:00 committed by GitHub
commit 3dca4489ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 139 additions and 67 deletions

View file

@ -20,4 +20,8 @@
## 0.0.11 ## 0.0.11
* Fixed bug where some field wouldn't update when submitted. * Fixed bug where some field wouldn't update when submitted.
## 1.0.1
* Added a default wrap instead of column

View file

@ -4,7 +4,7 @@
# This file should be version controlled. # This file should be version controlled.
version: version:
revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
channel: stable channel: stable
project_type: app project_type: app
@ -13,23 +13,26 @@ project_type: app
migration: migration:
platforms: platforms:
- platform: root - platform: root
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: android - platform: android
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: ios - platform: ios
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: linux - platform: linux
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: macos - platform: macos
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: web - platform: web
create_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: 52b3dc25f6471c27b2144594abb11c741cb88f57 base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: windows
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
# User provided section # User provided section

View file

@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:example/utils/example_profile_service.dart'; import 'package:example/utils/example_profile_service.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_profile/flutter_profile.dart'; import 'package:flutter_profile/flutter_profile.dart';
import 'utils/example_profile_data.dart'; import 'utils/example_profile_data.dart';
@ -53,53 +54,98 @@ class _ProfileExampleState extends State<ProfileExample> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: ProfilePage( body: Center(
bottomActionText: 'Log out', child: ProfilePage(
itemBuilderOptions: ItemBuilderOptions( wrapViewOptions:
inputDecorationField: { WrapViewOptions(direction: Axis.vertical, spacing: 16),
'first_name': const InputDecoration( bottomActionText: 'Log out',
label: Text('First name'), itemBuilderOptions: ItemBuilderOptions(
), inputDecorationField: {
'last_name': const InputDecoration( 'first_name': const InputDecoration(
label: Text('Last name'), constraints: BoxConstraints(maxHeight: 70, maxWidth: 200),
), label: Text('First name'),
'email': const InputDecoration( ),
label: Text('E-mail'), 'last_name': const InputDecoration(
), constraints: BoxConstraints(maxHeight: 70, maxWidth: 150),
}, label: Text('First name'),
validators: { ),
'first_name': (String? value) {
if (value == null || value.isEmpty) {
return 'Field empty';
}
return null;
}, },
'last_name': (String? value) { validators: {
if (value == null || value.isEmpty) { 'first_name': (String? value) {
return 'Field empty'; if (value == null || value.isEmpty) {
} return 'Field empty';
return null; }
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) { user: _user,
return 'Field empty'; service: ExampleProfileService(),
} style: ProfileStyle(
return null; avatarTextStyle: const TextStyle(fontSize: 20),
}, pagePadding: EdgeInsets.only(
}, top: 50,
), bottom: 50,
user: _user, left: MediaQuery.of(context).size.width * 0.1,
service: ExampleProfileService(), right: MediaQuery.of(context).size.width * 0.1,
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,
), ),
), ),
), ),
); );
} }
} }
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<FormFieldState>();
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;
}
}

View file

@ -124,7 +124,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "0.0.11" version: "1.0.1"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter

View file

@ -3,7 +3,7 @@ description: A new Flutter project.
# The following line prevents the package from being accidentally published to # The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages. # 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. # The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43 # A version number is three numbers separated by dots, like 1.2.43
@ -30,7 +30,6 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
@ -53,10 +52,8 @@ dev_dependencies:
# The following section is specific to Flutter packages. # The following section is specific to Flutter packages.
flutter: flutter:
assets:
# The following line ensures that the Material Icons font is - image/
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true uses-material-design: true
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets:

View file

@ -13,7 +13,8 @@ import 'package:flutter/material.dart';
/// Validator can be used to set a validator for the standard textfield. /// Validator can be used to set a validator for the standard textfield.
class ItemBuilderOptions { class ItemBuilderOptions {
ItemBuilderOptions({ ItemBuilderOptions({
this.inputDecoration = const InputDecoration(), this.inputDecoration = const InputDecoration(
constraints: BoxConstraints(maxWidth: 200, maxHeight: 40)),
this.inputDecorationField, this.inputDecorationField,
this.readOnly = false, this.readOnly = false,
this.validators, this.validators,

View file

@ -41,6 +41,7 @@ class ProfilePage extends StatefulWidget {
this.prioritizedItems = const [], this.prioritizedItems = const [],
this.showDefaultItems = true, this.showDefaultItems = true,
this.wrapItemsBuilder, this.wrapItemsBuilder,
this.wrapViewOptions,
}) : super(key: key); }) : super(key: key);
/// User containing all the user data. /// 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 /// Shows textfields for firstname and lastname if is set to true
final bool showDefaultItems; final bool showDefaultItems;
/// Edit the direction and spacing between every item
final WrapViewOptions? wrapViewOptions;
@override @override
State<ProfilePage> createState() => _ProfilePageState(); State<ProfilePage> createState() => _ProfilePageState();
} }
@ -98,6 +102,16 @@ class _ProfilePageState extends State<ProfilePage> {
prioritizedItems: widget.prioritizedItems, prioritizedItems: widget.prioritizedItems,
showDefaultItems: widget.showDefaultItems, showDefaultItems: widget.showDefaultItems,
wrapItemsBuilder: widget.wrapItemsBuilder, 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;
}

View file

@ -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.dart';
import 'package:flutter_profile/src/widgets/item_builder/item_builder_options.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/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'; import 'package:flutter_profile/src/widgets/profile/profile_style.dart';
class ProfileWrapper extends StatefulWidget { class ProfileWrapper extends StatefulWidget {
@ -21,6 +22,7 @@ class ProfileWrapper extends StatefulWidget {
this.showAvatar = true, this.showAvatar = true,
this.itemBuilder, this.itemBuilder,
this.itemBuilderOptions, this.itemBuilderOptions,
this.wrapViewOptions,
this.bottomActionText, this.bottomActionText,
this.prioritizedItems = const [], this.prioritizedItems = const [],
this.showDefaultItems = true, this.showDefaultItems = true,
@ -35,6 +37,7 @@ class ProfileWrapper extends StatefulWidget {
final bool showAvatar; final bool showAvatar;
final String? bottomActionText; final String? bottomActionText;
final ItemBuilder? itemBuilder; final ItemBuilder? itemBuilder;
final WrapViewOptions? wrapViewOptions;
final Function rebuild; final Function rebuild;
final ItemBuilderOptions? itemBuilderOptions; final ItemBuilderOptions? itemBuilderOptions;
final bool showDefaultItems; final bool showDefaultItems;
@ -147,7 +150,11 @@ class _ProfileWrapperState extends State<ProfileWrapper> {
), ),
); );
} }
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: [ children: [
ItemList( ItemList(
Map.fromEntries(widget.user.profileData!.toMap().entries.where( Map.fromEntries(widget.user.profileData!.toMap().entries.where(

View file

@ -1,6 +1,6 @@
name: flutter_profile name: flutter_profile
description: Flutter profile package description: Flutter profile package
version: 0.0.11 version: 1.0.1
repository: https://github.com/Iconica-Development/flutter_profile repository: https://github.com/Iconica-Development/flutter_profile
environment: environment:
@ -17,4 +17,4 @@ dev_dependencies:
sdk: flutter sdk: flutter
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0
flutter: flutter: