content: // ignore_for_file: use_key_in_widget_constructors, avoid_print
  
  import 'package:flutter/material.dart';
  import 'package:flutter_riverpod/flutter_riverpod.dart';
  import 'package:flutter_riverpod/legacy.dart';
  
  /* SNIPPET START */
  
  // Ein Zähler Beispiel implementiert mit Riverpod und Logger
  
  class Logger extends ProviderObserver {
    @override
    void didUpdateProvider(
      ProviderBase<Object?> provider,
      Object? previousValue,
      Object? newValue,
      ProviderContainer container,
    ) {
      print('''
  {
    "provider": "${provider.name ?? provider.runtimeType}",
    "newValue": "$newValue"
  }''');
    }
  }
  
  void main() {
    runApp(
      // Das Hinzufügen des ProviderScope aktiviert Riverpod für das gesamte Projekt
      // Hinzufügen des Loggers zu der Liste der Beobachter
      ProviderScope(observers: [Logger()], child: const MyApp()),
    );
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({super.key});
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(home: Home());
    }
  }
  
  final counterProvider = StateProvider((ref) => 0, name: 'counter');
  
  class Home extends ConsumerWidget {
    @override
    Widget build(BuildContext context, WidgetRef ref) {
      final count = ref.watch(counterProvider);
  
      return Scaffold(
        appBar: AppBar(title: const Text('Counter example')),
        body: Center(
          child: Text('$count'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => ref.read(counterProvider.notifier).state++,
          child: const Icon(Icons.add),
        ),
      );
    }
  }
  