mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 04:50:36 +08:00
Merge pull request #480 from FreeBono/resolve-issue-479
fix: environment field trigger field is not initializing with empty value
This commit is contained in:
@ -51,7 +51,8 @@ class EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> {
|
||||
@override
|
||||
void didUpdateWidget(EnvironmentTriggerField oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.initialValue != widget.initialValue) {
|
||||
if ((oldWidget.keyId != widget.keyId) ||
|
||||
(oldWidget.initialValue != widget.initialValue)) {
|
||||
controller.text = widget.initialValue ?? "";
|
||||
controller.selection =
|
||||
TextSelection.collapsed(offset: controller.text.length);
|
||||
|
@ -45,4 +45,46 @@ void main() {
|
||||
|
||||
expect(fieldKey.currentState!.controller.text, updatedValue);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Testing EnvironmentTriggerField with empty initialValue clears the controller text',
|
||||
(WidgetTester tester) async {
|
||||
final fieldKey = GlobalKey<EnvironmentTriggerFieldState>();
|
||||
const initialValue = 'initial';
|
||||
const emptyValue = '';
|
||||
|
||||
await tester.pumpWidget(
|
||||
Portal(
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerField(
|
||||
key: fieldKey,
|
||||
keyId: 'testKey',
|
||||
initialValue: initialValue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Finder field = find.byType(ExtendedTextField);
|
||||
expect(field, findsOneWidget);
|
||||
expect(fieldKey.currentState!.controller.text, initialValue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Portal(
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerField(
|
||||
key: fieldKey,
|
||||
keyId: 'testKey',
|
||||
initialValue: emptyValue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(fieldKey.currentState!.controller.text, emptyValue);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user