Skip to content

Instantly share code, notes, and snippets.

@ybakos
Last active February 4, 2020 19:28
Show Gist options
  • Select an option

  • Save ybakos/680d344f9c57a9e7a0773a574492cfa6 to your computer and use it in GitHub Desktop.

Select an option

Save ybakos/680d344f9c57a9e7a0773a574492cfa6 to your computer and use it in GitHub Desktop.
CS 492 Week 6 Exploration 3 Exercise
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WaxOnWaxOff()
),
);
}
}
class WaxOnWaxOff extends StatefulWidget {
@override
State createState() => WaxOnWaxOffState();
}
class WaxOnWaxOffState extends State<WaxOnWaxOff> {
String buttonText = 'There is only way...';
@override
Widget build(BuildContext context) {
return Center(
// FIXME: Why isn't the button label changing?
child: RaisedButton(
onPressed: showTruth,
child: Text(buttonText)
)
);
}
void showTruth() {
buttonText = 'Wax on, wax off!';
}
}
// TODO: No, you do not "got this." Prove it with practice.
// Implement four StatefulWidget & State pairs using
// Fee, Fi, Fo and Fum, or names that you choose.
// Can you implement them *without looking* at other code
// or references? You need to be able to do this from
// memory. No copy-paste! *Type from scratch.*
// Be sure to run this DartPad and check the Console for
// errors.
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: WaxOnWaxOff()
),
);
}
}
class WaxOnWaxOff extends StatefulWidget {
@override
State createState() => WaxOnWaxOffState();
}
class WaxOnWaxOffState extends State<WaxOnWaxOff> {
String buttonText = 'There is only way...';
@override
Widget build(BuildContext context) {
return Center(
child: RaisedButton(
onPressed: showTruth,
child: Text(buttonText)
)
);
}
// FIXED: wrap the state change in a call to setState
void showTruth() {
setState( () {
buttonText = 'Wax on, wax off!';
});
}
}
// Ah, now you've got it.
class Fee extends StatefulWidget {
@override
State createState() => FeeState();
}
class FeeState extends State<Fee> {
// State here
@override
Widget build(BuildContext context) {
return Text('FeeState');
}
}
class Fi extends StatefulWidget {
@override
State createState() => FiState();
}
class FiState extends State<Fi> {
// State here
@override
Widget build(BuildContext context) {
return Text('FiState');
}
}
class Fo extends StatefulWidget {
@override
State createState() => FoState();
}
class FoState extends State<Fo> {
// State here
@override
Widget build(BuildContext context) {
return Text('FoState');
}
}
class Funk extends StatefulWidget {
@override
State createState() => FunkState();
}
class FunkState extends State<Funk> {
// State here
@override
Widget build(BuildContext context) {
return Text('FunkState');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment