Code sample
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: FormPage(),
);
}
}
class FormPage extends StatefulWidget {
final _formKey = GlobalKey<FormBuilderState>();
FormPage({super.key});
@override
State<FormPage> createState() => _FormPageState();
}
class _FormPageState extends State<FormPage> {
bool? isValid;
@override
Widget build(BuildContext context) {
return FormBuilder(
key: widget._formKey,
autovalidateMode: AutovalidateMode.always,
onChanged: () {
// rebuild when form changes
isValid = widget._formKey.currentState?.isValid;
setState(() {});
},
child: Scaffold(
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
// UI BELOW //
children: [
FormBuilderTextField(
name: 'email',
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(),
FormBuilderValidators.email(),
]),
),
const SizedBox(height: 16),
Text(
isValid == null
? 'initial state'
: isValid!
? 'valid'
: 'invalid',
),
// UI ABOVE //
],
),
),
),
),
);
}
}
[ ] DwdsVmClient: Attempting a hot restart
[ ] DwdsVmClient: Attempting to disable breakpoints and resume the isolate
[ +1 ms] DwdsVmClient: Successfully disabled breakpoints and resumed the isolate
[ ] DwdsVmClient: Attempting to get execution context ID.
[ ] DwdsVmClient: Got execution context ID.
[ ] DwdsVmClient: Issuing $dartHotRestartDwds request
[ +361 ms] ChromeProxyService: Initializing expression compiler for main_module.bootstrap.js with sound null safety: true
[ +20 ms] DwdsVmClient: $dartHotRestartDwds request complete.
[ ] DwdsVmClient: Waiting for Isolate Start event.
[ +57 ms] DwdsVmClient: Successful hot restart
[ +8 ms] Restarted application in 571ms.
[ +31 ms] DevHandler: VmService proxy responded with an error:
{jsonrpc: 2.0, id: 144, error: {code: -32601, message: Method not found, data: {jsonrpc: 2.0, method: _setStreamIncludePrivateMembers, id: 144, params: {streamId: Isolate, includePrivateMembers: false}}}}
[ +52 ms] [🌎 Easy Localization] [DEBUG] Localization initialized
[ +2 ms] DevHandler: VmService proxy responded with an error:
{jsonrpc: 2.0, id: 149, error: {code: -32601, message: setLibraryDebuggable: Not supported on web devices}}
[ +3 ms] WARNING: You are using the Auth Emulator, which is intended for local testing only. Do not use with production credentials.
[ +14 ms] [2022-11-28T12:33:35.782Z] @firebase/firestore:
[ +2 ms] [🌎 Easy Localization] [DEBUG] Start
[ +64 ms] [🌎 Easy Localization] [DEBUG] Init state
[ +7 ms] [🌎 Easy Localization] [DEBUG] Build
[ +4 ms] [🌎 Easy Localization] [DEBUG] Init Localization Delegate
[ +1 ms] [🌎 Easy Localization] [DEBUG] Init provider
[ +58 ms] [🌎 Easy Localization] [DEBUG] Load Localization Delegate
[log] easy localization loader: load yaml file assets/translations/en-US.yaml
[ +352 ms] �[3;38;5;244m🐛 15:33:36.278 DEBUG [Logic][LoggingBlocObserver] - Instance of 'FormCubit' is being created.
[ +1 ms] 🤔 15:33:36.280 TRACE [Logic][LoggingBlocObserver] - bloc: Instance of 'FormCubit'
[+272865 ms] false
[ +3 ms] �[3;38;5;244m🐛 15:38:09.151 DEBUG [Logic][LoggingBlocObserver] - Instance of 'FormCubit' is on change.
[ +2 ms] 🤔 15:38:09.154 TRACE [Logic][LoggingBlocObserver] - change: Change { currentState: FormState.initial(), nextState: FormState.invalid(fields: {email: _FormBuilderTextFieldState#56f1d, password: _FormBuilderTextFieldState#cd37b}) }
[ +156 ms] false
[ +88 ms] false
[ +178 ms] false
[ +208 ms] false
[ +81 ms] false
[ +277 ms] false
[ +223 ms] false
[ +144 ms] false
[ +111 ms] false
[ +320 ms] false
[ +81 ms] false
[ +267 ms] ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
[ ] The following assertion was thrown during a platform message callback:
[ ] Assertion failed:
[ ]
[ ] event is! RawKeyDownEvent || _keysPressed.isNotEmpty
[ ] "Attempted to send a key down event when no keys are in keysPressed. This state can occur if the key
[ ] event being sent doesn't properly set its modifier flags. This was the event:
[ ] RawKeyDownEvent#cbfbd(logicalKey: LogicalKeyboardKey#9d80f(keyId: \"0x17032c92bb\", keyLabel: \"\",
[ ] debugName: \"Key with ID 0x017032c92bb\"), physicalKey: PhysicalKeyboardKey#700e6(usbHidUsage:
[ ] \"0x000700e6\", debugName: \"Alt Right\"), repeat: false) and its data:
[ ] RawKeyEventDataWeb#6459c(code: AltRight, key: AltGraph, location: 2, metaState: 0, keyCode: 225)"
[ ] When the exception was thrown, this was the stack:
[ ] dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw_
[ ] dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed
[ ] packages/flutter/src/services/raw_keyboard.dart 682:49 handleRawKeyEvent
[ ] packages/flutter/src/services/hardware_keyboard.dart 878:30 handleRawKeyMessage
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
[ ] packages/flutter/src/services/hardware_keyboard.dart 850:51 handleRawKeyMessage
[ ] packages/flutter/src/services/platform_channel.dart 197:49 <fn>
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
[ ] packages/flutter/src/services/platform_channel.dart 196:58 <fn>
[ ] packages/flutter/src/services/binding.dart 387:35 <fn>
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody
[ ] dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async
[ ] packages/flutter/src/services/binding.dart 384:98 <fn>
[ ] lib/_engine/engine/platform_dispatcher.dart 1199:13 invoke2
[ ] lib/ui/channel_buffers.dart 25:12 invoke
[ ] lib/ui/channel_buffers.dart 65:7 push
[ ] lib/ui/channel_buffers.dart 130:16 push
[ ] lib/_engine/engine/platform_dispatcher.dart 364:25 invokeOnPlatformMessage
[ ] lib/_engine/engine/keyboard.dart 130:39 [_handleHtmlEvent]
[ ] lib/_engine/engine/keyboard.dart 32:7 <fn>
[ ] dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall
[ ] dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall
[ ] ════════════════════════════════════════════════════════════════════════════════════════════════════
[ +2 ms] false
[ +188 ms] false
[ +136 ms] false
[ +92 ms] false
[ +139 ms] false
[ +86 ms] false
[ +208 ms] false
[ +129 ms] false
[ +124 ms] false
[ +88 ms] false
[ +867 ms] false
[ +174 ms] false
[ +167 ms] false
[ +152 ms] false
[ +295 ms] false
[ +167 ms] false
[ +168 ms] false
[ +168 ms] false
[+107543 ms] Another exception was thrown: Assertion failed:
[+53881 ms] true
[ +2 ms] �[3;38;5;244m🐛 15:40:56.085 DEBUG [Logic][LoggingBlocObserver] - Instance of 'FormCubit' is on change.
[ +1 ms] 🤔 15:40:56.088 TRACE [Logic][LoggingBlocObserver] - change: Change { currentState: FormState.invalid(fields: {email: _FormBuilderTextFieldState#56f1d, password: _FormBuilderTextFieldState#cd37b}), nextState: FormState.valid(fields: {email: _FormBuilderTextFieldState#56f1d, password: _FormBuilderTextFieldState#cd37b}) }
Environment
Package version: 7.7.0
Flutter doctor
Code sample
Description
Expected behavior:
_formKey.currentState.isValidshould return true when all the fields in the form are valid.Current behavior: It does not return true.
Steps to reproduce
_formKey.currentState.isValidis false.Images
Stacktrace/Logcat