Skip to content

Commit fcefe78

Browse files
authored
Merge pull request #253 from opxdelwin/issue-252-updated
[feat] Implement Press Enter to Send Request in URL Input Field
2 parents 1abc29a + 27bb3d8 commit fcefe78

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

lib/screens/home_page/editor_pane/url_card.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class URLTextField extends ConsumerWidget {
8181
.read(collectionStateNotifierProvider.notifier)
8282
.update(selectedId, url: value);
8383
},
84+
onFieldSubmitted: (value) {
85+
ref
86+
.read(collectionStateNotifierProvider.notifier)
87+
.sendRequest(selectedId);
88+
},
8489
);
8590
}
8691
}

lib/widgets/textfields.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ class URLField extends StatelessWidget {
77
required this.selectedId,
88
this.initialValue,
99
this.onChanged,
10+
this.onFieldSubmitted,
1011
});
1112

1213
final String selectedId;
1314
final String? initialValue;
1415
final void Function(String)? onChanged;
16+
final void Function(String)? onFieldSubmitted;
1517

1618
@override
1719
Widget build(BuildContext context) {
@@ -29,6 +31,7 @@ class URLField extends StatelessWidget {
2931
border: InputBorder.none,
3032
),
3133
onChanged: onChanged,
34+
onFieldSubmitted: onFieldSubmitted,
3235
);
3336
}
3437
}

test/widgets/textfields_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,41 @@ void main() {
5757
await tester.pumpAndSettle();
5858
expect(find.text('entering 123 for cell field'), findsOneWidget);
5959
});
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+
});
6097
}

0 commit comments

Comments
 (0)