Skip to content

Commit 59eea51

Browse files
committed
done!
1 parent 1cc15be commit 59eea51

File tree

3 files changed

+90
-57
lines changed

3 files changed

+90
-57
lines changed

flutter_quiz_app/lib/main.dart

Lines changed: 90 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -58,78 +58,110 @@ class _MyHomePageState extends State<MyHomePage> {
5858
title: Text("Quiz App"),
5959
elevation: 0.0,
6060
),
61-
body: FutureBuilder(
62-
future: fecthQuestions(),
63-
builder: (BuildContext context, AsyncSnapshot snapshot) {
64-
switch (snapshot.connectionState) {
65-
case ConnectionState.none:
66-
return Text("Press button to start");
67-
case ConnectionState.active:
68-
case ConnectionState.waiting:
69-
return Center(
70-
child: CircularProgressIndicator(),
71-
);
72-
case ConnectionState.done:
73-
if (snapshot.hasError) {
74-
return Container();
75-
}
61+
body: RefreshIndicator(
62+
onRefresh: fecthQuestions,
63+
child: FutureBuilder(
64+
future: fecthQuestions(),
65+
builder: (BuildContext context, AsyncSnapshot snapshot) {
66+
switch (snapshot.connectionState) {
67+
case ConnectionState.none:
68+
return Text("Press button to start");
69+
case ConnectionState.active:
70+
case ConnectionState.waiting:
71+
return Center(
72+
child: CircularProgressIndicator(),
73+
);
74+
case ConnectionState.done:
75+
if (snapshot.hasError) {
76+
return errorData(snapshot);
77+
}
7678
// return Container(child: Text("Data arrtived"),);
77-
return questionList();
78-
}
79-
return null;
80-
},
79+
return questionList();
80+
}
81+
return null;
82+
},
83+
),
8184
),
8285
floatingActionButton: FloatingActionButton(
8386
onPressed: _incrementCounter,
8487
tooltip: 'Increment',
85-
child: Icon(Icons.add),
88+
child: Icon(Icons.refresh),
8689
), // This trailing comma makes auto-formatting nicer for build methods.
8790
);
8891
}
92+
93+
Padding errorData(AsyncSnapshot snapshot){
94+
return Padding(
95+
padding: const EdgeInsets.all(12.0),
96+
child: Column(
97+
mainAxisAlignment: MainAxisAlignment.center,
98+
children: <Widget>[
99+
Text("Error : ${snapshot.error}"),
100+
SizedBox(height: 20.0,),
101+
RaisedButton(
102+
onPressed: (){
103+
fecthQuestions();
104+
setState(() {
105+
106+
});
107+
},
108+
child: Text("Try Again"),
109+
)
110+
],
111+
),
112+
);
113+
}
89114

90115
ListView questionList() {
91116
return ListView.builder(
92117
itemCount: results.length,
93118
itemBuilder: (context, index) => Card(
94119
color: Colors.white,
95120
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-
],
121+
child: Padding(
122+
padding: const EdgeInsets.all(18.0),
123+
child: ExpansionTile(
124+
title: Column(
125+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
126+
crossAxisAlignment: CrossAxisAlignment.start,
127+
children: <Widget>[
128+
Text(
129+
results[index].question,
130+
style:
131+
TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
122132
),
123-
)
124-
],
125-
),
126-
leading: CircleAvatar(
127-
backgroundColor: Colors.grey[100],
128-
child: Text(results[index].type.startsWith("m") ? "M" : "B"),
133+
FittedBox(
134+
child: Row(
135+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
136+
children: <Widget>[
137+
FilterChip(
138+
backgroundColor: Colors.grey[100],
139+
label: Text(results[index].category),
140+
onSelected: (b) {}),
141+
SizedBox(
142+
width: 10.0,
143+
),
144+
FilterChip(
145+
backgroundColor: Colors.grey[100],
146+
label: Text(results[index].difficulty),
147+
onSelected: (b) {})
148+
],
149+
),
150+
)
151+
],
152+
),
153+
154+
leading: Padding(
155+
padding: const EdgeInsets.all(8.0),
156+
child: CircleAvatar(
157+
backgroundColor: Colors.grey[100],
158+
child: Text(results[index].type.startsWith("m") ? "M" : "B"),
159+
),
160+
),
161+
children: results[index].incorrectAnswers.map((m) {
162+
return AnswerWidget(results, index, m);
163+
}).toList(),
129164
),
130-
children: results[index].incorrectAnswers.map((m) {
131-
return AnswerWidget(results, index, m);
132-
}).toList(),
133165
),
134166
),
135167
);
@@ -164,10 +196,11 @@ class _AnswerWidgetState extends State<AnswerWidget> {
164196
});
165197
},
166198
title: Text(
167-
168199
widget.m,
169200
textAlign: TextAlign.center,
170-
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
201+
style: TextStyle(
202+
color: c,
203+
fontWeight: FontWeight.bold),
171204
),
172205
);
173206
}
148 KB
Loading
144 KB
Loading

0 commit comments

Comments
 (0)