malikwang / expand_tap_area

Manually expand the tap area of a widget without changing its size or layout. Similar with the hitTest in iOS development.
MIT License
38 stars 5 forks source link

Ontap stops responding after setState #3

Open sidetraxaudio opened 2 years ago

sidetraxaudio commented 2 years ago

Great widget however I've experienced a problem:

I have an app-wide generic button utilising expand_tap_area. It works in all situations except this:

OnTap() calls SetState to change the size of some screen elements. It changes the icon for the button pressed and also changes the size of a container. Basically it's being used to change its own icon when pressed (on selected) and also expand a text box container to show more text.

The problem is that Ontap works the first time and does not work again. Swapping out for a gesture detector works fine.

` ShadedIconBtn( icon: (isExpanded) ? FontAwesomeIcons.arrowCircleUp : FontAwesomeIcons.arrowCircleDown,

      onPressed: () {
        setState(() {
          isExpanded=!isExpanded;
          print('************************ BUTTON PRESSED');
        });
      },`

Print call also doesn't respond after it's pressed once. If I remove isExpanded bool that affects the rest of the screen elements and the screen doesn't change then the Print statement DOES work as expected.

As mentioned gesture detector works fine.

malikwang commented 2 years ago

Great widget however I've experienced a problem:

I have an app-wide generic button utilising expand_tap_area. It works in all situations except this:

OnTap() calls SetState to change the size of some screen elements. It changes the icon for the button pressed and also changes the size of a container. Basically it's being used to change its own icon when pressed (on selected) and also expand a text box container to show more text.

The problem is that Ontap works the first time and does not work again. Swapping out for a gesture detector works fine.

` ShadedIconBtn( icon: (isExpanded) ? FontAwesomeIcons.arrowCircleUp : FontAwesomeIcons.arrowCircleDown,

      onPressed: () {
        setState(() {
          isExpanded=!isExpanded;
          print('************************ BUTTON PRESSED');
        });
      },`

Print call also doesn't respond after it's pressed once. If I remove isExpanded bool that affects the rest of the screen elements and the screen doesn't change then the Print statement DOES work as expected.

As mentioned gesture detector works fine.

plz paste the key snippet of 'generic button' to debug this problem

kameshWB commented 11 months ago

@sidetraxaudio use UniqueKey() to force rebuild the widget and that will update the new changes in your onTap method.

example image

@malikwang Thank you so much, This is a very nice package. But this issues needs to be fixed, I was using this widget in many places and everywhere I was passing UniqueKey() to see my latest onTap changes.

DaggeDaggmask commented 10 months ago

@kameshWB @sidetraxaudio @malikwang you can copy the entire file in lib/src and modify the file to work with onTap. Add this to the ExpandTapWidget under createRenderObject.

  @override
  void updateRenderObject(BuildContext context, covariant _ExpandTapRenderBox renderObject) {
    renderObject
      ..onTap = onTap
      ..tapPadding = tapPadding;
  }

onTap and tapPadding needs to be change to non-final variables in _ExpandTapRenderBox Hope this helps.