Skip to content

Commit

Permalink
feat: added pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Oct 5, 2024
1 parent 021694b commit be31019
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 112 deletions.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Components are always prefixed with `ImpaktfullUi` to avoid conflicts with other
- ImpaktfullUiNetworkImage
- ImpaktfullUiNotification
- ImpaktfullUiNotificationBadge
- ImpaktfullUiPagination
- ImpaktfullUiRefreshIndicator
- ImpaktfullUiSideNavigation
- ImpaktfullUiSideNavigationItem
- ImpaktfullUiSnackyConfigurator
Expand All @@ -84,21 +86,20 @@ Components are always prefixed with `ImpaktfullUi` to avoid conflicts with other

Many more to come in the future, always with the focus on minimizing maintenance and maximizing a recognizable UI/brand for impaktfull

- ImpaktfullDatePicker
- ImpaktfullDateTimePicker
- ImpaktfullDateTimePickerDialog
- ImpaktfullDateTimeRangePicker
- ImpaktfullListItemTitle
- ImpaktfullNavBar
- ImpaktfullPagination
- ImpaktfullRadioButtonListItem
- ImpaktfullScreen
- ImpaktfullSelectableListItem
- ImpaktfullSeparatedColumn
- ImpaktfullSwitchListItem
- ImpaktfullTabBar
- ImpaktfullTabBarItem
- ImpaktfullTimePicker
- ImpaktfullUiDatePicker
- ImpaktfullUiDateTimePicker
- ImpaktfullUiDateTimePickerDialog
- ImpaktfullUiDateTimeRangePicker
- ImpaktfullUiListItemTitle
- ImpaktfullUiNavBar
- ImpaktfullUiRadioButtonListItem
- ImpaktfullUiScreen
- ImpaktfullUiSelectableListItem
- ImpaktfullUiSeparatedColumn
- ImpaktfullUiSwitchListItem
- ImpaktfullUiTabBar
- ImpaktfullUiTabBarItem
- ImpaktfullUiTimePicker

### Theming

Expand All @@ -125,6 +126,9 @@ These icons can be overriden in the theme itself. By adding your own IconData.

- add
- arrowLeft
- arrowRight
- arrowUp
- arrowDown
- check
- chevronDown
- chevronLeft
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:impaktfull_ui_example/src/component_library/components/pagination/pagination_library_variant.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_inputs.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/inputs/component_library_int_input.dart';

class PaginationLibraryItem extends ComponentLibraryItem {
const PaginationLibraryItem();

@override
String get title => 'ImpaktfullUiPagination';

@override
List<ComponentLibraryVariant> getComponentVariants() {
return [
const PaginationLibraryVariant(),
];
}
}

class PaginationLibraryInputs extends ComponentLibraryInputs {
final ComponentLibraryIntInput page = ComponentLibraryIntInput(
'Page',
initialValue: 1,
);
final ComponentLibraryIntInput amountOfItems = ComponentLibraryIntInput(
'amountOfItems',
initialValue: 55,
);
final ComponentLibraryIntInput itemsPerPage = ComponentLibraryIntInput(
'itemsPerPage',
initialValue: 10,
);
@override
List<ComponentLibraryInputItem> buildInputItems() => [
itemsPerPage,
amountOfItems,
page,
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:impaktfull_ui_2/impaktfull_ui.dart';
import 'package:impaktfull_ui_example/src/component_library/components/pagination/pagination_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/config/component_library_item.dart';

class PaginationLibraryVariant extends ComponentLibraryVariant<PaginationLibraryPrimaryInputs> {
const PaginationLibraryVariant();

@override
String get title => 'Default';

@override
List<Widget> build(BuildContext context, PaginationLibraryPrimaryInputs inputs) {
return [
ImpaktfullUiPagination(
amountOfItems: inputs.amountOfItems.value ?? 0,
itemsPerPage: inputs.itemsPerPage.value ?? 0,
page: inputs.page.value ?? 0,
onLoadPage: (page) {
inputs.page.updateState(page);
ImpaktfullUiNotification.show(title: 'Load page $page');
},
),
];
}

@override
PaginationLibraryPrimaryInputs inputs() => PaginationLibraryPrimaryInputs();
}

class PaginationLibraryPrimaryInputs extends PaginationLibraryInputs {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:impaktfull_ui_example/src/component_library/components/loading_i
import 'package:impaktfull_ui_example/src/component_library/components/modal/modal_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/notification/notification_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/notification_badge/notification_badge_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/pagination/pagination_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/refreshindicator/refreshindicator_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/sidebar_navigation/sidebar_navigation_library_item.dart';
import 'package:impaktfull_ui_example/src/component_library/components/simple_list_item/simple_list_item_library_item.dart';
Expand Down Expand Up @@ -57,6 +58,7 @@ class ComponentLibrary {
const ModalLibraryItem(),
const NotificationLibraryItem(),
const NotificationBadgeLibraryItem(),
const PaginationLibraryItem(),
const RefreshIndicatorLibraryItem(),
const SidebarNavigationLibraryItem(),
const SidebarNavigationItemLibraryItem(),
Expand Down
1 change: 1 addition & 0 deletions lib/impaktfull_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export 'src/components/modal/modal.dart';
export 'src/components/network_image/network_image.dart';
export 'src/components/notification/notification.dart';
export 'src/components/notification_badge/notification_badge.dart';
export 'src/components/pagination/pagination.dart';
export 'src/components/refresh_indicator/refresh_indicator.dart';
export 'src/components/sidebar_navigation/sidebar_navigation.dart';
export 'src/components/sidebar_navigation_item/sidebar_navigation_item.dart';
Expand Down
147 changes: 73 additions & 74 deletions lib/src/components/button/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,96 +58,95 @@ class _ImpaktfullUiButtonState extends State<ImpaktfullUiButton> {
bool get hasOnTap => widget.onTap != null || widget.onAsyncTap != null;
@override
Widget build(BuildContext context) {
final iconSize = _getIconSize();
return ImpaktfullUiComponentThemeBuidler<ImpaktfullUiButtonTheme>(
overrideComponentTheme: widget.theme,
builder: (context, theme, componentTheme) {
final iconSize = _getIconSize();
final textStyle = _getTextStyle(componentTheme);
final color = textStyle?.color;
final backgroundColor = _getBackgroundColor(componentTheme);
final borderColor = _getBorderColor(componentTheme);
return ImpaktfullUiTouchFeedback(
color: backgroundColor,
borderRadius: componentTheme.dimens.borderRadius,
border: borderColor == null
? null
: Border.all(
color: borderColor,
width: 1,
strokeAlign: BorderSide.strokeAlignInside,
final isClickable = widget.onTap != null || widget.onAsyncTap != null;
return Opacity(
opacity: isClickable ? 1 : 0.5,
child: ImpaktfullUiTouchFeedback(
color: backgroundColor,
borderRadius: componentTheme.dimens.borderRadius,
border: borderColor == null
? null
: Border.all(
color: borderColor,
width: 1,
strokeAlign: BorderSide.strokeAlignInside,
),
onTap: isClickable ? _onTap : null,
child: Stack(
alignment: Alignment.center,
children: [
Opacity(
opacity: _isLoading ? 0 : 1,
child: Padding(
padding: _getPadding(componentTheme),
child: ImpaktfullUiAutoLayout.horizontal(
mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 4,
children: [
if (widget.leadingChild != null) ...[
widget.leadingChild!,
],
if (widget.leadingIcon != null) ...[
ImpaktfullUiAssetWidget(
asset: widget.leadingIcon,
color: color,
size: iconSize,
),
],
if (widget.title != null) ...[
Expanded(
flex: widget.fullWidth ? 1 : 0,
child: Text(
widget.title!,
textAlign: TextAlign.center,
style: textStyle,
),
),
],
if (widget.trailingIcon != null) ...[
ImpaktfullUiAssetWidget(
asset: widget.trailingIcon,
color: color,
size: iconSize,
),
],
if (widget.trailingChild != null) ...[
widget.trailingChild!,
],
],
),
),
),
onTap:
widget.onTap == null && widget.onAsyncTap == null ? null : _onTap,
child: Stack(
alignment: Alignment.center,
children: [
Opacity(
opacity: _isLoading ? 0 : 1,
child: Padding(
padding: _getPadding(componentTheme),
AnimatedOpacity(
opacity: _isLoading ? 1 : 0,
duration: theme.durations.short,
curve: Curves.easeInOut,
child: ImpaktfullUiAutoLayout.horizontal(
mainAxisSize:
widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 4,
children: [
if (widget.leadingChild != null) ...[
widget.leadingChild!,
],
if (widget.leadingIcon != null) ...[
ImpaktfullUiAssetWidget(
asset: widget.leadingIcon,
color: color,
size: iconSize,
Expanded(
flex: widget.fullWidth ? 1 : 0,
child: SizedBox(
height: _getLoadingSize(),
child: _isLoading ? ImpaktfullUiLoadingIndicator(color: color) : const SizedBox(),
),
],
if (widget.title != null) ...[
Expanded(
flex: widget.fullWidth ? 1 : 0,
child: Text(
widget.title!,
textAlign: TextAlign.center,
style: textStyle,
),
),
],
if (widget.trailingIcon != null) ...[
ImpaktfullUiAssetWidget(
asset: widget.trailingIcon,
color: color,
size: iconSize,
),
],
if (widget.trailingChild != null) ...[
widget.trailingChild!,
],
),
],
),
),
),
AnimatedOpacity(
opacity: _isLoading ? 1 : 0,
duration: theme.durations.short,
curve: Curves.easeInOut,
child: ImpaktfullUiAutoLayout.horizontal(
mainAxisSize:
widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 4,
children: [
Expanded(
flex: widget.fullWidth ? 1 : 0,
child: SizedBox(
height: _getLoadingSize(),
child: _isLoading
? ImpaktfullUiLoadingIndicator(color: color)
: const SizedBox(),
),
),
],
),
),
],
],
),
),
);
},
Expand Down
63 changes: 63 additions & 0 deletions lib/src/components/pagination/pagination.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:impaktfull_ui_2/src/components/auto_layout/auto_layout.dart';
import 'package:impaktfull_ui_2/src/components/button/button.dart';
import 'package:impaktfull_ui_2/src/components/pagination/pagination_style.dart';
import 'package:impaktfull_ui_2/src/components/theme/theme_component_builder.dart';
import 'package:impaktfull_ui_2/src/util/descriptor/component_descriptor_mixin.dart';

export 'pagination_style.dart';

part 'pagination.describe.dart';

class ImpaktfullUiPagination extends StatelessWidget with ComponentDescriptorMixin {
final int page;
final int itemsPerPage;
final int amountOfItems;
final ValueChanged<int> onLoadPage;
final ImpaktfullUiPaginationTheme? theme;

int get amountOfPages => (amountOfItems / itemsPerPage).ceil();
bool get isFinalPage => page == amountOfPages;

const ImpaktfullUiPagination({
required this.page,
required this.itemsPerPage,
required this.amountOfItems,
required this.onLoadPage,
this.theme,
super.key,
});

@override
Widget build(BuildContext context) {
return ImpaktfullUiComponentThemeBuidler<ImpaktfullUiPaginationTheme>(
overrideComponentTheme: theme,
builder: (context, theme, componentTheme) => ImpaktfullUiAutoLayout.horizontal(
spacing: 8,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ImpaktfullUiButton(
type: ImpaktfullUiButtonType.secondaryGrey,
leadingIcon: componentTheme.assets.arrowLeft,
onTap: page == 1 ? null : () => onLoadPage(page - 1),
),
Expanded(
child: Text(
'Page $page of $amountOfPages',
style: componentTheme.textStyles.text,
textAlign: TextAlign.center,
),
),
ImpaktfullUiButton(
type: ImpaktfullUiButtonType.secondaryGrey,
leadingIcon: componentTheme.assets.arrowRight,
onTap: isFinalPage ? null : () => onLoadPage(page + 1),
),
],
),
);
}

@override
String describe(BuildContext context) => _describeInstance(context, this);
}
7 changes: 7 additions & 0 deletions lib/src/components/pagination/pagination.describe.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
part of 'pagination.dart';

String _describeInstance(BuildContext context, ImpaktfullUiPagination instance) {
final descriptor = ComponentDescriptor();
descriptor.add('theme', instance.theme);
return descriptor.describe();
}
Loading

0 comments on commit be31019

Please sign in to comment.