1
+ import 'dart:typed_data' ;
2
+ import 'dart:ui' ;
3
+
1
4
import 'package:flutter/foundation.dart' show ChangeNotifier, ValueNotifier;
5
+ import 'package:flutter/rendering.dart' ;
2
6
import 'package:flutter_animation/pizza_order/constant/ingredient.dart' ;
3
7
4
- class PizzaOrderBLoC extends ChangeNotifier {
8
+ enum PizzaSizeValue {
9
+ s,
10
+ m,
11
+ l,
12
+ }
13
+
14
+ class PizzaSizeState {
15
+ PizzaSizeState (this .value) : factor = _getFactorBySize (value);
16
+ final PizzaSizeValue value;
17
+ final double factor;
18
+
19
+ static double _getFactorBySize (PizzaSizeValue value) {
20
+ switch (value) {
21
+ case PizzaSizeValue .s:
22
+ return 0.75 ;
23
+ case PizzaSizeValue .m:
24
+ return 0.85 ;
25
+ case PizzaSizeValue .l:
26
+ return 1.0 ;
27
+ }
28
+ return 0.0 ;
29
+ }
30
+ }
31
+
32
+ class PizzaMetadata {
33
+ const PizzaMetadata (this .imageBytes, this .position, this .size);
34
+
35
+ final Uint8List imageBytes;
36
+ final Offset position;
37
+ final Size size;
38
+ }
39
+
40
+ const initialTotal = 15 ;
41
+
42
+ class PizzaOrderBLoC extends ChangeNotifier {
5
43
final listIngredients = < Ingredient > [];
6
- final notifierTotal = ValueNotifier (15 );
44
+ final notifierTotal = ValueNotifier (initialTotal );
7
45
final notifierDeletedIngredient = ValueNotifier <Ingredient >(null );
8
- void addIngredient (Ingredient ingredient){
46
+ final notifierFocused = ValueNotifier (false );
47
+ final notifierPizzaSize =
48
+ ValueNotifier <PizzaSizeState >(PizzaSizeState (PizzaSizeValue .m));
49
+ final notifierPizzaBoxAnimation = ValueNotifier (false );
50
+
51
+ final notifierImagePizza = ValueNotifier <PizzaMetadata >(null );
52
+ final notifierCartIconAnimation = ValueNotifier (0 );
53
+
54
+ void addIngredient (Ingredient ingredient) {
9
55
listIngredients.add (ingredient);
10
56
notifierTotal.value++ ;
11
57
}
12
58
13
- bool containsIngredient (Ingredient ingredient){
59
+ bool containsIngredient (Ingredient ingredient) {
14
60
for (Ingredient i in listIngredients) {
15
61
if (i.compare (ingredient)) {
16
62
return true ;
@@ -22,12 +68,31 @@ class PizzaOrderBLoC extends ChangeNotifier{
22
68
void removeIngredient (Ingredient ingredient) {
23
69
listIngredients.remove (ingredient);
24
70
notifierTotal.value-- ;
25
- notifierDeletedIngredient.value = ingredient;
26
-
71
+ notifierDeletedIngredient.value = ingredient;
27
72
}
28
73
29
74
void refreshDeletedIngredient () {
30
75
notifierDeletedIngredient.value = null ;
31
76
}
32
77
78
+ void reset () {
79
+ notifierPizzaBoxAnimation.value = false ;
80
+ notifierImagePizza.value = null ;
81
+ listIngredients.clear ();
82
+ notifierTotal.value = initialTotal;
83
+ notifierCartIconAnimation.value++ ;
84
+ }
85
+
86
+ void startPizzaBoxAnimation () {
87
+ notifierPizzaBoxAnimation.value = true ;
88
+ }
89
+
90
+ Future <void > transformToImage (RenderRepaintBoundary boundary) async {
91
+ final position = boundary.localToGlobal (Offset .zero);
92
+ final size = boundary.size;
93
+ final image = await boundary.toImage ();
94
+ ByteData byteData = await image.toByteData (format: ImageByteFormat .png);
95
+ notifierImagePizza.value =
96
+ PizzaMetadata (byteData.buffer.asUint8List (), position, size);
97
+ }
33
98
}
0 commit comments