Skip to content

Commit

Permalink
Merge pull request #231 from edufolly/dev
Browse files Browse the repository at this point in the history
Version 3.20.
  • Loading branch information
edufolly authored May 14, 2024
2 parents 3d296b7 + aa16582 commit 7c2862e
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 127 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ jobs:
- name: Code Checkout
uses: actions/checkout@v4

- name: Get Pubspec Version
- name: Check Pubspec Version
id: version-step
run: |
export VERSION=$(grep 'version:' pubspec.yaml | cut -c 10- | cut -f 1 -d '+')
VERSION=$(grep 'version:' pubspec.yaml | cut -c 10- | cut -f 1 -d '+')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if version is used
run: |
URL=$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/latest
LATEST=$(curl --silent "$URL" | jq -r .name)
if [ "$LATEST" == "v$VERSION" ]; then
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [3.2.0] - 2024-05-14

* Updating to Flutter 3.22.0 and Dart 3.4.0.
* Changing getLeading method from AbstractBuilder to be able to return null.
* Updating ListField:
* Fixing component's alignment.
* Adding properties to configure the icons.
* Feature to manual sort the list.

## [3.1.1] - 2024-05-13

* Updating decorators from:
Expand Down
2 changes: 0 additions & 2 deletions example/lib/code_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class CodeLink extends StatelessWidget {

showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return AlertDialog(
title: Text(tag),
Expand Down Expand Up @@ -132,7 +131,6 @@ class CodeLink extends StatelessWidget {
],
);
},
useSafeArea: true,
);
}

Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ class MyHomePageState extends State<MyHomePage> {
edit: edit,
),
expandable: true,
clearAllButton: true,
showClearAllButton: true,
showCounter: true,
showTopAddButton: true,
onChanged: (List<ExampleModel> value) =>
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ description: A new Flutter project.

publish_to: 'none'

version: 3.1.1+212
version: 3.2.0+213

environment:
sdk: ">=3.3.0 <4.0.0"
flutter: ">=3.19.0"
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"

dependencies:
# https://pub.dev/packages/connectivity_plus
Expand Down
3 changes: 1 addition & 2 deletions lib/crud/abstract_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ abstract class AbstractBuilder<T extends AbstractModel<ID>, ID> {
///
///
///
Widget getLeading(BuildContext context, T model) =>
const FaIcon(FontAwesomeIcons.solidCircle);
Widget? getLeading(BuildContext context, T model) => null;

///
///
Expand Down
23 changes: 14 additions & 9 deletions lib/crud/abstract_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,21 @@ class AbstractListState<
Future<void> Function()? afterDeleteRefresh,
Function(T model)? onTap,
}) {
Widget? leading = widget.builder.getLeading(context, model);
bool multipleSelection = widget.multipleSelection && onTap == null;

return ListTile(
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (widget.multipleSelection && onTap == null)
FaIcon(selected ? widget.selectedIcon : widget.unselectedIcon)
else
widget.builder.getLeading(context, model),
],
),
leading: (leading != null || multipleSelection)
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (multipleSelection)
FaIcon(selected ? widget.selectedIcon : widget.unselectedIcon)
else
leading!,
],
)
: null,
title: widget.builder.getTitle(context, model),
subtitle: widget.builder.getSubtitle(context, model),
trailing: Row(
Expand Down
216 changes: 137 additions & 79 deletions lib/fields/list_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ class ListField<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
int Function(T a, T b)? listSort,
bool expandable = false,
bool initialExpanded = true,
bool clearAllButton = false,
bool showClearAllButton = false,
Icon clearAllIcon = const Icon(FontAwesomeIcons.solidTrashCan),
Widget Function(BuildContext context, List<T> value)? onCollapsed,
bool showCounter = false,
bool showTopAddButton = false,
Icon topAddIcon = const Icon(FontAwesomeIcons.plus),
bool showDeleteButton = true,
Icon deleteIcon = const Icon(FontAwesomeIcons.trashCan),
bool showAddButton = true,
String? hintText,
EdgeInsets? contentPadding,
Widget? prefix,
Widget? prefixIcon,
Widget? suffix,
Widget? suffixIcon,
bool sortable = false,
super.sizeExtraSmall,
super.sizeSmall,
super.sizeMedium,
Expand Down Expand Up @@ -129,10 +133,9 @@ class ListField<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
}

if (changed) {
field.value!.sort(
listSort ??
(T a, T b) => a.toString().compareTo(b.toString()),
);
if (listSort != null && !sortable) {
field.value?.sort(listSort);
}

onChanged?.call(field.value!);

Expand All @@ -153,78 +156,91 @@ class ListField<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
child: Column(
children: <Widget>[
/// Top Bar
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
/// Counter
if (showCounter)
Chip(
label: Text(field.value!.length.toString()),
),
if (showCounter ||
showTopAddButton ||
expandable ||
showClearAllButton)
Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 24, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
/// Left
if (showCounter || showTopAddButton)
Row(
children: <Widget>[
/// Top Add Button
if (showTopAddButton)
IconButton(
onPressed: add,
icon: topAddIcon,
),

/// Top Add Button
if (showTopAddButton)
IconButton(
onPressed: add,
icon: const Icon(FontAwesomeIcons.plus),
),
],
),
Row(
children: <Widget>[
/// Expand Button
if (expandable)
ExpandableButton(
child: ExpandableIcon(
theme: ExpandableThemeData(
iconColor: Theme.of(field.context)
.iconTheme
.color,
collapseIcon: FontAwesomeIcons.compress,
expandIcon: FontAwesomeIcons.expand,
iconSize: 24,
iconPadding: const EdgeInsets.all(4),
/// Counter
if (showCounter)
Chip(
label: Text(
field.value!.length.toString(),
),
),
],
),

/// Right
Row(
children: <Widget>[
/// Expand Button
if (expandable)
ExpandableButton(
child: ExpandableIcon(
theme: ExpandableThemeData(
iconColor: Theme.of(field.context)
.iconTheme
.color,
collapseIcon:
FontAwesomeIcons.compress,
expandIcon: FontAwesomeIcons.expand,
iconSize: 24,
iconPadding: const EdgeInsets.all(8),
),
),
),
),

/// Clear All Button
if (clearAllButton)
IconButton(
onPressed: field.value!.isEmpty
? null
: () {
FollyDialogs.yesNoDialog(
context: field.context,
message: sprintf(
clearText,
<dynamic>[
builder.superSingle(
field.context,
),
],
),
).then(
(bool del) {
if (del) {
field.value!.clear();
onChanged?.call(field.value!);
field.didChange(field.value);
}
},
);
},
icon: const Icon(FontAwesomeIcons.trashCan),
),
],
),
],
/// Clear All Button
if (showClearAllButton)
IconButton(
onPressed: field.value!.isEmpty
? null
: () {
FollyDialogs.yesNoDialog(
context: field.context,
message: sprintf(
clearText,
<dynamic>[
builder.superSingle(
field.context,
),
],
),
).then(
(bool del) {
if (del) {
field.value!.clear();
onChanged
?.call(field.value!);
field
.didChange(field.value);
}
},
);
},
icon: clearAllIcon,
),
],
),
],
),
),
),
Expandable(
collapsed: field.value!.isEmpty
? Padding(
Expand Down Expand Up @@ -267,6 +283,8 @@ class ListField<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
listSort: listSort,
onChanged: onChanged,
showDeleteButton: showDeleteButton,
deleteIcon: deleteIcon,
sortable: sortable,
),
),

Expand Down Expand Up @@ -319,6 +337,8 @@ class _MyListTile<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
final int Function(T a, T b)? listSort;
final void Function(List<T> value)? onChanged;
final bool showDeleteButton;
final Icon deleteIcon;
final bool sortable;

///
///
Expand All @@ -336,6 +356,8 @@ class _MyListTile<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
required this.listSort,
required this.onChanged,
required this.showDeleteButton,
required this.deleteIcon,
required this.sortable,
super.key,
});

Expand All @@ -344,21 +366,57 @@ class _MyListTile<T extends AbstractModel<ID>, B extends AbstractBuilder<T, ID>,
///
@override
Widget build(BuildContext context) {
Widget? leading = builder.getLeading(context, model);

return ChildBuilder(
child: ListTile(
enabled: enabled,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
builder.getLeading(context, model),
],
),
leading: (sortable || leading != null)
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (sortable)
IconButton(
icon: const Icon(FontAwesomeIcons.arrowUp),
onPressed: (enabled && index == 0)
? null
: () {
T? element = field.value?.removeAt(index);
if (element != null) {
field.value?.insert(index - 1, element);
field.didChange(field.value);
}
},
),
if (sortable)
IconButton(
icon: const Icon(FontAwesomeIcons.arrowDown),
onPressed: (enabled &&
index == (field.value?.length ?? 1) - 1)
? null
: () {
T? element = field.value?.removeAt(index);
if (element != null) {
field.value?.insert(index + 1, element);
field.didChange(field.value);
}
},
),
if (leading != null) leading,
],
),
],
)
: null,
title: builder.getTitle(context, model),
subtitle: builder.getSubtitle(context, model),
trailing: Visibility(
visible: FollyFields().isNotMobile && enabled && showDeleteButton,
child: IconButton(
icon: const Icon(FontAwesomeIcons.trashCan),
icon: deleteIcon,
onPressed: enabled
? () => _delete(context, index, model, ask: true)
: null,
Expand Down
Loading

0 comments on commit 7c2862e

Please sign in to comment.