content: import 'dart:convert';
  
  import 'package:flutter/material.dart';
  import 'package:flutter_riverpod/flutter_riverpod.dart';
  import 'package:freezed_annotation/freezed_annotation.dart';
  import 'package:http/http.dart' as http;
  import 'package:riverpod_annotation/riverpod_annotation.dart';
  
  part 'codegen.freezed.dart';
  part 'codegen.g.dart';
  
  /* SNIPPET START */
  @freezed
  sealed class Activity with _$Activity {
    factory Activity({
      required String activity,
      required String type,
      required int participants,
      required double price,
    }) = _Activity;
  
    factory Activity.fromJson(Map<String, dynamic> json) =>
        _$ActivityFromJson(json);
  }
  
  @riverpod
  Future<Activity> activity(Ref ref) async {
    final response = await http.get(
      Uri.https('www.boredapi.com', '/api/activity'),
    );
  
    final json = jsonDecode(response.body) as Map;
    return Activity.fromJson(Map.from(json));
  }
  
  class DetailPageView extends ConsumerWidget {
    const DetailPageView({super.key});
  
    @override
    Widget build(BuildContext context, WidgetRef ref) {
      final activity = ref.watch(activityProvider);
  
      return Scaffold(
        appBar: AppBar(
          title: const Text('Detail page'),
        ),
        body: RefreshIndicator(
          onRefresh: () => ref.refresh(activityProvider.future),
          child: ListView(
            children: [
              switch (activity) {
                AsyncValue(:final value?) => Text(value.activity),
                AsyncValue(:final error?) => Text('Error: $error'),
                _ => const Center(child: CircularProgressIndicator()),
              },
            ],
          ),
        ),
      );
    }
  }
  