Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ jobs:
contents: write
pull-requests: write

outputs:
release_created: ${{ steps.rp.outputs.release_created }}
created_tag: ${{ steps.rp.outputs.tag_name }}

steps:
- name: 📚 Code Checkout
uses: actions/checkout@v4
Expand All @@ -35,6 +31,10 @@ jobs:
config-file: release.config.json
include-component-in-tag: false

outputs:
release_created: ${{ steps.rp.outputs.release_created }}
created_tag: ${{ steps.rp.outputs.tag_name }}

dependencies:
name: 📦 Setup Dependencies For Deployment
needs: release
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ jobs:
name: 📦 Setup Dependencies
runs-on: ubuntu-latest

outputs:
fl-cache-key: ${{ steps.fl-setup.outputs.CACHE-KEY }}
fl-pub-cache-key: ${{ steps.fl-setup.outputs.PUB-CACHE-KEY }}

steps:
- name: 📚 Code Checkout
uses: actions/checkout@v4
Expand All @@ -47,6 +43,10 @@ jobs:
- name: 📦 Get dependencies
run: flutter pub get

outputs:
fl-cache-key: ${{ steps.fl-setup.outputs.CACHE-KEY }}
fl-pub-cache-key: ${{ steps.fl-setup.outputs.PUB-CACHE-KEY }}

ci-pr:
name: 🔍 PR Linting
needs: dependencies
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
paths:
- "{lib,test}/**"
- "pubspec.*"

workflow_dispatch:

Expand All @@ -15,9 +18,6 @@ jobs:
dependencies:
name: 📦 Setup Dependencies
runs-on: ubuntu-latest
outputs:
fl-cache-key: ${{ steps.fl-setup.outputs.CACHE-KEY }}
fl-pub-cache-key: ${{ steps.fl-setup.outputs.PUB-CACHE-KEY }}

steps:
- name: 📚 Code Checkout
Expand All @@ -38,6 +38,10 @@ jobs:
- name: 📦 Get dependencies
run: flutter pub get

outputs:
fl-cache-key: ${{ steps.fl-setup.outputs.CACHE-KEY }}
fl-pub-cache-key: ${{ steps.fl-setup.outputs.PUB-CACHE-KEY }}

lint:
name: 🔍 Code Linting
needs: dependencies
Expand All @@ -62,4 +66,6 @@ jobs:
flutter gen-l10n

- name: 🔍 Code Linting
run: flutter analyze lib
run: |
flutter analyze || dart analyze
dart run custom_lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ migrate_working_dir/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
.vscode/
# .vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down
7 changes: 4 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

dart run commitlint_cli --edit ${1} || {
echo "Commit lint failed. Trying run on fvm..."
fvm dart run commitlint_cli --edit ${1}
d() {
dart "$@" || fvm dart "$@"
}

d run commitlint_cli --edit ${1}
11 changes: 8 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

flutter analyze || {
echo "Flutter analyze failed. Trying run on fvm..."
fvm flutter analyze
fl() {
flutter "$@" || fvm flutter "$@"
}

d() {
dart "$@" || fvm dart "$@"
}

fl analyze && d run custom_lint
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.19.6",
"files.exclude": {
"{.dart_tool,.fvm,.idea}": true,
"**/*.{g,freezed,chopper}.dart": true
}
}
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

![Dart version][dart-badge] ![Flutter][fl-badge]

Projects from [dicoding.com flutter class][dicoding-fl] as a practice in
advanced navigation, use of media (audio, images, and video), and use of maps
such as Google Maps.
Simple media social app, project from [dicoding.com flutter class][dicoding-fl]
as a practice in advanced navigation, use of media (audio, images, and video),
and use of maps such as Google Maps.

## Table Of Contents

Expand Down Expand Up @@ -39,24 +39,24 @@ such as Google Maps.

### Dependencies

[build-runner]: https://pub.dev/packages/build_runner
[build_runner]: https://pub.dev/packages/build_runner
[injectable]: https://pub.dev/packages/injectable
[freezed]: https://pub.dev/packages/freezed
[chopper]: https://pub.dev/packages/chopper
[shared_preferences]: https://pub.dev/packages/shared_preferences
[go_router]: https://pub.dev/packages/go_router
[provider]: https://pub.dev/packages/provider
[riverpod]: https://riverpod.dev

Main packages that are used as foundation for this project.

- [injectable][injectable] -- Dependency injection framework.
- [freezed][freezed] -- Data model with short and simple syntax.
- [chopper][chopper] -- HTTP client service.
- [shared_preferences][shared_preferences] -- Local storage.
- [go_router][go_router] -- Web friendly routing.
- [provider][provider] -- State management.
- [injectable] -- Dependency injection framework.
- [freezed] -- Data model with short and simple syntax.
- [chopper] -- HTTP client service.
- [shared_preferences] -- Local storage.
- [go_router] -- Web friendly routing.
- [riverpod] -- State management.

Most of them need to generate its utilities with [build_runner][build-runner].
Most of them need to generate its utilities with [build_runner].

### Setup

Expand Down Expand Up @@ -106,6 +106,8 @@ Most of them need to generate its utilities with [build_runner][build-runner].

- [Dicoding Story API Docs][dicoding-story-api].
- [Google Maps API Docs][google-maps-docs].
- [Google Maps Proxy API Docs](https://nest-gmaps-api.fly.dev).
- [Source Code](https://github.com/KeidsID/nest-gmaps-api)

### Project Structures

Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ analyzer:
- "**/*.freezed.dart"
errors:
invalid_annotation_target: ignore
plugins:
- custom_lint

linter:
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ final class GoogleMapsApiClient extends ChopperClient {
level: Level.basic,
logger: chopperLogger,
),
if (_checkGeocodingType(type))
_GoogleMapsApiClientApiKeyInterceptor(apiKey),
//
_GoogleMapsApiClientApiKeyInterceptor(apiKey, type),
HeadersInterceptor({
if (!_checkGeocodingType(type)) "X-Goog-Api-Key": apiKey,
if (!kIsWeb) ...{
if (defaultTargetPlatform == TargetPlatform.android) ...{
"X-Android-Package": bundleId ?? "-",
Expand All @@ -44,9 +43,6 @@ final class GoogleMapsApiClient extends ChopperClient {
);
}

bool _checkGeocodingType(GoogleMapsApiClientType type) =>
type == GoogleMapsApiClientType.geocoding;

/// Determine which API to use on [GoogleMapsApiClient]
enum GoogleMapsApiClientType {
/// https://developers.google.com/maps/documentation/geocoding/overview
Expand All @@ -56,15 +52,26 @@ enum GoogleMapsApiClientType {
newPlaces,
}

class _GoogleMapsApiClientApiKeyInterceptor implements RequestInterceptor {
const _GoogleMapsApiClientApiKeyInterceptor(this.apiKey);
class _GoogleMapsApiClientApiKeyInterceptor implements Interceptor {
const _GoogleMapsApiClientApiKeyInterceptor(this.apiKey, this.clientType);

final String apiKey;
final GoogleMapsApiClientType clientType;

@override
FutureOr<Request> onRequest(Request request) {
return request.copyWith(
parameters: {"key": apiKey, ...request.parameters},
);
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) {
final req = chain.request;
final isGeocoding = clientType == GoogleMapsApiClientType.geocoding;

return chain.proceed(req.copyWith(
headers: {
if (!isGeocoding) "X-Goog-Api-Key": apiKey,
...req.headers,
},
parameters: {
if (isGeocoding) "key": apiKey,
...req.parameters,
},
));
}
}
12 changes: 4 additions & 8 deletions lib/infrastructures/libs/data/remote/modules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ abstract class RemoteDataModules {
baseUrl: Uri.tryParse(kApiBaseUrl),
converter: const JsonConverter(),
errorConverter: const JsonConverter(),
interceptors: kDebugMode
? [
HttpLoggingInterceptor(
level: Level.basic,
logger: chopperLogger,
),
]
: null,
interceptors: [
if (kDebugMode)
HttpLoggingInterceptor(level: Level.basic, logger: chopperLogger),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ abstract class AuthRemoteData extends ChopperService {
_$AuthRemoteData(client);

/// https://story-api.dicoding.dev/v1/#/?id=register
@Post(path: "/register")
@POST(path: "/register")
Future<Response<Map<String, dynamic>>> signUp({
@body required Map<String, dynamic> body,
});

/// https://story-api.dicoding.dev/v1/#/?id=login
@Post(path: "/login")
@POST(path: "/login")
Future<Response<Map<String, dynamic>>> signIn({
@body required Map<String, dynamic> body,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ abstract class GeocodingProxyRemoteData extends ChopperService {
));
}

@Get(path: "/geocode")
@GET(path: "/geocode")
Future<Response<Map<String, dynamic>>> geocoding(
@query String address, {
@query String? languageCode,
});

@Get(path: "/geocode/reverse")
@GET(path: "/geocode/reverse")
Future<Response<Map<String, dynamic>>> reverseGeocoding(
@query String lat,
@query String lng, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ abstract class GoogleMapsGeocodingRemoteData extends ChopperService {
));
}

@Get(path: "/json")
@GET(path: "/json")
Future<Response<Map<String, dynamic>>> geocoding(
@query String address, {
@Query("language") String? languageCode,
});

@Get(path: "/json")
@GET(path: "/json")
Future<Response<Map<String, dynamic>>> reverseGeocoding(
@query String latlng, {
@Query("language") String? languageCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ abstract class GoogleMapsNewPlacesRemoteData extends ChopperService {
}

/// https://developers.google.com/maps/documentation/places/web-service/place-details
@Get(path: "/places/{placeId}")
@GET(path: "/places/{placeId}")
Future<Response<Map<String, dynamic>>> placeDetails(
@path String placeId, {
@Header("X-Goog-FieldMask") required String fieldMask,
@query String? languageCode,
});

/// https://developers.google.com/maps/documentation/places/web-service/text-search
@Post(path: "/places:searchText")
@POST(path: "/places:searchText")
Future<Response<Map<String, dynamic>>> textSearch({
@Header("X-Goog-FieldMask") required String fieldMask,
@body required Map<String, dynamic> body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class StoriesRemoteData extends ChopperService {
});

/// https://story-api.dicoding.dev/v1/#/?id=detail-story
@Get(path: "/{id}")
@GET(path: "/{id}")
Future<Response<Map<String, dynamic>>> getStoryById({
@Header("Authorization") required String bearerToken,
@path required String id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ final class AuthRepositoryImpl implements AuthRepository {
final AuthRemoteData _remoteData;

@override
Future<User?> getAuth() async {
return _localData.getUser();
}
Future<User?> getAuth() async => _localData.getUser();

@override
Future<User> signIn({
Expand Down
4 changes: 0 additions & 4 deletions lib/interfaces/libs/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export "constants/route_paths/auth_route_paths_constant.dart";
export "constants/route_paths/app_route_paths_constant.dart";
export "constants/route_paths/profile_route_paths_constant.dart";
export "constants/route_paths/stories_route_paths_constant.dart";
export "constants/dark_google_maps_style_constants.dart";
export "constants/date_format_constant.dart";

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions lib/interfaces/libs/providers/modules.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export "modules/app_configs_provider.dart";
export "modules/auth_provider.dart";
export "modules/locale_provider.dart";
export "modules/picked_image_provider.dart";
export "modules/stories_provider.dart";
export "modules/story_detail_provider.dart";
export "modules/theme_mode_provider.dart";
Loading