Last active
March 17, 2019 15:28
-
-
Save boeledi/5042284c4d7e037f794275943db94b29 to your computer and use it in GitHub Desktop.
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( | |
MaterialApp( | |
home: ApplicationSample(), | |
), | |
); | |
} | |
class ApplicationSample extends StatefulWidget { | |
@override | |
_ApplicationSampleState createState() => _ApplicationSampleState(); | |
} | |
class _ApplicationSampleState extends State<ApplicationSample> { | |
final Key _keyGesture = Key("MyFakeButton"); | |
bool _isOn = false; | |
@override | |
Widget build(BuildContext context) { | |
return Material( | |
child: Center( | |
child: Stack( | |
alignment: Alignment.center, | |
children: <Widget>[ | |
_isOn ? ChildOn() : ChildOff(), | |
GestureDetector( | |
key: _keyGesture, | |
onTap: (){ | |
setState((){ | |
_isOn = !_isOn; | |
}); | |
}, | |
child: const Icon(Icons.swap_horizontal_circle), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class ChildOn extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 150.0, | |
height: 150.0, | |
color: Colors.green, | |
); | |
} | |
} | |
class ChildOff extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: 100.0, | |
height: 100.0, | |
color: Colors.red, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment