Start Abschnitt 4: Debugging Flutter Apps
parent
57b71432f8
commit
3084187ff1
@ -1,6 +1,7 @@
|
||||
import 'package:adv_basics/quiz.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adv_basics/quiz.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const Quiz());
|
||||
}
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
class QuestionsSummary extends StatelessWidget {
|
||||
const QuestionsSummary(this.summaryData, {super.key});
|
||||
|
||||
final List<Map<String, Object>> summaryData;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: summaryData.map(
|
||||
(data) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 15,
|
||||
backgroundColor:
|
||||
(data['correct_answer'] == data['user_answer'])
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
child: Center(
|
||||
child: Text(
|
||||
((data['question_index'] as int) + 1).toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
data['question'] as String,
|
||||
style: GoogleFonts.lato(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(
|
||||
data['user_answer'] as String,
|
||||
style: GoogleFonts.lato(
|
||||
color: Color.fromARGB(255, 201, 153, 251),
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
Text(
|
||||
data['correct_answer'] as String,
|
||||
style: GoogleFonts.lato(
|
||||
color:
|
||||
(data['correct_answer'] == data['user_answer'])
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class QuestionIdentifier extends StatelessWidget {
|
||||
const QuestionIdentifier({
|
||||
super.key,
|
||||
required this.isCorrectAnswer,
|
||||
required this.questionIndex,
|
||||
});
|
||||
|
||||
final int questionIndex;
|
||||
final bool isCorrectAnswer;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final questionNumber = questionIndex + 1;
|
||||
return Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: isCorrectAnswer
|
||||
? const Color.fromARGB(255, 150, 198, 241)
|
||||
: const Color.fromARGB(255, 249, 133, 241),
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
),
|
||||
child: Text(
|
||||
questionNumber.toString(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color.fromARGB(255, 22, 2, 56),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adv_basics/questions_summary/summary_item.dart';
|
||||
|
||||
class QuestionsSummary extends StatelessWidget {
|
||||
const QuestionsSummary(this.summaryData, {super.key});
|
||||
|
||||
final List<Map<String, Object>> summaryData;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 400,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: summaryData.map(
|
||||
(data) {
|
||||
return SummaryItem(data);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import 'package:adv_basics/questions_summary/question_identifier.dart';
|
||||
|
||||
class SummaryItem extends StatelessWidget {
|
||||
const SummaryItem(this.itemData, {super.key});
|
||||
|
||||
final Map<String, Object> itemData;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isCorrectAnswer =
|
||||
itemData['user_answer'] == itemData['correct_answer'];
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
QuestionIdentifier(
|
||||
isCorrectAnswer: isCorrectAnswer,
|
||||
questionIndex: itemData['question'] as int,
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
itemData['question'] as String,
|
||||
style: GoogleFonts.lato(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(itemData['user_answer'] as String,
|
||||
style: const TextStyle(
|
||||
color: Color.fromARGB(255, 202, 171, 252),
|
||||
)),
|
||||
Text(itemData['correct_answer'] as String,
|
||||
style: const TextStyle(
|
||||
color: Color.fromARGB(255, 181, 254, 246),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue