Skip to content

Commit cc59324

Browse files
committed
* Fixed linter warnings
* Updated dependencies * Updated config.. (Added more elements in config) * Updated version
1 parent 4ff5f55 commit cc59324

10 files changed

Lines changed: 318 additions & 133 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [1.2.2] - 07/06/2022
2+
3+
* Fixed linter warnings
4+
* Updated dependencies
5+
* Updated config.. (Added more elements in config)
6+
17
## [1.2.1+1] - 18/04/2022
28

39
* Updated README.md

example/lib/utils/mock_items.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:paginated_items_builder/paginated_items_builder.dart';
22
import 'package:paginated_items_builder_demo/models/post.dart';
33

44
class MockItems {
5-
/// should return either an object of related type,
5+
/// should return either an object of related type [T],
66
/// or a widget.
77
///
88
/// If an object is returned, then this item will be passed to the
@@ -11,7 +11,9 @@ class MockItems {
1111
///
1212
/// But if a widget is returned, then the widget is rendered directly.
1313
///
14-
/// It is rendered inside an [IgnorePointer] to disable any onTap listeners.
14+
/// It is by default rendered inside an [IgnorePointer] to disable any onTap listeners.
15+
///
16+
/// However, this can be changed by passing [PaginatedItemsBuilder.disableLoaderOnTaps] as false.
1517
static dynamic getByType<T>([String? mockItemKey]) {
1618
final key = mockItemKey ?? T.toString();
1719
switch (key) {

example/pubspec.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0"
45+
version: "1.16.0"
4646
dio:
4747
dependency: "direct main"
4848
description:
@@ -63,7 +63,7 @@ packages:
6363
name: fake_async
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "1.2.0"
66+
version: "1.3.0"
6767
flutter:
6868
dependency: "direct main"
6969
description: flutter
@@ -108,7 +108,7 @@ packages:
108108
name: material_color_utilities
109109
url: "https://pub.dartlang.org"
110110
source: hosted
111-
version: "0.1.3"
111+
version: "0.1.4"
112112
meta:
113113
dependency: transitive
114114
description:
@@ -129,14 +129,14 @@ packages:
129129
path: ".."
130130
relative: true
131131
source: path
132-
version: "1.2.1"
132+
version: "1.2.2"
133133
path:
134134
dependency: transitive
135135
description:
136136
name: path
137137
url: "https://pub.dartlang.org"
138138
source: hosted
139-
version: "1.8.0"
139+
version: "1.8.1"
140140
provider:
141141
dependency: "direct main"
142142
description:
@@ -162,7 +162,7 @@ packages:
162162
name: source_span
163163
url: "https://pub.dartlang.org"
164164
source: hosted
165-
version: "1.8.1"
165+
version: "1.8.2"
166166
stack_trace:
167167
dependency: transitive
168168
description:
@@ -197,7 +197,7 @@ packages:
197197
name: test_api
198198
url: "https://pub.dartlang.org"
199199
source: hosted
200-
version: "0.4.8"
200+
version: "0.4.9"
201201
typed_data:
202202
dependency: transitive
203203
description:
@@ -211,7 +211,7 @@ packages:
211211
name: vector_math
212212
url: "https://pub.dartlang.org"
213213
source: hosted
214-
version: "2.1.1"
214+
version: "2.1.2"
215215
sdks:
216-
dart: ">=2.15.1 <3.0.0"
216+
dart: ">=2.17.0-0 <3.0.0"
217217
flutter: ">=1.17.0"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:paginated_items_builder/paginated_items_builder.dart';
3+
4+
/// ConfigDefaults
5+
class ConfigDefaults {
6+
/// getByType
7+
static dynamic getByType<T>([String? mockItemKey]) => null;
8+
9+
/// noItemsTextGetter
10+
static String noItemsTextGetter(String name) {
11+
final beforeCapitalLetter = RegExp(r"(?=[A-Z])");
12+
name = name
13+
.split(beforeCapitalLetter)
14+
.map(
15+
(e) => e.toLowerCase(),
16+
)
17+
.join(' ');
18+
19+
return "No ${name}s found!";
20+
}
21+
22+
/// errorTextGetter
23+
static String errorTextGetter(dynamic error) => 'Something went wrong!';
24+
25+
/// showLoaderOnResetGetter
26+
static bool showLoaderOnResetGetter(scope) =>
27+
scope != ItemsFetchScope.pullDownToRefresh;
28+
29+
/// defaultTextStyle
30+
static const defaultTextStyle = TextStyle(
31+
fontWeight: FontWeight.w600,
32+
fontSize: 14,
33+
);
34+
35+
/// defaultLoader
36+
static const defaultLoader = Center(
37+
child: CircularProgressIndicator.adaptive(),
38+
);
39+
40+
/// logErrors
41+
static const logErrors = true;
42+
43+
/// customScrollPhysics
44+
static const customScrollPhysics = null;
45+
46+
/// padding
47+
static const padding = null;
48+
}
Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
1-
import 'package:flutter/material.dart';
1+
import 'package:flutter/material.dart' hide ErrorWidgetBuilder;
22
import '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].
157
class 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.
86101
class 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
}

lib/src/loader_shimmer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class LoaderShimmer extends StatelessWidget {
4141

4242
@override
4343
Widget build(BuildContext context) {
44-
final _config = PaginatedItemsBuilder.config?.shimmerConfig;
45-
final shimmerConfig = _config ?? ShimmerConfig.defaultShimmer();
44+
final config = PaginatedItemsBuilder.config?.shimmerConfig;
45+
final shimmerConfig = config ?? ShimmerConfig();
4646

4747
if (isLoading) {
4848
return Shimmer.fromColors(

0 commit comments

Comments
 (0)