Created
February 21, 2020 08:51
-
-
Save ericorruption/c9689b40a5402e12538c726b5c0380ff to your computer and use it in GitHub Desktop.
Gesture detector around button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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