mirror of
https://github.com/Iconica-Development/flutter_profile.git
synced 2025-05-19 01:03:45 +02:00
Merge pull request #16 from Iconica-Development/feat/wrap
now with wrap!
This commit is contained in:
commit
3dca4489ba
9 changed files with 139 additions and 67 deletions
|
@ -21,3 +21,7 @@
|
|||
## 0.0.11
|
||||
|
||||
* Fixed bug where some field wouldn't update when submitted.
|
||||
|
||||
## 1.0.1
|
||||
|
||||
* Added a default wrap instead of column
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<ProfileExample> {
|
|||
@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<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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<ProfilePage> createState() => _ProfilePageState();
|
||||
}
|
||||
|
@ -98,6 +102,16 @@ class _ProfilePageState extends State<ProfilePage> {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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<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: [
|
||||
ItemList(
|
||||
Map.fromEntries(widget.user.profileData!.toMap().entries.where(
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue