Skip to content

Instantly share code, notes, and snippets.

@ericorruption
Created February 21, 2020 08:51
Show Gist options
  • Save ericorruption/c9689b40a5402e12538c726b5c0380ff to your computer and use it in GitHub Desktop.
Save ericorruption/c9689b40a5402e12538c726b5c0380ff to your computer and use it in GitHub Desktop.
Gesture detector around button
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Assessment Documents Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: GenericTappableWidget(
onTap: () {
print('parent ontap');
},
child: RaisedButton.icon(
onPressed: () {},
label: Text('Test'),
icon: Icon(Icons.add),
),
)),
),
);
}
}
class GenericTappableWidget extends StatelessWidget {
final Widget child;
final Function() onTap;
GenericTappableWidget({@required this.child, @required this.onTap});
@override
Widget build(BuildContext context) {
return GestureDetector(
child: child,
onTap: () {
print('tap');
onTap();
},
onTapCancel: () {
print('tapCancel');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment