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

FormBuilderDateTimePicker calendar not disposing properly and crashing #1210

Closed
MattConflitti opened this issue Mar 26, 2023 · 1 comment · Fixed by #1268
Closed

FormBuilderDateTimePicker calendar not disposing properly and crashing #1210

MattConflitti opened this issue Mar 26, 2023 · 1 comment · Fixed by #1268
Assignees
Labels
bug Something isn't working

Comments

@MattConflitti
Copy link

Environment

Package version: 7.8.0

Flutter doctor
[✓] Flutter (Channel stable, 3.7.6, on macOS 12.6 21G115 darwin-arm64, locale en-US)
    • Flutter version 3.7.6 on channel stable at /Users/mattc/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12cb4eb7a0 (3 weeks ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/mattc/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.71.2)
    • VS Code at /Users/mattc/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 01B33C0A-0548-4C4E-BB59-D32155592120 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2
      (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 12.6 21G115 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 111.0.5563.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
Code sample
FormBuilder(
  key: _formKey,
  child: FormBuilderDateTimePicker(
      inputType: InputType.date,
      decoration: const InputDecoration(
        labelText: 'Start Date',
        labelStyle: TextStyle(fontSize: 20),
        filled: true,
        fillColor: Colors.white,
      ),
      maxLines: 1,
      autocorrect: false,
      name: 'start_date',
      initialValue: DateTime.now(),
      style: const TextStyle(fontSize: 25),
      onChanged: (value) {},
      valueTransformer: (value) => value.toString(),
      // controller: nameTextFieldController,
    ),
)

Description

Expected behavior:
Should be able to update the date when hitting okay

Current behavior:
Throws an error related to dispose and setState

Steps to reproduce

  1. Click on field to change the date.
  2. Change date
  3. Tap okay

Debugger highlights this code from the _FormBuilderDateTimePickerState

  @override
  void dispose() {
    effectiveFocusNode.removeListener(_handleFocus);
    // Dispose the _textFieldController when initState created it
    if (null == widget.controller) {
      _textFieldController.dispose();
    }
    super.dispose();
  }

  Future<void> _handleFocus() async {
    if (effectiveFocusNode.hasFocus && enabled) {
      effectiveFocusNode.unfocus();
      await onShowPicker(context, value); // <<<----- HERE
    }
  }

Stacktrace/Logcat

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

#0      State.setState.<anonymous closure>
package:flutter/…/widgets/framework.dart:1097
#1      State.setState
package:flutter/…/widgets/framework.dart:1132
#2      FormFieldState.didChange
package:flutter/…/widgets/form.dart:459
#3      FormBuilderFieldState.didChange
package:flutter_form_builder/src/form_builder_field.dart:201
#4      _FormBuilderDateTimePickerState.didChange
package:flutter_form_builder/…/fields/form_builder_date_time_picker.dart:388
#5      _FormBuilderDateTimePickerState.onShowPicker
package:flutter_form_builder/…/fields/form_builder_date_time_picker.dart:312
<asynchronous suspension>
#6      _FormBuilderDateTimePickerState._handleFocus
package:flutter_form_builder/…/fields/form_builder_date_time_picker.dart:271
<asynchronous suspension>```
@MattConflitti MattConflitti added the bug Something isn't working label Mar 26, 2023
@deandreamatias deandreamatias self-assigned this Apr 23, 2023
@MattConflitti
Copy link
Author

@deandreamatias Thanks for taking this up. Any ideas on what may be causing this issue?

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

Successfully merging a pull request may close this issue.

2 participants