Skip to content
Snippets Groups Projects
Commit 34402998 authored by Adrien BONNIN's avatar Adrien BONNIN
Browse files

:sparkles: Le provider est déplacé dans le TodoListHeader

parent 63b01bc9
No related branches found
No related tags found
No related merge requests found
Pipeline #79145 passed
...@@ -25,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> { ...@@ -25,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final todos = ref.watch(todosProvider.select((tds) => tds.whereTodos(_isUncheckedFilter))); final todos = ref.watch(todosProvider.select((tds) => tds.whereTodos(_isUncheckedFilter)));
final asyncTodosCount = ref.watch(todosCountProvider);
return Column( return Column(
children: [ children: [
...@@ -34,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> { ...@@ -34,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> {
onFilterChanged: _onFilterChanged, onFilterChanged: _onFilterChanged,
), ),
const Divider(height: 1), const Divider(height: 1),
Padding( const Padding(
padding: const EdgeInsets.only(top: 16, bottom: 8), padding: EdgeInsets.only(top: 16, bottom: 8),
child: TodoListHeader(asyncTodosCount), child: TodoListHeader(),
), ),
Expanded( Expanded(
child: ListView.builder( child: ListView.builder(
...@@ -89,20 +88,17 @@ class TodoListFilter extends StatelessWidget { ...@@ -89,20 +88,17 @@ class TodoListFilter extends StatelessWidget {
} }
} }
class TodoListHeader extends StatelessWidget { class TodoListHeader extends ConsumerWidget {
const TodoListHeader( const TodoListHeader({Key? key}) : super(key: key);
this.todosCount, {
Key? key,
}) : super(key: key);
final AsyncValue<int> todosCount;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<int> asyncTodosCount = ref.watch(todosCountProvider);
return Container( return Container(
height: 16, height: 16,
alignment: Alignment.center, alignment: Alignment.center,
child: todosCount.when( child: asyncTodosCount.when(
data: (count) => Text( data: (count) => Text(
"$count todos", "$count todos",
style: Theme.of(context).textTheme.subtitle2, style: Theme.of(context).textTheme.subtitle2,
......
import 'package:article_flutter_riverpod/presentation/01_introduction_example.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
...@@ -26,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> { ...@@ -26,7 +25,6 @@ class _TodoListState extends ConsumerState<TodoList> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final asyncTodos = ref.watch(todosProvider.selectTodos(_isUncheckedFilter)); final asyncTodos = ref.watch(todosProvider.selectTodos(_isUncheckedFilter));
final asyncTodosCount = ref.watch(todosCountProvider);
return Column( return Column(
children: [ children: [
...@@ -35,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> { ...@@ -35,9 +33,9 @@ class _TodoListState extends ConsumerState<TodoList> {
onFilterChanged: _onFilterChanged, onFilterChanged: _onFilterChanged,
), ),
const Divider(height: 1), const Divider(height: 1),
Padding( const Padding(
padding: const EdgeInsets.only(top: 16, bottom: 8), padding: EdgeInsets.only(top: 16, bottom: 8),
child: TodoListHeader(asyncTodosCount), child: TodoListHeader(),
), ),
Expanded( Expanded(
child: asyncTodos.when( child: asyncTodos.when(
...@@ -98,20 +96,17 @@ class TodoListFilter extends StatelessWidget { ...@@ -98,20 +96,17 @@ class TodoListFilter extends StatelessWidget {
} }
} }
class TodoListHeader extends StatelessWidget { class TodoListHeader extends ConsumerWidget {
const TodoListHeader( const TodoListHeader({Key? key}) : super(key: key);
this.todosCount, {
Key? key,
}) : super(key: key);
final AsyncValue<int> todosCount;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<int> asyncTodosCount = ref.watch(todosCountProvider);
return Container( return Container(
height: 16, height: 16,
alignment: Alignment.center, alignment: Alignment.center,
child: todosCount.when( child: asyncTodosCount.when(
data: (count) => Text( data: (count) => Text(
"$count todos", "$count todos",
style: Theme.of(context).textTheme.subtitle2, style: Theme.of(context).textTheme.subtitle2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment