From aa0b9d141d10904a614e575cd8b7f09cee75e02a Mon Sep 17 00:00:00 2001
From: Adrien Bonnin <adbonnin@ippon.fr>
Date: Mon, 19 Sep 2022 11:10:10 +0200
Subject: [PATCH] =?UTF-8?q?:sparkles:=20Le=20provider=20est=20d=C3=A9plac?=
 =?UTF-8?q?=C3=A9=20dans=20le=20TodoListHeader?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../08_future_provider_example.dart           | 22 ++++++++----------
 lib/presentation/09_async_value_example.dart  | 23 ++++++++-----------
 2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/lib/presentation/08_future_provider_example.dart b/lib/presentation/08_future_provider_example.dart
index f4766ed..bb948c6 100644
--- a/lib/presentation/08_future_provider_example.dart
+++ b/lib/presentation/08_future_provider_example.dart
@@ -25,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> {
   @override
   Widget build(BuildContext context) {
     final todos = ref.watch(todosProvider.select((tds) => tds.whereTodos(_isUncheckedFilter)));
-    final asyncTodosCount = ref.watch(todosCountProvider);
 
     return Column(
       children: [
@@ -34,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> {
           onFilterChanged: _onFilterChanged,
         ),
         const Divider(height: 1),
-        Padding(
-          padding: const EdgeInsets.only(top: 16, bottom: 8),
-          child: TodoListHeader(asyncTodosCount),
+        const Padding(
+          padding: EdgeInsets.only(top: 16, bottom: 8),
+          child: TodoListHeader(),
         ),
         Expanded(
           child: ListView.builder(
@@ -89,20 +88,17 @@ class TodoListFilter extends StatelessWidget {
   }
 }
 
-class TodoListHeader extends StatelessWidget {
-  const TodoListHeader(
-    this.todosCount, {
-    Key? key,
-  }) : super(key: key);
-
-  final AsyncValue<int> todosCount;
+class TodoListHeader extends ConsumerWidget {
+  const TodoListHeader({Key? key}) : super(key: key);
 
   @override
-  Widget build(BuildContext context) {
+  Widget build(BuildContext context, WidgetRef ref) {
+    final asyncTodosCount = ref.watch(todosCountProvider);
+
     return Container(
       height: 16,
       alignment: Alignment.center,
-      child: todosCount.when(
+      child: asyncTodosCount.when(
         data: (count) => Text(
           "$count todos",
           style: Theme.of(context).textTheme.subtitle2,
diff --git a/lib/presentation/09_async_value_example.dart b/lib/presentation/09_async_value_example.dart
index 88600b7..9c47b9b 100644
--- a/lib/presentation/09_async_value_example.dart
+++ b/lib/presentation/09_async_value_example.dart
@@ -1,4 +1,3 @@
-import 'package:article_flutter_riverpod/presentation/01_introduction_example.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_riverpod/flutter_riverpod.dart';
 
@@ -26,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> {
   @override
   Widget build(BuildContext context) {
     final asyncTodos = ref.watch(todosProvider.selectTodos(_isUncheckedFilter));
-    final asyncTodosCount = ref.watch(todosCountProvider);
 
     return Column(
       children: [
@@ -35,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> {
           onFilterChanged: _onFilterChanged,
         ),
         const Divider(height: 1),
-        Padding(
-          padding: const EdgeInsets.only(top: 16, bottom: 8),
-          child: TodoListHeader(asyncTodosCount),
+        const Padding(
+          padding: EdgeInsets.only(top: 16, bottom: 8),
+          child: TodoListHeader(),
         ),
         Expanded(
           child: asyncTodos.when(
@@ -98,20 +96,17 @@ class TodoListFilter extends StatelessWidget {
   }
 }
 
-class TodoListHeader extends StatelessWidget {
-  const TodoListHeader(
-    this.todosCount, {
-    Key? key,
-  }) : super(key: key);
-
-  final AsyncValue<int> todosCount;
+class TodoListHeader extends ConsumerWidget {
+  const TodoListHeader({Key? key}) : super(key: key);
 
   @override
-  Widget build(BuildContext context) {
+  Widget build(BuildContext context, WidgetRef ref) {
+    final asyncTodosCount = ref.watch(todosCountProvider);
+
     return Container(
       height: 16,
       alignment: Alignment.center,
-      child: todosCount.when(
+      child: asyncTodosCount.when(
         data: (count) => Text(
           "$count todos",
           style: Theme.of(context).textTheme.subtitle2,
-- 
GitLab