### Consume Async Data in Flutter UI with Riverpod Source: https://pub.dev/documentation/flutter_riverpod/3.0.1/index Demonstrates how to consume asynchronous data fetched by Riverpod within a Flutter UI component using `ConsumerWidget`. It shows how to watch the data provider and gracefully handle loading, error, and success states using a switch-case statement on `AsyncData`, `AsyncError`, and the default loading state. ```dart class Home extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final boredSuggestion = ref.watch(boredSuggestionProvider); // Perform a switch-case on the result to handle loading/error states return switch (boredSuggestion) { AsyncData(:final value) => Text('data: $value'), AsyncError(:final error) => Text('error: $error'), _ => const Text('loading'), }; } } ``` -------------------------------- ### Define Async Data Fetching with Riverpod Source: https://pub.dev/documentation/flutter_riverpod/3.0.1/index Defines an asynchronous function to fetch data from an external API using Riverpod's `@riverpod` annotation. It handles HTTP requests and JSON decoding, returning a Future of a String. This pattern separates data fetching logic from the UI. ```dart @riverpod Future boredSuggestion(Ref ref) async { final response = await http.get( Uri.https('boredapi.com', '/api/activity'), ); final json = jsonDecode(response.body); return json['activity']! as String; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.