Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mataku/sunrisescrob
https://github.com/mataku/sunrisescrob
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mataku/sunrisescrob
- Owner: mataku
- License: apache-2.0
- Created: 2024-08-01T10:35:41.000Z (5 months ago)
- Default Branch: develop
- Last Pushed: 2024-12-19T18:26:47.000Z (17 days ago)
- Last Synced: 2024-12-24T00:38:49.740Z (12 days ago)
- Language: Dart
- Size: 10.1 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Last.fm client
Flutter Architecture Sample like Model-View-ViewModel using Last.fm API.
## Features
- Recent scrobbles
- Top tracks
- Top artists
- Account info
- Switch theme## Setup
```shell
# fvm flutter
flutter pub get --no-example && dart run build_runner build --delete-conflicting-outputs
```## Architecture
TODO
- View (Flutter Widget)
- Presentation layer: ChangeNotifier
- Data layer: Repository (or use UseCase if there are complex business logic, various data type, or something) and class with freezed and json_serializable
- Domain layer: Dart Class with freezed: [./lib/model/](./lib/model)### HTTP request
uses Endpoint data class.
```dart
abstract class Endpoint {
final String path;
final Map params;
final RequestType requestType;Endpoint({
required this.path,
required this.params,
required this.requestType,
});T parseFromJson(Response response);
}
``````dart
// api client
abstract class LastFmApiService {
Future request(Endpoint endpoint);
}class _LastFmApiServiceImpl extends LastFmApiService {
final Dio _dio;_LastFmApiServiceImpl({required Dio dio}) : _dio = dio;
@override
Future request(Endpoint endpoint) async {
final result = switch (endpoint.requestType) {
RequestType.get => _get(endpoint),
RequestType.post => _post(endpoint),
};return result;
}Future _get(Endpoint endpoint) async {
final response =
await _dio.get(endpoint.path, queryParameters: endpoint.params);
return endpoint.parseFromJson(response);
}Future _post(Endpoint endpoint) async {
final response =
await _dio.post(endpoint.path, queryParameters: endpoint.params);
return endpoint.parseFromJson(response);
}
}```
Define the type returned for each endpoint. In the API Client, use the `request` method with defined type in endpoint: `Future request(Endpoint endpoint)`
```dart
// GET
class RecentTracksEndpoint extends Endpoint {
RecentTracksEndpoint(
{super.path = '/2.0/?method=user.getrecenttracks',
required super.params,
super.requestType = RequestType.get});@override
RecentTracksApiResponse parseFromJson(Response response) {
return RecentTracksApiResponse.fromJson(response.data);
}
}// usage
final recentEndpoint = RecentTrackEndpoint(params: {'username': 'mataku'});
// ref.read(lastFmApiServiceProvider)
final response = await lastFmApiService.request(recentEndpoint); // RecentTracksApiResponse type
```# Licenses
See [LICENSE](./LICENSE).
This app uses [Noto Sans Japanese](https://fonts.google.com/noto/specimen/Noto+Sans+JP) in golden tests.