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

Double Datepicker raised #46

Closed
sante85 opened this issue Jul 12, 2019 · 9 comments
Closed

Double Datepicker raised #46

sante85 opened this issue Jul 12, 2019 · 9 comments

Comments

@sante85
Copy link

sante85 commented Jul 12, 2019

DateTimePickerFormField(
firstDate: DateTime.now(),
inputType: InputType.date,
format: DateFormat('dd-MM-yyyy'),
editable: false,
validator: (DateTime value) {
if (value == null) {
return 'Data obbligatoria';
} else {
widget.orderDate = value;
}
},
decoration:
InputDecoration(labelText: 'Data *', hasFloatingPlaceholder: false),
);

this is raised two or many times at open.

@sante85
Copy link
Author

sante85 commented Jul 12, 2019

flutter > 1.5.4-hotfix.2

@NickCullen
Copy link

Can confirm this occurs in Flutter version 1.7.8+hotfix3

@NickCullen
Copy link

I have been doing some digging about & testing... It looks like the code is listening to changes on both the focus node and text controller so there are multiple entries to the function that opens the date picker. Here is the referenced code:

@override
  void initState() {
    super.initState();
    widget.focusNode.addListener(inputChanged);
    widget.controller.addListener(inputChanged);
  }

  @override
  void dispose() {
    widget.controller.removeListener(inputChanged);
    widget.focusNode.removeListener(inputChanged);
    super.dispose();
  }

  void inputChanged() {
    final bool requiresInput = widget.controller.text.isEmpty &&
        _previousValue.isEmpty &&
        widget.focusNode.hasFocus;

    if (requiresInput) {
      getDateTimeInput(context, widget.initialDate, widget.initialTime)
          .then(_setValue);
    } else if (widget.resetIcon != null &&
        widget.controller.text.isEmpty == showResetIcon) {
      setState(() => showResetIcon = !showResetIcon);
      // widget.focusNode.unfocus();
    }
    _previousValue = widget.controller.text;
    if (!widget.focusNode.hasFocus) {
      setValue(_toDate(_previousValue, widget.format));
    } else if (!requiresInput && !widget.editable) {
      var date = _toDate(_previousValue, widget.format);
      getDateTimeInput(context, date ?? widget.initialDate,
              _toTime(date) ?? widget.initialTime)
          .then(_setValue);
    }
  }

What is more interesting... If I waited before clicking on the datetime picker (by click I mean a fairly quick mouse down + mouse up) but after waiting ~3 seconds after closing the datepicker before starting again I could get it to replicate.

HOWEVER - this was only replicatable AFTER I had set a value AND AFTER I hit the reset icon (although this does throw an exception) :

I/flutter (15494): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (15494): The following assertion was thrown while handling a gesture:
I/flutter (15494): invalid text selection: TextSelection(baseOffset: 10, extentOffset: 10, affinity:
I/flutter (15494): TextAffinity.upstream, isDirectional: false)
I/flutter (15494):
I/flutter (15494): When the exception was thrown, this was the stack:
I/flutter (15494): #0      TextEditingController.selection= 
package:flutter/…/widgets/editable_text.dart:169
I/flutter (15494): #1      EditableTextState._handleSelectionChanged 
package:flutter/…/widgets/editable_text.dart:1216
I/flutter (15494): #2      RenderEditable._handlePotentialSelectionChange 
package:flutter/…/rendering/editable.dart:369
I/flutter (15494): #3      RenderEditable.selectPositionAt 
package:flutter/…/rendering/editable.dart:1416
I/flutter (15494): #4      RenderEditable.selectPosition 
package:flutter/…/rendering/editable.dart:1388
I/flutter (15494): #5      _TextFieldState._handleSingleTapUp 
package:flutter/…/material/text_field.dart:770
I/flutter (15494): #6      _TextSelectionGestureDetectorState._handleTapUp 
package:flutter/…/widgets/text_selection.dart:944
I/flutter (15494): #7      TapGestureRecognizer._checkUp.<anonymous closure> 
package:flutter/…/gestures/tap.dart:363
I/flutter (15494): #8      GestureRecognizer.invokeCallback 
package:flutter/…/gestures/recognizer.dart:182
I/flutter (15494): #9      TapGestureRecognizer._checkUp 
package:flutter/…/gestures/tap.dart:363
I/flutter (15494): #10     TapGestureRecognizer.acceptGesture 
package:flutter/…/gestures/tap.dart:312
I/flutter (15494): #11     _TransparentTapGestureRecognizer.rejectGesture 
package:flutter/…/widgets/text_selection.dart:1146
I/flutter (15494): #12     GestureArenaManager.sweep 
package:flutter/…/gestures/arena.dart:159
I/flutter (15494): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent 
package:flutter/…/gestures/binding.dart:222
I/flutter (15494): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent 
package:flutter/…/gestures/binding.dart:198
I/flutter (15494): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent 
package:flutter/…/gestures/binding.dart:156
I/flutter (15494): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue 
package:flutter/…/gestures/binding.dart:102
I/flutter (15494): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket 
package:flutter/…/gestures/binding.dart:86
I/flutter (15494): #21     _invoke1  (dart:ui/hooks.dart:250:10)
I/flutter (15494): #22     _dispatchPointerDataPacket  (dart:ui/hooks.dart:159:5)
I/flutter (15494): (elided 3 frames from package dart:async)
I/flutter (15494):
I/flutter (15494): Handler: "onTapUp"
I/flutter (15494): Recognizer:
I/flutter (15494):   _TransparentTapGestureRecognizer#1273d
I/flutter (15494): ════════════════════════════════════════════════════════════════════════════════════════════════════

Perhaps it is related to the exception? The widget may likely be in some broken state?

@sante85
Copy link
Author

sante85 commented Jul 14, 2019 via email

@sante85
Copy link
Author

sante85 commented Jul 14, 2019 via email

@sante85
Copy link
Author

sante85 commented Jul 14, 2019 via email

@jifalops
Copy link
Owner

This should be fixed in v0.3.0.

@sante85
Copy link
Author

sante85 commented Jul 15, 2019

Ok. When?

@sante85
Copy link
Author

sante85 commented Jul 15, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants