@@ -9,83 +9,7 @@ import 'package:flutter/rendering.dart';
9
9
import 'package:flutter/services.dart' ;
10
10
import 'package:flutter_test/flutter_test.dart' ;
11
11
12
- typedef PostInvokeCallback = void Function ({Action <Intent > action, Intent intent, ActionDispatcher dispatcher});
13
-
14
- class TestIntent extends Intent {
15
- const TestIntent ();
16
- }
17
-
18
- class SecondTestIntent extends TestIntent {
19
- const SecondTestIntent ();
20
- }
21
-
22
- class ThirdTestIntent extends SecondTestIntent {
23
- const ThirdTestIntent ();
24
- }
25
-
26
- class TestAction extends CallbackAction <TestIntent > {
27
- TestAction ({
28
- required OnInvokeCallback onInvoke,
29
- }) : assert (onInvoke != null ),
30
- super (onInvoke: onInvoke);
31
-
32
- @override
33
- bool isEnabled (TestIntent intent) => enabled;
34
-
35
- bool get enabled => _enabled;
36
- bool _enabled = true ;
37
- set enabled (bool value) {
38
- if (_enabled == value) {
39
- return ;
40
- }
41
- _enabled = value;
42
- notifyActionListeners ();
43
- }
44
-
45
- @override
46
- void addActionListener (ActionListenerCallback listener) {
47
- super .addActionListener (listener);
48
- listeners.add (listener);
49
- }
50
-
51
- @override
52
- void removeActionListener (ActionListenerCallback listener) {
53
- super .removeActionListener (listener);
54
- listeners.remove (listener);
55
- }
56
- List <ActionListenerCallback > listeners = < ActionListenerCallback > [];
57
-
58
- void _testInvoke (TestIntent intent) => invoke (intent);
59
- }
60
-
61
- class TestDispatcher extends ActionDispatcher {
62
- const TestDispatcher ({this .postInvoke});
63
-
64
- final PostInvokeCallback ? postInvoke;
65
-
66
- @override
67
- Object ? invokeAction (Action <Intent > action, Intent intent, [BuildContext ? context]) {
68
- final Object ? result = super .invokeAction (action, intent, context);
69
- postInvoke? .call (action: action, intent: intent, dispatcher: this );
70
- return result;
71
- }
72
- }
73
-
74
- class TestDispatcher1 extends TestDispatcher {
75
- const TestDispatcher1 ({super .postInvoke});
76
- }
77
-
78
12
void main () {
79
- testWidgets ('CallbackAction passes correct intent when invoked.' , (WidgetTester tester) async {
80
- late Intent passedIntent;
81
- final TestAction action = TestAction (onInvoke: (Intent intent) {
82
- passedIntent = intent;
83
- return true ;
84
- });
85
- const TestIntent intent = TestIntent ();
86
- action._testInvoke (intent);
87
- expect (passedIntent, equals (intent));
88
- });
89
13
group (ActionDispatcher , () {
90
14
testWidgets ('ActionDispatcher invokes actions when asked.' , (WidgetTester tester) async {
91
15
await tester.pumpWidget (Container ());
@@ -1033,6 +957,29 @@ void main() {
1033
957
);
1034
958
});
1035
959
960
+ group ('Action subclasses' , () {
961
+ testWidgets ('CallbackAction passes correct intent when invoked.' , (WidgetTester tester) async {
962
+ late Intent passedIntent;
963
+ final TestAction action = TestAction (onInvoke: (Intent intent) {
964
+ passedIntent = intent;
965
+ return true ;
966
+ });
967
+ const TestIntent intent = TestIntent ();
968
+ action._testInvoke (intent);
969
+ expect (passedIntent, equals (intent));
970
+ });
971
+ testWidgets ('VoidCallbackAction' , (WidgetTester tester) async {
972
+ bool called = false ;
973
+ void testCallback () {
974
+ called = true ;
975
+ }
976
+ final VoidCallbackAction action = VoidCallbackAction ();
977
+ final VoidCallbackIntent intent = VoidCallbackIntent (testCallback);
978
+ action.invoke (intent);
979
+ expect (called, isTrue);
980
+ });
981
+ });
982
+
1036
983
group ('Diagnostics' , () {
1037
984
testWidgets ('default Intent debugFillProperties' , (WidgetTester tester) async {
1038
985
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder ();
@@ -1766,6 +1713,72 @@ void main() {
1766
1713
});
1767
1714
}
1768
1715
1716
+ typedef PostInvokeCallback = void Function ({Action <Intent > action, Intent intent, ActionDispatcher dispatcher});
1717
+
1718
+ class TestIntent extends Intent {
1719
+ const TestIntent ();
1720
+ }
1721
+
1722
+ class SecondTestIntent extends TestIntent {
1723
+ const SecondTestIntent ();
1724
+ }
1725
+
1726
+ class ThirdTestIntent extends SecondTestIntent {
1727
+ const ThirdTestIntent ();
1728
+ }
1729
+
1730
+ class TestAction extends CallbackAction <TestIntent > {
1731
+ TestAction ({
1732
+ required OnInvokeCallback onInvoke,
1733
+ }) : assert (onInvoke != null ),
1734
+ super (onInvoke: onInvoke);
1735
+
1736
+ @override
1737
+ bool isEnabled (TestIntent intent) => enabled;
1738
+
1739
+ bool get enabled => _enabled;
1740
+ bool _enabled = true ;
1741
+ set enabled (bool value) {
1742
+ if (_enabled == value) {
1743
+ return ;
1744
+ }
1745
+ _enabled = value;
1746
+ notifyActionListeners ();
1747
+ }
1748
+
1749
+ @override
1750
+ void addActionListener (ActionListenerCallback listener) {
1751
+ super .addActionListener (listener);
1752
+ listeners.add (listener);
1753
+ }
1754
+
1755
+ @override
1756
+ void removeActionListener (ActionListenerCallback listener) {
1757
+ super .removeActionListener (listener);
1758
+ listeners.remove (listener);
1759
+ }
1760
+ List <ActionListenerCallback > listeners = < ActionListenerCallback > [];
1761
+
1762
+ void _testInvoke (TestIntent intent) => invoke (intent);
1763
+ }
1764
+
1765
+ class TestDispatcher extends ActionDispatcher {
1766
+ const TestDispatcher ({this .postInvoke});
1767
+
1768
+ final PostInvokeCallback ? postInvoke;
1769
+
1770
+ @override
1771
+ Object ? invokeAction (Action <Intent > action, Intent intent, [BuildContext ? context]) {
1772
+ final Object ? result = super .invokeAction (action, intent, context);
1773
+ postInvoke? .call (action: action, intent: intent, dispatcher: this );
1774
+ return result;
1775
+ }
1776
+ }
1777
+
1778
+ class TestDispatcher1 extends TestDispatcher {
1779
+ const TestDispatcher1 ({super .postInvoke});
1780
+ }
1781
+
1769
1782
class TestContextAction extends ContextAction <TestIntent > {
1770
1783
List <BuildContext ?> capturedContexts = < BuildContext ? > [];
1771
1784
0 commit comments