-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
We have a good API to handle tap outside events (TapRegion/TapRegionSurface) in Flutter and we even have onTapOutside on TextField but we have no ability to change the default logic of onTapOutside for the whole app or scope.
Current default logic bases on platform and follows default platform behavior. If I want to change it globally I have to set a custom onTapOutside for every TextField(which is a bit redundant for such a simple task) but if I am using external library with UI (like firebase_ui_auth) I am not able to change onTapOutside logic.
We have very similar situation for ScrollPhysics where we have a default per platform behaviour and we have physics on every Scrollable but we also let to configure default physics for the whole app or scope using ScrollConfiguration.
Proposal
My proposition is to create TapOutsideConfiguration where you can define a custom default logic for `onTapOutside.
TapOutsideConfiguration(
behavior: AlwaysUnfocusTapOutsideBehavior(),
// behavior: const NeverUnfocusTapOutsideBehavior(),
// behavior: const CustomTapOutsideBehavior(),
child: Column(
children: [
// This TextField will use onTapOutside from TapOutsideConfiguration
TextField(),
// Of course you can still define onTapOutside
TextField(onTapOutside: (event) => print('Tapped outside')),
],
),
)We can add 2 simple behaviors like AlwaysUnfocusTapOutsideBehavior and NeverUnfocusTapOutsideBehavior and let devs to define own custom logic like this:
class CustomTapOutsideBehavior extends TapOutsideBehavior {
const CustomTapOutsideBehavior();
@override
void defaultOnTapOutside(PointerDownEvent event, FocusNode focusNode) {
// any custom logic here
}
}