File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
screens/home_page/editor_pane Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ class URLTextField extends ConsumerWidget {
81
81
.read (collectionStateNotifierProvider.notifier)
82
82
.update (selectedId, url: value);
83
83
},
84
+ onFieldSubmitted: (value) {
85
+ ref
86
+ .read (collectionStateNotifierProvider.notifier)
87
+ .sendRequest (selectedId);
88
+ },
84
89
);
85
90
}
86
91
}
Original file line number Diff line number Diff line change @@ -7,11 +7,13 @@ class URLField extends StatelessWidget {
7
7
required this .selectedId,
8
8
this .initialValue,
9
9
this .onChanged,
10
+ this .onFieldSubmitted,
10
11
});
11
12
12
13
final String selectedId;
13
14
final String ? initialValue;
14
15
final void Function (String )? onChanged;
16
+ final void Function (String )? onFieldSubmitted;
15
17
16
18
@override
17
19
Widget build (BuildContext context) {
@@ -29,6 +31,7 @@ class URLField extends StatelessWidget {
29
31
border: InputBorder .none,
30
32
),
31
33
onChanged: onChanged,
34
+ onFieldSubmitted: onFieldSubmitted,
32
35
);
33
36
}
34
37
}
Original file line number Diff line number Diff line change @@ -57,4 +57,41 @@ void main() {
57
57
await tester.pumpAndSettle ();
58
58
expect (find.text ('entering 123 for cell field' ), findsOneWidget);
59
59
});
60
+
61
+ testWidgets ('URL Field sends request on enter keystroke' , (tester) async {
62
+ bool wasSubmitCalled = false ;
63
+
64
+ void testSubmit (String val) {
65
+ wasSubmitCalled = true ;
66
+ }
67
+
68
+ await tester.pumpWidget (
69
+ MaterialApp (
70
+ title: 'URL Field' ,
71
+ theme: kThemeDataDark,
72
+ home: Scaffold (
73
+ body: Column (children: [
74
+ URLField (
75
+ selectedId: '2' ,
76
+ onFieldSubmitted: testSubmit,
77
+ )
78
+ ]),
79
+ ),
80
+ ),
81
+ );
82
+
83
+ // ensure URLField is blank
84
+ expect (find.byType (TextFormField ), findsOneWidget);
85
+ expect (find.textContaining ('Enter API endpoint ' ), findsOneWidget);
86
+ expect (wasSubmitCalled, false );
87
+
88
+ // modify value and press enter
89
+ var txtForm = find.byKey (const Key ("url-2" ));
90
+ await tester.enterText (txtForm, 'entering 123' );
91
+ await tester.testTextInput.receiveAction (TextInputAction .done);
92
+ await tester.pump ();
93
+
94
+ // check if value was updated
95
+ expect (wasSubmitCalled, true );
96
+ });
60
97
}
You can’t perform that action at this time.
0 commit comments