Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[General]: Exception in the form_builder_field.dart file for a custom field #1340

Open
2 of 7 tasks
SonGoku85 opened this issue Dec 12, 2023 · 0 comments
Open
2 of 7 tasks
Labels
bug Something isn't working

Comments

@SonGoku85
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.1.1

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.3, on Ubuntu 22.04.3 LTS 6.2.0-37-generic, locale de_DE.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Community Edition (version 2023.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Minimal code example

class FormBuilderNumericField extends FormBuilderFieldDecoration<double> {
 
  FormBuilderNumericField({
    super.key,
    required super.name,
    super.validator,
    super.onChanged,
    double? initialValue,
  }) : super(
    builder: (FormFieldState<double?> field) {
      final state = field as _FormBuilderNumericFieldState;

      return NumericField(
        value: initialValue,
        onChanged: (newValue) {
          if(onChanged != null) {
            onChanged(newValue);
          }
          state.didChange(newValue);
        }
      );
    }
  );

  @override
  FormBuilderFieldDecorationState<FormBuilderNumericField, double> createState() => _FormBuilderNumericFieldState();
}

class _FormBuilderNumericFieldState extends FormBuilderFieldDecorationState<FormBuilderNumericField, double> {
}

Current Behavior

exception in form_builder_field.dart:
type 'String' is not a subtype of type 'double?' in type cast

Expected Behavior

I wrote my own field which gives me a double. That all works too. However, if I don't set "initialValue" (=null), I get the following exception in form_builder_field.dart:
type 'String' is not a subtype of type 'double?' in type cast

This is the line:

T? get initialValue =>
      widget.initialValue ??
      (_formBuilderState?.initialValue ??
          const <String, dynamic>{})[widget.name] as T?;

Steps To Reproduce

Use the small snippet of my code.

Aditional information

No response

@SonGoku85 SonGoku85 added the bug Something isn't working label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant