Skip to content

Instantly share code, notes, and snippets.

@boeledi
Last active March 17, 2019 15:28
Show Gist options
  • Save boeledi/5042284c4d7e037f794275943db94b29 to your computer and use it in GitHub Desktop.
Save boeledi/5042284c4d7e037f794275943db94b29 to your computer and use it in GitHub Desktop.
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