-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a REST API Client package (#521)
* feat: Add a REST API Client package * test: add rest_api_client_test * chore: update slang file * refactor: rest_api_client to pub_dev_api_client * chore: rename provider * chore: update dependencies and improve pub.dev package providers * refactor: rename package details provider and implement new provider for pub.dev package details
- Loading branch information
Showing
46 changed files
with
3,267 additions
and
176 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
packages/flutter_app/lib/features/post/view/post_page.dart
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
...ges/flutter_app/lib/features/pub_dev_packages/query/pub_dev_package_details_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:pub_dev_api_client/pub_dev_api_client.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../../../package_adaptor/pub_dev_api_client_provider.dart'; | ||
|
||
part 'pub_dev_package_details_provider.g.dart'; | ||
|
||
/// Provider for pub.dev package details by package name. | ||
@riverpod | ||
Future<GetPackageDetailsResponseBody> pubDevPackageDetails( | ||
Ref ref, { | ||
required String packageName, | ||
}) async { | ||
final client = ref.watch(pubDevApiClientProvider); | ||
final response = await client.getPackageDetails(packageName: packageName); | ||
return response; | ||
} |
184 changes: 184 additions & 0 deletions
184
...s/flutter_app/lib/features/pub_dev_packages/query/pub_dev_package_details_provider.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...flutter_app/lib/features/pub_dev_packages/query/pub_dev_packages_page_state_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:pub_dev_api_client/pub_dev_api_client.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
import '../../../package_adaptor/pub_dev_api_client_provider.dart'; | ||
|
||
part 'pub_dev_packages_page_state_provider.g.dart'; | ||
|
||
/// Provider for the search word of pub.dev packages. | ||
@Riverpod(keepAlive: true) | ||
class PubDevPackageSearchWordState extends _$PubDevPackageSearchWordState { | ||
@override | ||
String build() => ''; | ||
|
||
/// Update the search word. | ||
// ignore: use_setters_to_change_properties | ||
void update(String word) { | ||
state = word; | ||
} | ||
|
||
/// Clear the search word. | ||
void clear() { | ||
state = ''; | ||
} | ||
} | ||
|
||
@Riverpod(keepAlive: true) | ||
class PubDevPackagesPageState extends _$PubDevPackagesPageState { | ||
@override | ||
Future<GetSearchedPackagesResponseBody> build() async { | ||
final searchWord = ref.watch(pubDevPackageSearchWordStateProvider); | ||
final client = ref.watch(pubDevApiClientProvider); | ||
final response = await client.getSearchedPackages(searchWord: searchWord); | ||
return response; | ||
} | ||
|
||
Future<void> loadNext(int nextPage) async { | ||
state = const AsyncLoading<GetSearchedPackagesResponseBody>() | ||
.copyWithPrevious(state); | ||
|
||
final searchWord = ref.read(pubDevPackageSearchWordStateProvider); | ||
final client = ref.read(pubDevApiClientProvider); | ||
final response = await client.getSearchedPackages( | ||
searchWord: searchWord, | ||
page: nextPage, | ||
); | ||
final currentPackages = state.requireValue.packages; | ||
final newPackages = [...currentPackages, ...response.packages]; | ||
|
||
state = AsyncData( | ||
GetSearchedPackagesResponseBody( | ||
packages: newPackages, | ||
nextPageUrl: response.nextPageUrl, | ||
), | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...utter_app/lib/features/pub_dev_packages/query/pub_dev_packages_page_state_provider.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
packages/flutter_app/lib/features/pub_dev_packages/query/query.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'pub_dev_package_details_provider.dart'; | ||
export 'pub_dev_packages_page_state_provider.dart'; |
Oops, something went wrong.