-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathmain.dart
110 lines (103 loc) · 4.05 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'package:flutter/material.dart';
import 'story_brain.dart';
//TODO: Step 15 - Run the app and see if you can see the screen update with the first story. Delete this TODO if it looks as you expected.
void main() => runApp(Destini());
class Destini extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: StoryPage(),
);
}
}
//TODO: Step 9 - Create a new storyBrain object from the StoryBrain class.
StoryBrain storyBrain = StoryBrain();
class StoryPage extends StatefulWidget {
_StoryPageState createState() => _StoryPageState();
}
class _StoryPageState extends State<StoryPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/background.png'),
fit: BoxFit.cover,
),
),
padding: EdgeInsets.symmetric(vertical: 50.0, horizontal: 15.0),
constraints: BoxConstraints.expand(),
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 12,
child: Center(
child: Text(
//TODO: Step 10 - use the storyBrain to get the first story title and display it in this Text Widget.
storyBrain.getStory(),
style: TextStyle(
fontSize: 25.0,
),
),
),
),
Expanded(
flex: 2,
child: FlatButton(
onPressed: () {
//Choice 1 made by user.
//TODO: Step 18 - Call the nextStory() method from storyBrain and pass the number 1 as the choice made by the user.
//TODO: Step 24 - Run the app and try to figure out what code you need to add to this file to make the story change when you press on the choice buttons.
setState(() {
storyBrain.nextStory(1);
});
},
color: Colors.red,
child: Text(
//TODO: Step 13 - Use the storyBrain to get the text for choice 1.
storyBrain.getChoice1(),
style: TextStyle(
fontSize: 20.0,
),
),
),
),
SizedBox(
height: 20.0,
),
Expanded(
flex: 2,
//TODO: Step 26 - Use a Flutter Visibility Widget to wrap this FlatButton.
//TODO: Step 28 - Set the "visible" property of the Visibility Widget to equal the output from the buttonShouldBeVisible() method in the storyBrain.
child: Visibility(
visible: storyBrain.buttonShouldBeVisible(),
child: FlatButton(
onPressed: () {
//Choice 2 made by user.
//TODO: Step 19 - Call the nextStory() method from storyBrain and pass the number 2 as the choice made by the user.
setState(() {
storyBrain.nextStory(2);
});
},
color: Colors.blue,
child: Text(
//TODO: Step 14 - Use the storyBrain to get the text for choice 2.
storyBrain.getChoice2(),
style: TextStyle(
fontSize: 20.0,
),
),
),
),
),
],
),
),
),
);
}
}
//TODO: Step 29 - Run the app and test it against the Story Outline to make sure you've completed all the steps. The code for the completed app can be found here: https://github.com/londonappbrewery/destini-challenge-completed/