Files
MinByeongDon 02b86a2bd6 Translation [KO]: Comments in code (#3514)
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>
2024-05-07 08:51:59 +02:00

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 [];
});