Created
January 13, 2020 18:18
-
-
Save av/c546e935cd28056efcf7c4e88b162306 to your computer and use it in GitHub Desktop.
Flutter: neu
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
| // Converting NeumorphicContainer to a StatefulWidget | |
| class NeumorphicContainer extends StatefulWidget { | |
| final Widget child; | |
| final double bevel; | |
| final Offset blurOffset; | |
| final Color color; | |
| NeumorphicContainer({ | |
| Key key, | |
| this.child, | |
| this.bevel = 10.0, | |
| this.color, | |
| }) : this.blurOffset = Offset(bevel / 2, bevel / 2), | |
| super(key: key); | |
| @override | |
| _NeumorphicContainerState createState() => _NeumorphicContainerState(); | |
| } | |
| class _NeumorphicContainerState extends State<NeumorphicContainer> { | |
| // New state, representing if surface is being pressed | |
| bool _isPressed = false; | |
| // We're only really interested in down and up events, | |
| // for now. | |
| void _onPointerDown(PointerDownEvent event) { | |
| setState(() { | |
| _isPressed = true; | |
| }); | |
| } | |
| void _onPointerUp(PointerUpEvent event) { | |
| setState(() { | |
| _isPressed = false; | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| final color = this.widget.color ?? Theme.of(context).backgroundColor; | |
| // Listener is almost like GestureDetector, | |
| // just a bit simpler | |
| return Listener( | |
| onPointerDown: _onPointerDown, | |
| onPointerUp: _onPointerUp, | |
| child: Container(...), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment