GotJimmy / accordion

Other
46 stars 43 forks source link

Widgets inside a closed section still getting the focus ! #30

Closed nassimus26 closed 1 year ago

nassimus26 commented 2 years ago

Hi, when a section is closed all the widgets which have a Keyboard listener still get the focus, How to disable it ? I try this :

class AccordionSection extends StatelessWidget with CommonParams {
  final SectionController sectionCtrl = SectionController();
  late final UniqueKey uniqueKey;
  late final int index;
  final bool isOpen;
.....
  AccordionSection({
    Key? key,
    this.index = 0,
    this.isOpen = false,
.........
  @override
  build(context) {
    final borderRadius = headerBorderRadius ?? 10;
    return Obx(
      () => Column(
        key: uniqueKey,
     ........
                            child: Center(
my change  >>>>>>>>>>>             child: AbsorbPointer( absorbing: !_isOpen, child: content ),
......
}

But it's not working, how to disable the focus for all the widget inside a closed section ?

And I have another observation, the Event onClose is called only if the section is closed by the User, but never when the section is closed after the max opened section is reached.

GotJimmy commented 2 years ago

1) I think you can find the answer here: https://stackoverflow.com/questions/53481261/how-to-unfocus-textfield-that-has-custom-focusnode

2) ok, I'll take care of this in the next version.

nassimus26 commented 2 years ago

After trying with !_isOpen I tried with fixed value TRUE:

AbsorbPointer( absorbing:TRUE, child: content ) And I figure that the AbsorbPointerhandle only the mouse events not the keyboard event, so thats why the Widgets still continue to get the Focus,

And thanks, I will check if it could help me

I open a stackoverflow question : https://stackoverflow.com/questions/72983549/how-to-prevent-children-from-getting-focus-when-using-keyboard-events

nassimus26 commented 2 years ago

I read the link that you put in the second comment, I don't see how it could help, a closed section should automatically disable all the keyboard events for it's children, and the post is talking about how to unfocus just one field !

GotJimmy commented 2 years ago

Only one field can be focused. I'll see in the next version if this can be done automatically by Accordion. But please don't count on it and the next version won't be out anytime soon.

nassimus26 commented 2 years ago

I understand, but if only the onClose event works correctly maybe I could done it manually, but since the onClose occured only when the user close the section, and not when the secion is closed (when the max is reached for example), it makes hard to do it makes impossible to do it manualy, there's no way to know when the secion is closed.

nassimus26 commented 2 years ago

And maybe you didn't understand the need, I don't need to unfocus the children, I need them to not get the focus at all , for example with the skipTraversalproperty of the FocusManager

nassimus26 commented 2 years ago

Hi again, I just fixed the Close Open events with :

listCtrl.controllerIsOpen.stream.asBroadcastStream().listen((data) {
      var open = listCtrl.openSections.contains(key);
      var prevOpen = sectionCtrl.isSectionOpen.value;
      if (prevOpen && !open) {
        if (onCloseSection != null) onCloseSection!.call();
      } else if (!prevOpen && open) {
        if (onOpenSection != null) onOpenSection!.call();
      }
      sectionCtrl.isSectionOpen.value = open;
    });

No need for this in the Tapevent

              if (_isOpen) {
                //if (onCloseSection != null) onCloseSection!.call();
              } else {
                //if (onOpenSection != null) onOpenSection!.call();
              }

Now maybe I have a chance to solve it manually

GotJimmy commented 2 years ago

Ok, I'll have a look at that soon. Thanks.