Open stargazing-dino opened 3 years ago
Hi, nice library! I wish we found it a week ago, we've just published something very similar (https://pub.dev/packages/progress_builder) but we did take a slightly different approach.
Perhaps we can exchange ideas.
I was thinking about supporting multiple actions as well, but I guess then it would make more sense to use a Cubit or Bloc, as you get more complexity you may not want to have inside your UI.
Nice work though!
Thanks ! Of course, I'd be happy to share ideas.
Concerning needing a more complicated state management, I feel as though this package shouldn't obstruct anyone from doing that on their side. This package so far is only concerned in moving UI around so I personally don't feel as I need anything more than setState
under the hood.
As for the issue, from inkwell there are a lot of pointer events to possibly account for:
GestureTapCallback? onTap,
GestureTapCallback? onDoubleTap,
GestureLongPressCallback? onLongPress,
GestureTapDownCallback? onTapDown,
GestureTapCancelCallback? onTapCancel,
ValueChanged<bool>? onHighlightChanged,
ValueChanged<bool>? onHover,
I wonder where I draw the line. Personally would not consider anything after onTapDown
. This reminded me however that we might be able to do something similar with nested builders to get the same functionality:
AsyncButtonBuilder(
child: Text('Click Me'),
onPressed: () async {
// for presses
await Future.delayed(Duration(seconds: 1));
},
builder: (context, child, onPressed, _) {
return AsyncButtonBuilder(
child: child,
onPressed: () async {
// for long pressed
await Future.delayed(Duration(seconds: 1));
},
builder: (context, child, longPressed, _) {
return TextButton(
child: child,
onPressed: onPressed,
onLongPress: longPressed,
);
},
);
},
),
I would rename onPressed
to callback
to be generic but that looks reasonable. I'm still favoring adding new properties though instead of nesting which inevitably leads to a MultiProvider
kind of situation and I don't think that's possibly for function types. Talking about builders I just had the realization this whole package could be a nifty hook
as well.
final buttonHandler = useAsyncButton(myCallback, child);
// Then add these to the UI
// buttonHandler.child
// buttonHandler.callback
I could add more parameters, but then the function signature would change on the builder which is breaking. I could also make a class to hold all the various types of taps but that's also breaking:
Dunno.
Another non-breaking option would to make a factory version with all the different types of presses. Not really the cleanest solution though.