Skip to content

Commit 1cc15be

Browse files
committed
wo hoo
1 parent 6fcaa3d commit 1cc15be

File tree

6 files changed

+88
-2
lines changed

6 files changed

+88
-2
lines changed

flutter_quiz_app/lib/main.dart

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ class _MyHomePageState extends State<MyHomePage> {
7070
child: CircularProgressIndicator(),
7171
);
7272
case ConnectionState.done:
73-
if(snapshot.hasError){
73+
if (snapshot.hasError) {
7474
return Container();
7575
}
76-
return Container(child: Text("Data arrtived"),);
76+
// return Container(child: Text("Data arrtived"),);
77+
return questionList();
7778
}
7879
return null;
7980
},
@@ -85,4 +86,89 @@ class _MyHomePageState extends State<MyHomePage> {
8586
), // This trailing comma makes auto-formatting nicer for build methods.
8687
);
8788
}
89+
90+
ListView questionList() {
91+
return ListView.builder(
92+
itemCount: results.length,
93+
itemBuilder: (context, index) => Card(
94+
color: Colors.white,
95+
elevation: 0.0,
96+
child: ExpansionTile(
97+
title: Column(
98+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
99+
crossAxisAlignment: CrossAxisAlignment.start,
100+
children: <Widget>[
101+
Text(
102+
results[index].question,
103+
style:
104+
TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
105+
),
106+
FittedBox(
107+
child: Row(
108+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
109+
children: <Widget>[
110+
FilterChip(
111+
backgroundColor: Colors.grey[100],
112+
label: Text(results[index].category),
113+
onSelected: (b) {}),
114+
SizedBox(
115+
width: 10.0,
116+
),
117+
FilterChip(
118+
backgroundColor: Colors.grey[100],
119+
label: Text(results[index].difficulty),
120+
onSelected: (b) {})
121+
],
122+
),
123+
)
124+
],
125+
),
126+
leading: CircleAvatar(
127+
backgroundColor: Colors.grey[100],
128+
child: Text(results[index].type.startsWith("m") ? "M" : "B"),
129+
),
130+
children: results[index].incorrectAnswers.map((m) {
131+
return AnswerWidget(results, index, m);
132+
}).toList(),
133+
),
134+
),
135+
);
136+
}
137+
}
138+
139+
class AnswerWidget extends StatefulWidget {
140+
final List<Results> _results;
141+
final int index;
142+
final String m;
143+
144+
AnswerWidget(this._results, this.index, this.m);
145+
146+
@override
147+
State<StatefulWidget> createState() => _AnswerWidgetState();
148+
}
149+
150+
class _AnswerWidgetState extends State<AnswerWidget> {
151+
Color c = Colors.black;
152+
153+
@override
154+
Widget build(BuildContext context) {
155+
// TODO: implement build
156+
return ListTile(
157+
onTap: () {
158+
setState(() {
159+
if (widget.m == widget._results[widget.index].correctAnswer) {
160+
c = Colors.green;
161+
} else {
162+
c = Colors.red;
163+
}
164+
});
165+
},
166+
title: Text(
167+
168+
widget.m,
169+
textAlign: TextAlign.center,
170+
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
171+
),
172+
);
173+
}
88174
}
218 KB
Loading
173 KB
Loading
188 KB
Loading
193 KB
Loading
149 KB
Loading

0 commit comments

Comments
 (0)