diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2b17e34 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + package: + name: Analyze & test (package) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + - name: Install dependencies + run: flutter pub get + + - name: Verify generated code is up to date + run: | + dart run build_runner build + if ! git diff --quiet; then + echo "::error::Generated *.g.dart files are out of date. Run: dart run build_runner build" + git --no-pager diff --stat + exit 1 + fi + + - name: Analyze + run: dart analyze --fatal-infos --fatal-warnings + + - name: Test + run: flutter test + + example: + name: Analyze (example) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + + - name: Create example secret + working-directory: example + run: cp lib/secret.dart.example lib/secret.dart + + - name: Install dependencies + working-directory: example + run: flutter pub get + + - name: Analyze + working-directory: example + run: flutter analyze diff --git a/README.md b/README.md index d80a303..8682dc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -gir# strava_flutter +# strava_flutter + +[![CI](https://github.com/dreampowder/strava_flutter/actions/workflows/ci.yml/badge.svg)](https://github.com/dreampowder/strava_flutter/actions/workflows/ci.yml) Dart/flutter package to use Strava API v3 diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..9cc8b3f --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,17 @@ +include: package:flutter_lints/flutter.yaml + +analyzer: + exclude: + # Generated by json_serializable / build_runner. + - "**/*.g.dart" + # The example is a standalone package with its own analysis + CI job. + - "example/**" + errors: + # Keep the published API tidy without failing the build on doc nits. + todo: ignore + +linter: + rules: + # The package exposes snake_case enum values that mirror Strava's API + # (e.g. AuthenticationScope.read_all); don't fight the wire format. + constant_identifier_names: false diff --git a/lib/src/common/local_storage.dart b/lib/src/common/local_storage.dart index c0f185c..925dfaf 100644 --- a/lib/src/common/local_storage.dart +++ b/lib/src/common/local_storage.dart @@ -5,7 +5,7 @@ import 'package:strava_client/src/domain/model/model_authentication_response.dar import 'package:strava_client/src/domain/model/model_authentication_scopes.dart'; class LocalStorageManager { - static String _kTokenKey = "strava_token"; + static const String _kTokenKey = "strava_token"; // static String _kScopesKey = "strava_scopes"; static Future saveToken( diff --git a/lib/src/common/session_manager.dart b/lib/src/common/session_manager.dart index c48ea42..01e99c2 100644 --- a/lib/src/common/session_manager.dart +++ b/lib/src/common/session_manager.dart @@ -28,7 +28,7 @@ class SessionManager { if (_currentToken != null) { completer.complete(_currentToken); } else { - LocalStorageManager.getToken(applicationName: this.applicationName) + LocalStorageManager.getToken(applicationName: applicationName) .then((storedValue) { if (storedValue != null) { _currentToken = storedValue; diff --git a/lib/src/data/repository/client.dart b/lib/src/data/repository/client.dart index 213357a..ce5dfa2 100644 --- a/lib/src/data/repository/client.dart +++ b/lib/src/data/repository/client.dart @@ -12,7 +12,7 @@ class ApiClient { var dio = Dio(); if (isAuthenticated) { var token = await sl().getValidToken(); - var headers = Map(); + var headers = {}; if (token != null) { headers.putIfAbsent( "Authorization", () => "Bearer ${token.accessToken}"); diff --git a/lib/src/data/repository/repository_authentication_impl.dart b/lib/src/data/repository/repository_authentication_impl.dart index 7d0e159..2afe244 100644 --- a/lib/src/data/repository/repository_authentication_impl.dart +++ b/lib/src/data/repository/repository_authentication_impl.dart @@ -101,7 +101,7 @@ class RepositoryAuthenticationImpl extends RepositoryAuthentication { final Completer completer = Completer(); final params = '?client_id=${sl().clientId}&redirect_uri=$redirectUrl&response_type=code&approval_prompt=${forceShowingApproval ? "force" : "auto"}&scope=${AuthenticationScopeHelper.buildScopeString(scopes)}'; - final _appLinks = AppLinks(); + final appLinks = AppLinks(); var host = "https://www.strava.com/"; @@ -114,7 +114,7 @@ class RepositoryAuthenticationImpl extends RepositoryAuthentication { didLaunchNativeApp = true; host = "strava://"; _uriLinkStream?.cancel(); - _uriLinkStream = _appLinks.uriLinkStream.listen((uri) { + _uriLinkStream = appLinks.uriLinkStream.listen((uri) { final error = uri.queryParameters['error']; final code = uri.queryParameters['code']; if (error != null) { diff --git a/lib/src/domain/model/model_activity_type_enum.dart b/lib/src/domain/model/model_activity_type_enum.dart index 45acfe2..1d5170f 100644 --- a/lib/src/domain/model/model_activity_type_enum.dart +++ b/lib/src/domain/model/model_activity_type_enum.dart @@ -53,6 +53,6 @@ extension ActivityTypeEnumHelper on ActivityTypeEnum { } String stringValue() { - return this.toString().split(".").last; + return toString().split(".").last; } } diff --git a/pubspec.yaml b/pubspec.yaml index 6532ea0..62e4005 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,6 +22,7 @@ dev_dependencies: sdk: flutter build_runner: ^2.15.0 json_serializable: ^6.14.0 + flutter_lints: ^5.0.0 # test: 1.5.3 # To launch some tests in /test # For information on the generic Dart part of this file, see the