passsy / prefer-reactive-formsr4
Prefer reactive_forms for Form Handling
PublicHandle Flutter forms with package:reactive_forms instead of Form, TextFormField and TextEditingController, so form state and validation live in one model.
tests, run by the registry9 passed · slowest 6.2 ms
- The advice links to pub.dev
✓fires2.8 ms
fires on hand-rolled form plumbing the agent writes
write lib/login_page.dartfired: line 2, line 3, line 9
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(controller: _email),
);
}
}✓quiet3.3 ms
stays quiet on a TextEditingController outside a form
write lib/search_bar.dartstayed quiet
class _SearchBarState extends State<SearchBar> {
final _query = TextEditingController();
}✓quiet3.1 ms
stays quiet in a file that already uses reactive_forms
write lib/login_page.dartstayed quiet
import 'package:reactive_forms/reactive_forms.dart';
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(controller: _email),
);
}
}✓quiet3.2 ms
stays quiet on plumbing the edit did not touch
write lib/login_page.dart · wrote line 7stayed quiet
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(controller: _email),
);
}
}✓skips0.0 ms
stays quiet when the agent only reads the file
read lib/login_page.dartno handler of the detector wants this event
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(controller: _email),
);
}
}✓fires4.2 ms
fires on flutter_form_builder added to the pubspec
write pubspec.yamlfired: line 3
namedemo
dependencies
flutter_form_builder^9.0.0
# flutter_form_builder: ^8.0.0
✓fires4.0 ms
points at the principle when the user mentions forms in a Dart project
prompt · in fixtures/dart_appfired: "forms"
Build the signup forms for the onboarding flow✓quiet6.2 ms
stays quiet on the bare word form
prompt · in fixtures/dart_appstayed quiet
Return the result in the form of a list✓quiet4.1 ms
stays quiet outside a Dart project
promptstayed quiet
Build the signup forms for the onboarding flowdetector.test.tseach detect() call runs the real detectorEdit
import { expect, test } from "vitest";
import { detect, edit, prompt, read, source, write } from "@wellactually/sdk/v3/test";
const loginForm = source`
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: TextFormField(controller: _email),
);
}
}
`;
test("fires on hand-rolled form plumbing the agent writes", () => {
expect(detect(write("lib/login_page.dart", loginForm))).toEqual([
{ line: 2 },
{ line: 3 },
{ line: 9 },
]);
});
test("stays quiet on a TextEditingController outside a form", () => {
const search = source`
class _SearchBarState extends State<SearchBar> {
final _query = TextEditingController();
}
`;
expect(detect(write("lib/search_bar.dart", search))).toEqual([]);
});
test("stays quiet in a file that already uses reactive_forms", () => {
const code = "import 'package:reactive_forms/reactive_forms.dart';\n" + loginForm;
expect(detect(write("lib/login_page.dart", code))).toEqual([]);
});
test("stays quiet on plumbing the edit did not touch", () => {
expect(detect(edit("lib/login_page.dart", loginForm, { written: " return Form(" }))).toEqual([]);
});
test("stays quiet when the agent only reads the file", () => {
expect(detect(read("lib/login_page.dart", loginForm))).toEqual([]);
});
test("fires on flutter_form_builder added to the pubspec", () => {
const pubspec = "name: demo\ndependencies:\n flutter_form_builder: ^9.0.0\n # flutter_form_builder: ^8.0.0\n";
expect(detect(write("pubspec.yaml", pubspec))).toEqual([{ line: 3 }]);
});
const dartApp = { project: "fixtures/dart_app" };
test("points at the principle when the user mentions forms in a Dart project", () => {
expect(detect(prompt("Build the signup forms for the onboarding flow"), dartApp)).toEqual([{ match: "forms", depth: "pointer" }]);
});
test("stays quiet on the bare word form", () => {
expect(detect(prompt("Return the result in the form of a list"), dartApp)).toEqual([]);
});
test("stays quiet outside a Dart project", () => {
expect(detect(prompt("Build the signup forms for the onboarding flow"))).toEqual([]);
});