@Ivo's comment, in my question, provided me with a solution in which:
the user-provided callback takes a context
parameter, e.g. void myOnTap(BuildContext context){ ... }
You do not pass directly this callback to each basic Widget's onTap
property but you provide it like this: onTap: (){ myOnTap(context); }
(and context
is now available as we are inside a build()
method).
For example,
// untested pseudocode
class MyComplexWidget extends StatelessWidget {
final void Function(BuildContext)? onTapForA;
final void Function(BuildContext)? onTapForB;
const MyComplexWidget({super.key, this.onTapForA, this.onTapForB});
@override
build(BuildContext context) {
return Column(children: [
InkWell( // basic widget A
...
onTap: () {
onTapForA!(context);
},
),
InkWell( // basic widget B
...
onTap: () {
onTapForB!(context);
},
)
]);
} // build
}
Thank you for your help