Skip to content

Commit

Permalink
Dart 3 upgrade (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirland authored Oct 5, 2023
1 parent 6a2f54f commit c30a12c
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 241 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/dart-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest

runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
Expand All @@ -27,18 +26,6 @@ jobs:
- name: Flutter Analyze project source
run: flutter analyze .

- name: Analyze project source - Code Metrics
run: |
result=$(dart run dart_code_metrics:metrics analyze lib --fatal-style --fatal-performance --fatal-warnings)
echo "$result"
[[ $result == '✔ no issues found!' ]] || { echo -e "${RED}Linter error" ; exit 1; }
- name: Analyze project source - Check Unused Code
run: dart run dart_code_metrics:metrics check-unused-code lib --fatal-unused

- name: Analyze project source - Check Unused Files
run: dart run dart_code_metrics:metrics check-unused-files lib --fatal-unused

- name: Run tests
run: |
dart pub global activate coverage 1.5.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
name: Dart Metrics
name: Dart Pana

on: [pull_request]

jobs:
check:
name: dart-code-metrics-action
runs-on: ubuntu-latest
name: pana-action
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1

- name: dart-code-metrics
uses: dart-code-checker/dart-code-metrics-action@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Run pana
run: |
dart pub global activate pana
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.1.0
* Dart 3 upgrade

## 1.0.1
* Document improvements ([#34](https://github.com/xmartlabs/stock/pull/34))
* Make SourceOfTruth non-required in the Stock constrictor ([#33](https://github.com/xmartlabs/stock/pull/33))
Expand Down
5 changes: 2 additions & 3 deletions lib/src/extensions/stock_response_internal_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import 'package:stock/src/stock_response_extensions.dart';
extension StockResponseExtensions<T> on StockResponse<T> {
StockResponse<R> swapType<R>() => when(
onData: (origin, data) => StockResponse.data(origin, data as R),
onLoading: (origin) => StockResponse.loading(origin),
onError: (origin, error, stacktrace) =>
StockResponse.error(origin, error, stacktrace),
onLoading: StockResponse.loading,
onError: StockResponse.error,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/implementations/factory_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ class FutureFetcher<Key, Output> extends FactoryFetcher<Key, Output> {
}

class StreamFetcher<Key, Output> extends FactoryFetcher<Key, Output> {
StreamFetcher(Stream<Output> Function(Key key) factory) : super(factory);
StreamFetcher(super.factory);
}
8 changes: 4 additions & 4 deletions lib/src/stock_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class StockResponse<Output> {
@immutable
class StockResponseLoading<T> extends StockResponse<T> {
/// StockResponseLoading constructor
const StockResponseLoading(ResponseOrigin origin) : super._(origin);
const StockResponseLoading(super.origin) : super._();

@override
String toString() => 'StockResponse<$T>.loading(origin: $origin)';
Expand All @@ -58,7 +58,7 @@ class StockResponseLoading<T> extends StockResponse<T> {
@immutable
class StockResponseData<T> extends StockResponse<T> {
/// StockResponseData constructor
const StockResponseData(ResponseOrigin origin, this.value) : super._(origin);
const StockResponseData(super.origin, this.value) : super._();

/// The data value
final T value;
Expand All @@ -82,8 +82,8 @@ class StockResponseData<T> extends StockResponse<T> {
@immutable
class StockResponseError<T> extends StockResponse<T> {
/// StockResponseError constructor
const StockResponseError(ResponseOrigin origin, this.error, [this.stackTrace])
: super._(origin);
const StockResponseError(super.origin, this.error, [this.stackTrace])
: super._();

/// The error
final Object error;
Expand Down
13 changes: 5 additions & 8 deletions lib/src/stock_response_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ extension StockResponseExtensions<T> on StockResponse<T> {
/// [onLoading] or [orElse] as fallback if the response is loading, and
/// [onError] or [orElse] as fallback if the response is an error.
E maybeMap<E>({
required E Function() orElse,
E Function(StockResponseLoading<T> value)? onLoading,
E Function(StockResponseData<T> value)? onData,
E Function(StockResponseError<T> value)? onError,
required E Function() orElse,
}) =>
map(
onLoading: onLoading ?? (_) => orElse(),
Expand Down Expand Up @@ -113,8 +113,7 @@ extension StockResponseExtensions<T> on StockResponse<T> {
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)
onError,
) onError,
}) =>
map(
onLoading: (value) => onLoading(value.origin),
Expand All @@ -137,8 +136,7 @@ extension StockResponseExtensions<T> on StockResponse<T> {
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)?
onError,
)? onError,
}) =>
maybeWhen(
onLoading: onLoading,
Expand All @@ -151,15 +149,14 @@ extension StockResponseExtensions<T> on StockResponse<T> {
/// [onLoading] or [orElse] as fallback if the response is loading, and
/// [onError] or [orElse] as fallback if the response is an error.
E maybeWhen<E>({
required E Function(ResponseOrigin origin) orElse,
E Function(ResponseOrigin origin)? onLoading,
E Function(ResponseOrigin origin, T data)? onData,
E Function(
ResponseOrigin origin,
Object error,
StackTrace? stackTrace,
)?
onError,
required E Function(ResponseOrigin origin) orElse,
)? onError,
}) =>
when(
onLoading: onLoading ?? (origin) => orElse(origin),
Expand Down
Loading

0 comments on commit c30a12c

Please sign in to comment.