adar2378 / pin_code_fields

A flutter package which will help you to generate pin code fields with beautiful design and animations. Can be useful for OTP or pin code inputs 🤓🤓
https://pub.dev/packages/pin_code_fields
MIT License
690 stars 336 forks source link

Assertion failure: Looking up a deactivated widget's ancestor is unsafe. #296

Closed cjwhitsitt closed 1 year ago

cjwhitsitt commented 1 year ago

The following log message seems to happen any time a character is entered in a field. I'm using pin_code_fields: ^7.4.0.

======== Exception caught by widgets library =======================================================
The following assertion was thrown while dispatching notifications for FocusManager:
Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

When the exception was thrown, this was the stack: 
#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:4241:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:4255:6)
#2      Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:4275:12)
#3      MediaQuery.maybeOf (package:flutter/src/widgets/media_query.dart:922:20)
#4      _InkResponseState._shouldShowFocus (package:flutter/src/material/ink_well.dart:997:44)
#5      _InkResponseState.updateFocusHighlights (package:flutter/src/material/ink_well.dart:1013:21)
#6      _InkResponseState.handleFocusHighlightModeChange.<anonymous closure> (package:flutter/src/material/ink_well.dart:992:7)
#7      State.setState (package:flutter/src/widgets/framework.dart:1114:30)
#8      _InkResponseState.handleFocusHighlightModeChange (package:flutter/src/material/ink_well.dart:991:5)
#9      FocusManager._notifyHighlightModeListeners (package:flutter/src/widgets/focus_manager.dart:1607:19)
#10     FocusManager._updateHighlightMode (package:flutter/src/widgets/focus_manager.dart:1583:7)
#11     FocusManager._handleKeyMessage (package:flutter/src/widgets/focus_manager.dart:1663:5)
#12     KeyEventManager._dispatchKeyMessage (package:flutter/src/services/hardware_keyboard.dart:824:34)
#13     KeyEventManager.handleRawKeyMessage (package:flutter/src/services/hardware_keyboard.dart:889:17)
#14     BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:197:49)
#15     _DefaultBinaryMessenger.setMessageHandler.<anonymous closure> (package:flutter/src/services/binding.dart:387:35)
#16     _invoke2 (dart:ui/hooks.dart:186:13)
#17     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#18     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#19     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#20     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:599:22)
#21     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)
The FocusManager sending notification was: FocusManager#4ca5d
  primaryFocus: FocusNode#6ca59([PRIMARY FOCUS])
  primaryFocusCreator: Focus ← _ActionsMarker ← Actions ← _TextEditingHistory ← _ActionsMarker ← Actions ← MouseRegion ← EditableText-[LabeledGlobalKey<EditableTextState>#981ae] ← UnmanagedRestorationScope ← RepaintBoundary ← _Decorator ← InputDecorator ← AnimatedBuilder ← Listener ← RawGestureDetector ← TextSelectionGestureDetector ← Semantics ← AnimatedBuilder ← IgnorePointer ← MouseRegion ← ⋯
====================================================================================================

My widget instantiation:

    var textField = PinCodeTextField(
      appContext: context,
      animationType: AnimationType.fade,
      autoDisposeControllers: false,
      autoFocus: true,
      beforeTextPaste: (value) {
        return value != null && value.length == 4;
      },
      controller: _textEditingController,
      cursorColor: Theme.of(context).colorScheme.secondary,
      inputFormatters: [_UpperCaseTextFormatter()],
      length: Configuration.instance.shortCodeLength,
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      pinTheme: PinTheme(
        activeColor: Theme.of(context).colorScheme.onBackground,
        inactiveColor: Theme.of(context).colorScheme.onBackground,
        selectedColor: Theme.of(context).colorScheme.onBackground,
        fieldHeight: height * 1.5,
      ),
      textCapitalization: TextCapitalization.characters,
      textStyle: Theme.of(context).textTheme.displayMedium,
      onChanged: (_) {},
      onSubmitted: (value) => _submit(value, context: context),
      onCompleted: (value) => _submit(value, context: context),
    );
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.