1- import 'package:flutter/material.dart' ;
1+ import 'package:flutter/material.dart' hide ErrorWidgetBuilder ;
22import 'package:paginated_items_builder/paginated_items_builder.dart' ;
3-
4- dynamic _getByType <T >([String ? mockItemKey]) => null ;
5-
6- String _noItemsTextGetter (String name) {
7- final beforeCapitalLetter = RegExp (r"(?=[A-Z])" );
8- name = name.split (beforeCapitalLetter).map ((e) => e.toLowerCase ()).join (' ' );
9- return "No ${name }s found!" ;
10- }
11-
12- String _errorTextGetter (dynamic error) => 'Something went wrong!' ;
3+ import 'package:paginated_items_builder/src/config/config_defaults.dart' ;
4+ import 'package:paginated_items_builder/src/type_definitions.dart' ;
135
146/// The config for [PaginatedItemsBuilder] .
157class PaginatedItemsBuilderConfig {
168 PaginatedItemsBuilderConfig ({
179 ShimmerConfig ? shimmerConfig,
18- this .mockItemGetter = _getByType,
19- this .noItemsTextGetter = _noItemsTextGetter,
20- this .errorTextGetter = _errorTextGetter,
21- this .noItemsTextStyle = const TextStyle (
22- fontWeight: FontWeight .w600,
23- fontSize: 14 ,
24- ),
25- this .logErrors = true ,
26- }) : shimmerConfig = shimmerConfig ?? ShimmerConfig .defaultShimmer ();
27-
28- /// Default config
29- PaginatedItemsBuilderConfig .defaultConfig () {
30- shimmerConfig = ShimmerConfig .defaultShimmer ();
31- mockItemGetter = _getByType;
32- noItemsTextGetter = _noItemsTextGetter;
33- errorTextGetter = _errorTextGetter;
34- noItemsTextStyle = const TextStyle (
35- fontWeight: FontWeight .w600,
36- fontSize: 14 ,
37- );
38- logErrors = true ;
10+ this .mockItemGetter = ConfigDefaults .getByType,
11+ this .noItemsTextGetter = ConfigDefaults .noItemsTextGetter,
12+ this .errorTextGetter = ConfigDefaults .errorTextGetter,
13+ this .showLoaderOnResetGetter = ConfigDefaults .showLoaderOnResetGetter,
14+ this .noItemsTextStyle = ConfigDefaults .defaultTextStyle,
15+ this .errorTextStyle = ConfigDefaults .defaultTextStyle,
16+ this .loader = ConfigDefaults .defaultLoader,
17+ this .bottomLoader = ConfigDefaults .defaultLoader,
18+ this .logErrors = ConfigDefaults .logErrors,
19+ this .customScrollPhysics = ConfigDefaults .customScrollPhysics,
20+ this .padding = ConfigDefaults .padding,
21+ }) {
22+ shimmerConfig = shimmerConfig ?? ShimmerConfig ();
3923 }
4024
4125 /// Create a function and pass the reference to this.
@@ -46,9 +30,14 @@ class PaginatedItemsBuilderConfig {
4630 ///
4731 /// You can also return a widget from this method, then that widget
4832 /// will be built in place of the loader.
33+ ///
4934 /// The widget is wrapped in an [IgnorePointer] when built to disable any
5035 /// onTap gesture listeners.
5136 ///
37+ /// However, this can be changed by passing
38+ /// [PaginatedItemsBuilder.disableLoaderOnTaps] as false,
39+ /// if you want to have loader onTap handlers...
40+ ///
5241 /// ```dart
5342 /// class MockItems {
5443 /// static dynamic getByType<T>([String? mockItemKey]) {
@@ -68,33 +57,59 @@ class PaginatedItemsBuilderConfig {
6857 /// color, or the duration.
6958 late final ShimmerConfig shimmerConfig;
7059
71- /// Customize the text that is rendered when there are no items to display.
72- late final String Function ( String name) noItemsTextGetter;
60+ /// {@macro noItemsTextGetter}
61+ late final NoItemsTextGetter noItemsTextGetter;
7362
74- /// Customize the text that is rendered when an occurs.
75- late final String Function ( dynamic error) errorTextGetter ;
63+ /// {@macro noItemsWidgetBuilder}
64+ late final NoItemsWidgetBuilder noItemsWidgetBuilder ;
7665
77- /// Customize the style of the text that is rendered when there
78- /// are no items to display.
66+ /// {@macro noItemsTextStyle}
7967 late final TextStyle noItemsTextStyle;
8068
81- /// Whether to log errors to the console or not.
69+ /// {@macro errorTextGetter}
70+ late final ErrorTextGetter errorTextGetter;
71+
72+ /// {@macro errorWidgetBuilder}
73+ late final ErrorWidgetBuilder errorWidgetBuilder;
74+
75+ /// {@macro errorTextStyle}
76+ late final TextStyle errorTextStyle;
77+
78+ /// {@macro loader}
79+ late final Widget loader;
80+
81+ /// {@macro bottomLoader}
82+ late final Widget bottomLoader;
83+
84+ /// {@macro showLoaderOnResetGetter}
85+ late final ShowLoaderOnResetGetter showLoaderOnResetGetter;
86+
87+ /// {@macro logErrors}
8288 late final bool logErrors;
89+
90+ /// {@macro customScrollPhysics}
91+ late final ScrollPhysics ? customScrollPhysics;
92+
93+ /// {@macro padding}
94+ late final EdgeInsets ? padding;
95+
96+ /// {@macro refreshIconBuilder}
97+ late final RefreshIconBuilder ? refreshIconBuilder;
8398}
8499
85100/// [ShimmerConfig] class to customize the loading shimmer colors, duration etc.
86101class ShimmerConfig {
87102 /// The shimmer's base color. Defaults to Colors.grey[300] .
88- late final Color baseColor;
103+ final Color baseColor;
89104
90105 /// The shimmer's highlight color. Defaults to Colors.grey[200] .
91- late final Color highlightColor;
106+ final Color highlightColor;
92107
93108 /// The shimmer's duration. Defaults to 800ms.
94- late final Duration duration;
109+ final Duration duration;
95110
96111 /// The shimmer's direction. Defaults to [ShimmerDirection.ltr] .
97- late final ShimmerDirection direction;
112+ final ShimmerDirection direction;
98113
99114 static final _defaultBaseColor = Colors .grey[300 ]! ;
100115 static final _defaultHighlightColor = Colors .grey[200 ]! ;
@@ -108,12 +123,4 @@ class ShimmerConfig {
108123 this .duration = _defaultDuration,
109124 }) : baseColor = baseColor ?? _defaultBaseColor,
110125 highlightColor = highlightColor ?? _defaultHighlightColor;
111-
112- /// default
113- ShimmerConfig .defaultShimmer () {
114- baseColor = _defaultBaseColor;
115- highlightColor = _defaultHighlightColor;
116- direction = _defaultDirection;
117- duration = _defaultDuration;
118- }
119126}
0 commit comments