Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
article_flutter_riverpod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adrien BONNIN
article_flutter_riverpod
Commits
18c3596a
Commit
18c3596a
authored
2 years ago
by
Adrien BONNIN
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des examples pour la présentation
parent
b3f83953
No related branches found
No related tags found
No related merge requests found
Pipeline
#78764
passed
2 years ago
Stage: test
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/main.dart
+7
-0
7 additions, 0 deletions
lib/main.dart
lib/presentation/smaller_stateful_example.dart
+55
-0
55 additions, 0 deletions
lib/presentation/smaller_stateful_example.dart
test/presentation/listener_test.dart
+27
-0
27 additions, 0 deletions
test/presentation/listener_test.dart
with
89 additions
and
0 deletions
lib/main.dart
+
7
−
0
View file @
18c3596a
...
@@ -3,6 +3,7 @@ import 'package:article_flutter_riverpod/article_02/consumer_example.dart';
...
@@ -3,6 +3,7 @@ import 'package:article_flutter_riverpod/article_02/consumer_example.dart';
import
'package:article_flutter_riverpod/article_02/parent_example.dart'
;
import
'package:article_flutter_riverpod/article_02/parent_example.dart'
;
import
'package:article_flutter_riverpod/article_02/stateful_example.dart'
;
import
'package:article_flutter_riverpod/article_02/stateful_example.dart'
;
import
'package:article_flutter_riverpod/article_02/stateless_example.dart'
;
import
'package:article_flutter_riverpod/article_02/stateless_example.dart'
;
import
'package:article_flutter_riverpod/presentation/smaller_stateful_example.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:go_router/go_router.dart'
;
...
@@ -25,6 +26,12 @@ final examples = [
...
@@ -25,6 +26,12 @@ final examples = [
path:
'stateful'
,
path:
'stateful'
,
builder:
(
_
)
=
>
const
StatefulExample
(),
builder:
(
_
)
=
>
const
StatefulExample
(),
),
),
Example
(
title:
'Stateful (smaller)'
,
icon:
Icons
.
add_circle_outline
,
path:
'smaller-stateful'
,
builder:
(
_
)
=
>
const
SmallerStatefulExample
(),
),
Example
(
Example
(
title:
'Parent ProviderScope'
,
title:
'Parent ProviderScope'
,
icon:
Icons
.
child_care
,
icon:
Icons
.
child_care
,
...
...
This diff is collapsed.
Click to expand it.
lib/presentation/smaller_stateful_example.dart
0 → 100644
+
55
−
0
View file @
18c3596a
import
'package:flutter/material.dart'
;
import
'package:flutter_riverpod/flutter_riverpod.dart'
;
final
countServiceProvider
=
StateNotifierProvider
<
CountService
,
int
>((
ref
)
=
>
CountService
(
42
));
// <1>
class
CountService
extends
StateNotifier
<
int
>
{
CountService
(
int
firstValue
)
:
super
(
firstValue
);
void
increment
()
{
state
++
;
}
}
class
SmallerStatefulExample
extends
StatelessWidget
{
const
SmallerStatefulExample
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
const
ProviderScope
(
child:
Counter
(),
);
}
}
class
Counter
extends
ConsumerStatefulWidget
{
// <2>
const
Counter
({
Key
?
key
})
:
super
(
key:
key
);
@override
ConsumerState
<
Counter
>
createState
()
=
>
_CounterState
();
// <3>
}
class
_CounterState
extends
ConsumerState
<
Counter
>
{
// <4>
late
int
firstValue
;
@override
void
initState
()
{
super
.
initState
();
firstValue
=
ref
.
read
(
countServiceProvider
);
// <5>
}
@override
Widget
build
(
BuildContext
context
)
{
// <6>
final
currentValue
=
ref
.
watch
(
countServiceProvider
);
// <7>
return
Column
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
ElevatedButton
(
// <8>
onPressed:
()
=
>
ref
.
read
(
countServiceProvider
.
notifier
)
.
increment
(),
// <9>
child:
Text
(
"Increment
$firstValue
->
$currentValue
"
),
),
],
);
}
}
This diff is collapsed.
Click to expand it.
test/presentation/listener_test.dart
0 → 100644
+
27
−
0
View file @
18c3596a
import
'package:flutter_riverpod/flutter_riverpod.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'../utils.dart'
;
final
intProvider
=
StateProvider
<
int
>((
_
)
=
>
13
);
// <1>
void
main
()
{
test
(
'doit écouter un état'
,
()
{
const
defaultValue
=
-
1
;
// given:
final
container
=
createContainer
();
var
intValue
=
defaultValue
;
// <2>
container
.
listen
<
int
>(
intProvider
,
(
_
,
next
)
=
>
intValue
=
next
);
// expect:
expect
(
intValue
,
equals
(
defaultValue
));
// <3>
// when:
container
.
read
(
intProvider
.
notifier
)
.
state
=
42
;
// <4>
// then:
expect
(
intValue
,
equals
(
42
));
// <5>
});
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment