mirror of
https://github.com/rrousselGit/riverpod.git
synced 2025-08-16 11:20:55 +08:00

This PR adds "{@template}" to the source code of the documentation, and provides the latest Korean translation (include comments in code) of the following pages. - introduction: 2 pages - essentials: 11 pages - from_provider: 2 pages - advanced: 1 page Thanks --------- Co-authored-by: Remi Rousselet <darky12s@gmail.com>
33 lines
1.0 KiB
Dart
33 lines
1.0 KiB
Dart
// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class Package {
|
|
static Package fromJson(dynamic json) {
|
|
throw UnimplementedError();
|
|
}
|
|
}
|
|
|
|
/* SNIPPET START */
|
|
|
|
// {@template fetchPackages}
|
|
// Fetches the list of packages from pub.dev
|
|
// {@endtemplate}
|
|
final fetchPackagesProvider = FutureProvider.autoDispose.family<List<Package>, ({int page, String? search})>((ref, params) async {
|
|
final page = params.page;
|
|
final search = params.search ?? '';
|
|
final dio = Dio();
|
|
// {@template fetchApi}
|
|
// Fetch an API. Here we're using package:dio, but we could use anything else.
|
|
// {@endtemplate}
|
|
final response = await dio.get<List<Object?>>(
|
|
'https://pub.dartlang.org/api/search?page=$page&q=${Uri.encodeQueryComponent(search)}',
|
|
);
|
|
|
|
// {@template decodeJson}
|
|
// Decode the JSON response into a Dart class.
|
|
// {@endtemplate}
|
|
return response.data?.map(Package.fromJson).toList() ?? const [];
|
|
});
|