content: // ignore_for_file: use_key_in_widget_constructors, unreachable_from_main
  
  /* SNIPPET START */
  import 'dart:convert';
  
  import 'package:flutter/material.dart';
  import 'package:flutter_riverpod/flutter_riverpod.dart';
  import 'package:http/http.dart' as http;
  
  void main() => runApp(ProviderScope(child: MyApp()));
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(home: ActivityView());
    }
  }
  
  class ActivityView extends ConsumerWidget {
    @override
    Widget build(BuildContext context, WidgetRef ref) {
      final activity = ref.watch(activityProvider);
  
      return Scaffold(
        appBar: AppBar(title: const Text('Pull to refresh')),
        body: RefreshIndicator(
          onRefresh: () => ref.refresh(activityProvider.future),
          child: ListView(
            children: [
              switch (activity) {
                AsyncValue<Activity>(:final value?) => Text(value.activity),
                AsyncValue(:final error?) => Text('Error: $error'),
                _ => const CircularProgressIndicator(),
              },
            ],
          ),
        ),
      );
    }
  }
  
  final activityProvider = FutureProvider.autoDispose<Activity>((ref) async {
    final response = await http.get(
      Uri.https('www.boredapi.com', '/api/activity'),
    );
  
    final json = jsonDecode(response.body) as Map;
    return Activity.fromJson(json);
  });
  
  class Activity {
    Activity({
      required this.activity,
      required this.type,
      required this.participants,
      required this.price,
    });
  
    factory Activity.fromJson(Map<Object?, Object?> json) {
      return Activity(
        activity: json['activity']! as String,
        type: json['type']! as String,
        participants: json['participants']! as int,
        price: json['price']! as double,
      );
    }
  
    final String activity;
    final String type;
    final int participants;
    final double price;
  }
  