Created
August 30, 2020 06:14
-
-
Save vignarajj/30e86fddf5d8ddd9697e3c42518503d4 to your computer and use it in GitHub Desktop.
Ignore Pointer and Absorb Pointer Example
This file contains 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(MyPointerExample()); | |
} | |
class MyPointerExample extends StatefulWidget { | |
@override | |
_MyPointerExampleState createState() => _MyPointerExampleState(); | |
} | |
class _MyPointerExampleState extends State<MyPointerExample> { | |
bool _ignoring = false; | |
bool _absorbing = false; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "Pointer Example", | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Pointers Example'), | |
), | |
body: Container( | |
child: Column( | |
children: [ | |
IgnorePointer( | |
ignoring: _ignoring, | |
child: FlatButton( | |
child: Text('Click me'), | |
onPressed: () { | |
Scaffold.of(context).showSnackBar( | |
SnackBar(content: Text("you pressed me..")), | |
); | |
}, | |
), | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Want to Ignore the button?'), | |
Switch( | |
value: _ignoring, | |
onChanged: (bool value) { | |
setState(() { | |
_ignoring = value; | |
}); | |
}), | |
], | |
), | |
AbsorbPointer( | |
absorbing: _absorbing, | |
child: FlatButton( | |
child: Text('Press me'), | |
onPressed: () { | |
Scaffold.of(context).showSnackBar( | |
SnackBar(content: Text("you pressed me..")), | |
); | |
}, | |
), | |
), | |
Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('Want to absorb the button?'), | |
Switch( | |
value: _absorbing, | |
onChanged: (bool value) { | |
setState(() { | |
_absorbing = value; | |
}); | |
}), | |
], | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment