jesusrp98 / expand_widget

Ability to easily expand and retract a widget collection or text
https://pub.dev/packages/expand_widget
GNU General Public License v3.0
45 stars 22 forks source link

Use custom widget in place of text or icon #23

Closed mtkgeek closed 3 years ago

mtkgeek commented 3 years ago

Hi, great package. Is there a way i can use a widget like a button as my tap widget instead of just a text and/or an icon?

jesusrp98 commented 3 years ago

This could be a pretty cool new feature added to this package, but it will require a significant rewrite of the whole thing. Maybe I'll have some time to do this, but I'm open to PRs :)

JamesMcIntosh commented 3 years ago

There are a couple of ways you could do it which may not be that invasive:

  1. Extract a method from buildChilden which becomes public API that you can override i.e. createArrowWidget(BuildContext context) expand_text.dart#L209.
  2. Add a Builder as a parameter to ExpandText. The builder accepts the ExpandText widget so you can read it's state, anything else needs to remain internal such as onTap can be passed in as parameters to the function too. i.e.
    typedef ExpandOnTap = void Function([DragEndDetails? dragDetails])
    typedef ExpandWidgetBuilder = Widget Function(BuildContext context, ExpandText widget, ExpandOnTap onTap)

    When building my own classes I tend to use 1 when I have full control of what could be changing in the super classes. For a library it's better to use 2 to give you more control over what becomes API and is easier to implement for an end user.

jesusrp98 commented 3 years ago

Hey! This makes sense and you guidelines @JamesMcIntosh looks cool, I'll take a look a this in the coming days!

jesusrp98 commented 3 years ago

So the final solution is ready @JamesMcIntosh ! I've added a new IndicatorBuilder typedef which you can use to build your own indicator. The VoidCallback is the interal onTap method, and the bool tell you if the widget is on 'expanded` mode or not.

typedef IndicatorBuilder = Widget Function(
  BuildContext,
  VoidCallback,
  bool,
);

You can now pass a new argument to both 'expand' wigdets, called indicatorBuilder. This new widget will replace the default expansion arrow.

indicatorBuilder: (context, onTap, expanded) => InkWell(
  child: FlutterLogo(
    style: expanded
        ? FlutterLogoStyle.horizontal
        : FlutterLogoStyle.stacked,
    size: 50,
  ),
  onTap: onTap,
),

I think this is the best way of bring to developers the ability to construct the best indicator they can, and by maintaining the ease of use and stability this package offers today.

If you have any feedback on this, please let me know!

JamesMcIntosh commented 3 years ago

Nice and clean!

I think I suggested having the widget/state as part of the type because you may wish to access these: collapsedHint, expandedHint, arrowPadding, arrowColor, arrowSize, icon, hintTextStyle, expandArrowStyle, capitalArrowtext If you're making the statement that these are not needed when creating a custom widget, which looks to be sensible, then it's all good.