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

40 lines
1.2 KiB
Dart

// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals
import 'dart:convert';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart' as http;
import '../../first_request/raw/activity.dart';
/* SNIPPET START */
// {@template parameters}
// We define a record representing the parameters we want to pass to the provider.
// Making a typedef is optional but can make the code more readable.
// {@endtemplate}
typedef ActivityParameters = ({String type, int maxPrice});
final activityProvider = FutureProvider.autoDispose
// {@template defined}
// We now use the newly defined record as the argument type.
// {@endtemplate}
.family<Activity, ActivityParameters>((ref, arguments) async {
final response = await http.get(
Uri(
scheme: 'https',
host: 'boredapi.com',
path: '/api/activity',
queryParameters: {
// {@template query}
// Lastly, we can use the arguments to update our query parameters.
// {@endtemplate}
'type': arguments.type,
'price': arguments.maxPrice,
},
),
);
final json = jsonDecode(response.body) as Map<String, dynamic>;
return Activity.fromJson(json);
});