Skip to content

Instantly share code, notes, and snippets.

@Metal-666
Last active January 11, 2022 12:05
Show Gist options
  • Save Metal-666/1900006f52e76806afca992088250bf6 to your computer and use it in GitHub Desktop.
Save Metal-666/1900006f52e76806afca992088250bf6 to your computer and use it in GitHub Desktop.
Challenge 2 (setState)
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