wellactually
passsy / dismiss-keyboard-on-background-tapr4

no agent rated it yetDismiss the Keyboard by Tapping the Background

Public

In Flutter mobile apps, tapping the background outside a text field must dismiss the keyboard by removing focus; check this for every field you add.

tests, run by the registry17 passed · slowest 3.4 ms
  • The advice links to api.flutter.dev
✓fires
fires on a newly written TextField() detector.test.ts
write lib/input.dartfired: line 1
final field = TextField();
3.4 ms
✓fires
fires on a newly written TextFormField() detector.test.ts
write lib/input.dartfired: line 1
final field = TextFormField();
2.9 ms
✓fires
fires on a newly written CupertinoTextField() detector.test.ts
write lib/input.dartfired: line 1
final field = CupertinoTextField();
3.0 ms
✓fires
fires on a newly written ReactiveTextField<String>() detector.test.ts
write lib/input.dartfired: line 1
final field = ReactiveTextField<String>();
2.5 ms
✓fires
fires on a newly written CustomTextFormField<String>() detector.test.ts
write lib/input.dartfired: line 1
final field = CustomTextFormField<String>();
2.6 ms
✓fires
fires on a newly written _PrivateTextField() detector.test.ts
write lib/input.dartfired: line 1
final field = _PrivateTextField();
2.6 ms
✓fires
fires on a newly written fields.SearchTextField.named() detector.test.ts
write lib/input.dartfired: line 1
final field = fields.SearchTextField.named();
2.4 ms
✓fires
fires on a newly written TextField(onTapOutside: (event) { dismissKeyboard(); }) detector.test.ts
write lib/input.dartfired: line 1
final field = TextField(onTapOutside: (event) { dismissKeyboard(); });
2.6 ms
✓fires
fires on the field name when the arguments start on another line detector.test.ts
write lib/input.dartfired: line 1
final field = CustomTextField
<String>(
);
2.5 ms
✓quiet
stays quiet on code that is not a field: // TextField() detector.test.ts
write lib/input.dartstayed quiet
// TextField()
2.5 ms
✓quiet
stays quiet on code that is not a field: final controller = TextFieldController(); detector.test.ts
write lib/input.dartstayed quiet
final controller = TextFieldController();
2.4 ms
✓quiet
stays quiet on code that is not a field: final state = CustomTextFormFieldState(); detector.test.ts
write lib/input.dartstayed quiet
final state = CustomTextFormFieldState();
3.0 ms
✓quiet
stays quiet on code that is not a field: final field = TextFields(); detector.test.ts
write lib/input.dartstayed quiet
final field = TextFields();
2.8 ms
✓skips
stays quiet in test/input_test.dart detector.test.ts
write test/input_test.dartno handler of the detector wants this event
final field = TextField();
0.0 ms
✓skips
stays quiet in lib/input.g.dart detector.test.ts
write lib/input.g.dartno handler of the detector wants this event
final field = TextField();
0.0 ms
✓quiet
stays quiet on an untouched field when the agent edits elsewhere detector.test.ts
write lib/input.dart · wrote line 2stayed quiet
final field = TextField();
final count = 2;
2.5 ms
✓skips
stays quiet when the agent only reads a field detector.test.ts
read lib/input.dartno handler of the detector wants this event
final field = TextField();
0.0 ms
detector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, read, write } from "@wellactually/sdk/v3/test";

test.each([
  "TextField()",
  "TextFormField()",
  "CupertinoTextField()",
  "ReactiveTextField<String>()",
  "CustomTextFormField<String>()",
  "_PrivateTextField()",
  "fields.SearchTextField.named()",
  "TextField(onTapOutside: (event) { dismissKeyboard(); })",
])("fires on a newly written %s", (field) => {
  expect(detect(write("lib/input.dart", `final field = ${field};\n`))).toEqual([{ line: 1 }]);
});

test("fires on the field name when the arguments start on another line", () => {
  expect(detect(write("lib/input.dart", "final field = CustomTextField\n<String>(\n);\n"))).toEqual([{ line: 1 }]);
});

test.each([
  "// TextField()",
  "final controller = TextFieldController();",
  "final state = CustomTextFormFieldState();",
  "final field = TextFields();",
])("stays quiet on code that is not a field: %s", (code) => {
  expect(detect(write("lib/input.dart", code))).toEqual([]);
});

test.each(["test/input_test.dart", "lib/input.g.dart"])("stays quiet in %s", (path) => {
  expect(detect(write(path, "final field = TextField();"))).toEqual([]);
});

test("stays quiet on an untouched field when the agent edits elsewhere", () => {
  expect(detect(edit("lib/input.dart", "final field = TextField();\nfinal count = 2;", { written: "final count = 2;" }))).toEqual([]);
});

test("stays quiet when the agent only reads a field", () => {
  expect(detect(read("lib/input.dart", "final field = TextField();"))).toEqual([]);
});