Skip to content

Commit

Permalink
* Fixed linter warnings
Browse files Browse the repository at this point in the history
* Updated dependencies
* Updated config.. (Added more elements in config)
* Updated version
  • Loading branch information
rithik-dev committed Jun 7, 2022
1 parent 4ff5f55 commit cc59324
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 133 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.2.2] - 07/06/2022

* Fixed linter warnings
* Updated dependencies
* Updated config.. (Added more elements in config)

## [1.2.1+1] - 18/04/2022

* Updated README.md
Expand Down
6 changes: 4 additions & 2 deletions example/lib/utils/mock_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:paginated_items_builder/paginated_items_builder.dart';
import 'package:paginated_items_builder_demo/models/post.dart';

class MockItems {
/// should return either an object of related type,
/// should return either an object of related type [T],
/// or a widget.
///
/// If an object is returned, then this item will be passed to the
Expand All @@ -11,7 +11,9 @@ class MockItems {
///
/// But if a widget is returned, then the widget is rendered directly.
///
/// It is rendered inside an [IgnorePointer] to disable any onTap listeners.
/// It is by default rendered inside an [IgnorePointer] to disable any onTap listeners.
///
/// However, this can be changed by passing [PaginatedItemsBuilder.disableLoaderOnTaps] as false.
static dynamic getByType<T>([String? mockItemKey]) {
final key = mockItemKey ?? T.toString();
switch (key) {
Expand Down
18 changes: 9 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
dio:
dependency: "direct main"
description:
Expand All @@ -63,7 +63,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -108,7 +108,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -129,14 +129,14 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.1"
version: "1.2.2"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
provider:
dependency: "direct main"
description:
Expand All @@ -162,7 +162,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -197,7 +197,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
typed_data:
dependency: transitive
description:
Expand All @@ -211,7 +211,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.15.1 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.17.0"
48 changes: 48 additions & 0 deletions lib/src/config/config_defaults.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:paginated_items_builder/paginated_items_builder.dart';

/// ConfigDefaults
class ConfigDefaults {
/// getByType
static dynamic getByType<T>([String? mockItemKey]) => null;

/// noItemsTextGetter
static String noItemsTextGetter(String name) {
final beforeCapitalLetter = RegExp(r"(?=[A-Z])");
name = name
.split(beforeCapitalLetter)
.map(
(e) => e.toLowerCase(),
)
.join(' ');

return "No ${name}s found!";
}

/// errorTextGetter
static String errorTextGetter(dynamic error) => 'Something went wrong!';

/// showLoaderOnResetGetter
static bool showLoaderOnResetGetter(scope) =>
scope != ItemsFetchScope.pullDownToRefresh;

/// defaultTextStyle
static const defaultTextStyle = TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
);

/// defaultLoader
static const defaultLoader = Center(
child: CircularProgressIndicator.adaptive(),
);

/// logErrors
static const logErrors = true;

/// customScrollPhysics
static const customScrollPhysics = null;

/// padding
static const padding = null;
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide ErrorWidgetBuilder;
import 'package:paginated_items_builder/paginated_items_builder.dart';

dynamic _getByType<T>([String? mockItemKey]) => null;

String _noItemsTextGetter(String name) {
final beforeCapitalLetter = RegExp(r"(?=[A-Z])");
name = name.split(beforeCapitalLetter).map((e) => e.toLowerCase()).join(' ');
return "No ${name}s found!";
}

String _errorTextGetter(dynamic error) => 'Something went wrong!';
import 'package:paginated_items_builder/src/config/config_defaults.dart';
import 'package:paginated_items_builder/src/type_definitions.dart';

/// The config for [PaginatedItemsBuilder].
class PaginatedItemsBuilderConfig {
PaginatedItemsBuilderConfig({
ShimmerConfig? shimmerConfig,
this.mockItemGetter = _getByType,
this.noItemsTextGetter = _noItemsTextGetter,
this.errorTextGetter = _errorTextGetter,
this.noItemsTextStyle = const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
),
this.logErrors = true,
}) : shimmerConfig = shimmerConfig ?? ShimmerConfig.defaultShimmer();

/// Default config
PaginatedItemsBuilderConfig.defaultConfig() {
shimmerConfig = ShimmerConfig.defaultShimmer();
mockItemGetter = _getByType;
noItemsTextGetter = _noItemsTextGetter;
errorTextGetter = _errorTextGetter;
noItemsTextStyle = const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14,
);
logErrors = true;
this.mockItemGetter = ConfigDefaults.getByType,
this.noItemsTextGetter = ConfigDefaults.noItemsTextGetter,
this.errorTextGetter = ConfigDefaults.errorTextGetter,
this.showLoaderOnResetGetter = ConfigDefaults.showLoaderOnResetGetter,
this.noItemsTextStyle = ConfigDefaults.defaultTextStyle,
this.errorTextStyle = ConfigDefaults.defaultTextStyle,
this.loader = ConfigDefaults.defaultLoader,
this.bottomLoader = ConfigDefaults.defaultLoader,
this.logErrors = ConfigDefaults.logErrors,
this.customScrollPhysics = ConfigDefaults.customScrollPhysics,
this.padding = ConfigDefaults.padding,
}) {
shimmerConfig = shimmerConfig ?? ShimmerConfig();
}

/// Create a function and pass the reference to this.
Expand All @@ -46,9 +30,14 @@ class PaginatedItemsBuilderConfig {
///
/// You can also return a widget from this method, then that widget
/// will be built in place of the loader.
///
/// The widget is wrapped in an [IgnorePointer] when built to disable any
/// onTap gesture listeners.
///
/// However, this can be changed by passing
/// [PaginatedItemsBuilder.disableLoaderOnTaps] as false,
/// if you want to have loader onTap handlers...
///
/// ```dart
/// class MockItems {
/// static dynamic getByType<T>([String? mockItemKey]) {
Expand All @@ -68,33 +57,59 @@ class PaginatedItemsBuilderConfig {
/// color, or the duration.
late final ShimmerConfig shimmerConfig;

/// Customize the text that is rendered when there are no items to display.
late final String Function(String name) noItemsTextGetter;
/// {@macro noItemsTextGetter}
late final NoItemsTextGetter noItemsTextGetter;

/// Customize the text that is rendered when an occurs.
late final String Function(dynamic error) errorTextGetter;
/// {@macro noItemsWidgetBuilder}
late final NoItemsWidgetBuilder noItemsWidgetBuilder;

/// Customize the style of the text that is rendered when there
/// are no items to display.
/// {@macro noItemsTextStyle}
late final TextStyle noItemsTextStyle;

/// Whether to log errors to the console or not.
/// {@macro errorTextGetter}
late final ErrorTextGetter errorTextGetter;

/// {@macro errorWidgetBuilder}
late final ErrorWidgetBuilder errorWidgetBuilder;

/// {@macro errorTextStyle}
late final TextStyle errorTextStyle;

/// {@macro loader}
late final Widget loader;

/// {@macro bottomLoader}
late final Widget bottomLoader;

/// {@macro showLoaderOnResetGetter}
late final ShowLoaderOnResetGetter showLoaderOnResetGetter;

/// {@macro logErrors}
late final bool logErrors;

/// {@macro customScrollPhysics}
late final ScrollPhysics? customScrollPhysics;

/// {@macro padding}
late final EdgeInsets? padding;

/// {@macro refreshIconBuilder}
late final RefreshIconBuilder? refreshIconBuilder;
}

/// [ShimmerConfig] class to customize the loading shimmer colors, duration etc.
class ShimmerConfig {
/// The shimmer's base color. Defaults to Colors.grey[300].
late final Color baseColor;
final Color baseColor;

/// The shimmer's highlight color. Defaults to Colors.grey[200].
late final Color highlightColor;
final Color highlightColor;

/// The shimmer's duration. Defaults to 800ms.
late final Duration duration;
final Duration duration;

/// The shimmer's direction. Defaults to [ShimmerDirection.ltr].
late final ShimmerDirection direction;
final ShimmerDirection direction;

static final _defaultBaseColor = Colors.grey[300]!;
static final _defaultHighlightColor = Colors.grey[200]!;
Expand All @@ -108,12 +123,4 @@ class ShimmerConfig {
this.duration = _defaultDuration,
}) : baseColor = baseColor ?? _defaultBaseColor,
highlightColor = highlightColor ?? _defaultHighlightColor;

/// default
ShimmerConfig.defaultShimmer() {
baseColor = _defaultBaseColor;
highlightColor = _defaultHighlightColor;
direction = _defaultDirection;
duration = _defaultDuration;
}
}
4 changes: 2 additions & 2 deletions lib/src/loader_shimmer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class LoaderShimmer extends StatelessWidget {

@override
Widget build(BuildContext context) {
final _config = PaginatedItemsBuilder.config?.shimmerConfig;
final shimmerConfig = _config ?? ShimmerConfig.defaultShimmer();
final config = PaginatedItemsBuilder.config?.shimmerConfig;
final shimmerConfig = config ?? ShimmerConfig();

if (isLoading) {
return Shimmer.fromColors(
Expand Down
Loading

0 comments on commit cc59324

Please sign in to comment.