Skip to content

Commit

Permalink
Merge pull request #18 from K9i-0/feature/yumemi_lints
Browse files Browse the repository at this point in the history
change lint package
  • Loading branch information
K9i-0 authored Jun 2, 2024
2 parents 5e2d91c + a770d59 commit 1316295
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 69 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: check-pr

on:
pull_request:

jobs:
check_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# https://github.com/dart-lang/setup-dart/blob/v1/.github/workflows/publish.yml
- name: Fetch flutter config
uses: kuhnroyal/flutter-fvm-config-action@v2
id: fvm-config-action

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
cache: true

# https://github.com/actions/cache
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
${{ env.PUB_CACHE }}
${{ github.workspace }}/.packages
${{ github.workspace }}/.flutter-plugins
${{ github.workspace }}/.flutter-plugin-dependencies
${{ github.workspace }}/.dart_tool/package_config.json
key: build-pubspec-${{ hashFiles(format('{0}{1}', github.workspace, '/pubspec.lock')) }}
restore-keys: |
build-pubspec-
- name: Install dependencies
run: dart pub get

# https://github.com/invertase/github-action-dart-analyzer
- name: Report analyze
uses: invertase/github-action-dart-analyzer@v3
with:
fatal-infos: true
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ jobs:
- name: Fetch flutter config
uses: kuhnroyal/flutter-fvm-config-action@v2
id: fvm-config-action

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }}
channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }}
cache: true

# https://github.com/actions/cache
- name: Cache dependencies
uses: actions/cache@v4
Expand All @@ -41,7 +43,9 @@ jobs:
key: build-pubspec-${{ hashFiles(format('{0}{1}', github.workspace, '/pubspec.lock')) }}
restore-keys: |
build-pubspec-
- name: Install dependencies
run: dart pub get

- name: Publish
run: dart pub publish --force
10 changes: 7 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include: package:flutter_lints/flutter.yaml
# https://pub.dev/packages/yumemi_lints
include: package:yumemi_lints/flutter/3.0/recommended.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

linter:
rules:
lines_longer_than_80_chars: false
diagnostic_describe_all_properties: false
10 changes: 8 additions & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
include: package:flutter_lints/flutter.yaml
# https://pub.dev/packages/yumemi_lints
include: package:yumemi_lints/flutter/3.0/recommended.yaml

linter:
rules:
lines_longer_than_80_chars: false
diagnostic_describe_all_properties: false

analyzer:
plugins:
- custom_lint
- custom_lint
2 changes: 1 addition & 1 deletion example/lib/main2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SampleNotifier extends _$SampleNotifier
required String? cursor,
}) async {
// Simulate a delay of 2 seconds to demonstrate the loading view.
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
final repository = ref.read(sampleRepositoryProvider);
final (items, nextCursor) = await repository.getByCursor(cursor);
final hasMore = nextCursor != null && nextCursor.isNotEmpty;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/repository/sample_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SampleRepository {
Future<(List<SampleItem> items, String? nextCursor)> getByCursor(
String? cursor,
) async {
await Future.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));

final items = _db
.sublist(
Expand All @@ -38,7 +38,7 @@ class SampleRepository {
String id,
String? cursor,
) async {
await Future.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));

final items = _db
.sublist(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/ui/first_page_error_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class FirstPageErrorNotifier extends _$FirstPageErrorNotifier
with CursorPagingNotifierMixin<SampleItem> {
@override
Future<CursorPagingData<SampleItem>> build() async {
await Future.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
throw Exception('Error fetching data');
// ignore: dead_code
return fetch(cursor: null);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/ui/second_page_error_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SecondPageErrorNotifier extends _$SecondPageErrorNotifier
required String? cursor,
}) async {
if (cursor != null) {
await Future.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
throw Exception('Error fetching data');
}

Expand Down
28 changes: 10 additions & 18 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ packages:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
version: "6.1.4"
fixnum:
dependency: transitive
description:
Expand All @@ -246,14 +246,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_riverpod:
dependency: "direct main"
description:
Expand Down Expand Up @@ -395,14 +387,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
loading_animation_widget:
dependency: "direct main"
description:
Expand Down Expand Up @@ -743,6 +727,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.2"
yumemi_lints:
dependency: "direct dev"
description:
name: yumemi_lints
sha256: "32793569af25ca58377c39cbde762ce14e1fe81859f0e3dde213d4e8e7715da2"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.1.0-0"
16 changes: 8 additions & 8 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
name: example
description: "A new Flutter project."
publish_to: 'none'
publish_to: "none"
version: 0.1.0

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.0.0'
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_riverpod: ^2.5.1
freezed_annotation: ^2.4.1
loading_animation_widget: ^1.2.1
random_name_generator: ^1.3.0
record_iterable_utils: ^0.1.0
riverpod_annotation: ^2.3.5
random_name_generator: ^1.3.0
riverpod_paging_utils:
path: ../
loading_animation_widget: ^1.2.1

dev_dependencies:
build_runner: ^2.4.9
custom_lint: ^0.6.4
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter
freezed: ^2.5.2
riverpod_generator: ^2.4.0
riverpod_lint: ^2.3.10
grinder: ^0.9.5
k9i_cli: ^1.1.1
riverpod_generator: ^2.4.0
riverpod_lint: ^2.3.10
yumemi_lints: ^2.1.0

flutter:
uses-material-design: true
66 changes: 38 additions & 28 deletions lib/src/paging_helper_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class PagingHelperView<D extends PagingData<I>, I> extends ConsumerWidget {
final Refreshable<PagingNotifierMixin<D, I>> notifierRefreshable;

/// Specifies a function that returns a widget to display when data is available.
/// [endItem] is a widget to detect when the last displayed item is visible.
/// If [endItem] is non-null, it is displayed at the end of the list.
/// endItemView is a widget to detect when the last displayed item is visible.
/// If endItemView is non-null, it is displayed at the end of the list.
final Widget Function(D data, Widget? endItemView) contentBuilder;

final bool showSecondPageError;
Expand Down Expand Up @@ -72,28 +72,33 @@ class PagingHelperView<D extends PagingData<I>, I> extends ConsumerWidget {
);

return ref.watch(provider).whenIgnorableError(
data: (data,
{required hasError, required isLoading, required error}) {
data: (
data, {
required hasError,
required isLoading,
required error,
}) {
return RefreshIndicator(
onRefresh: () => ref.refresh(futureRefreshable),
child: contentBuilder(
data,
switch ((data.hasMore, hasError, isLoading)) {
// Display a widget to detect when the last element is reached
// if there are more pages and no errors
(true, false, _) => _EndVisibilityDetectorLoadingItemView(
onScrollEnd: () =>
ref.read(notifierRefreshable).loadNext(),
),
(true, true, false) when showSecondPageError =>
_EndErrorItemView(
error: error,
onRetryButtonPressed: () =>
ref.read(notifierRefreshable).loadNext(),
),
(true, true, true) => const _EndLoadingItemView(),
_ => null,
}),
data,
switch ((data.hasMore, hasError, isLoading)) {
// Display a widget to detect when the last element is reached
// if there are more pages and no errors
(true, false, _) => _EndVisibilityDetectorLoadingItemView(
onScrollEnd: () =>
ref.read(notifierRefreshable).loadNext(),
),
(true, true, false) when showSecondPageError =>
_EndErrorItemView(
error: error,
onRetryButtonPressed: () =>
ref.read(notifierRefreshable).loadNext(),
),
(true, true, true) => const _EndLoadingItemView(),
_ => null,
},
),
);
},
// Loading state for the first page
Expand Down Expand Up @@ -199,11 +204,12 @@ extension _AsyncValueX<T> on AsyncValue<T> {
/// even if subsequent fetch attempts result in errors,
/// ideal for maintaining a seamless user experience.
R whenIgnorableError<R>({
required R Function(T data,
{required bool hasError,
required bool isLoading,
required Object? error})
data,
required R Function(
T data, {
required bool hasError,
required bool isLoading,
required Object? error,
}) data,
required R Function(Object error, StackTrace stackTrace) error,
required R Function() loading,
bool skipLoadingOnReload = false,
Expand All @@ -213,8 +219,12 @@ extension _AsyncValueX<T> on AsyncValue<T> {
}) {
if (skipErrorOnHasValue) {
if (hasValue && hasError) {
return data(requireValue,
hasError: true, isLoading: isLoading, error: this.error);
return data(
requireValue,
hasError: true,
isLoading: isLoading,
error: this.error,
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/src/paging_helper_view_theme.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:riverpod_paging_utils/riverpod_paging_utils.dart';

typedef ErrorWidgetBuilder = Widget Function(
BuildContext context,
Expand Down Expand Up @@ -50,7 +51,9 @@ class PagingHelperViewTheme extends ThemeExtension<PagingHelperViewTheme> {

@override
ThemeExtension<PagingHelperViewTheme> lerp(
covariant ThemeExtension<PagingHelperViewTheme>? other, double t) {
covariant ThemeExtension<PagingHelperViewTheme>? other,
double t,
) {
return this;
}
}
10 changes: 6 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: riverpod_paging_utils
description: A Flutter package that provides utilities for implementing pagination with Riverpod. It includes a generic PagingHelperView widget and mixins for page-based, offset-based, and cursor-based pagination.
description: A Flutter package that provides utilities for implementing
pagination with Riverpod. It includes a generic PagingHelperView widget and
mixins for page-based, offset-based, and cursor-based pagination.
version: 0.4.3
homepage: https://github.com/K9i-0/riverpod_paging_utils
environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.0.0'
sdk: ">=3.0.0 <4.0.0"
flutter: ">=3.0.0"
dependencies:
flutter:
sdk: flutter
Expand All @@ -14,12 +16,12 @@ dependencies:

dev_dependencies:
build_runner: ^2.4.9
flutter_lints: ^4.0.0
flutter_test:
sdk: flutter
freezed: ^2.5.2
grinder: ^0.9.5
k9i_cli: ^1.1.1
yumemi_lints: ^2.1.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
Expand Down

0 comments on commit 1316295

Please sign in to comment.