Last active
January 11, 2022 12:05
-
-
Save Metal-666/1900006f52e76806afca992088250bf6 to your computer and use it in GitHub Desktop.
Challenge 2 (setState)
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) => MaterialApp( | |
home: Scaffold(body: MyWidget()), | |
); | |
} | |
class MyWidgetState extends State<MyWidget> { | |
double scale = 1; | |
@override | |
Widget build(BuildContext context) => Stack(children: <Widget>[ | |
Center( | |
child: Transform.scale( | |
scale: scale, | |
child: Container( | |
width: 100, | |
height: 100, | |
color: Colors.yellow, | |
), | |
)), | |
Positioned( | |
bottom: 0, | |
left: 0, | |
right: 0, | |
child: Slider( | |
value: scale, | |
max: 2, | |
onChanged: (newValue) => setState(() => scale = newValue), | |
)) | |
]); | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => MyWidgetState(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment