lass QuestionIdentifier extends StatelessWidget {
const QuestionIdentifier({
super.key,
required this.questionIndex,
required this.isCorrectAnswer,
});
final int questionIndex;
final bool isCorrectAnswer;
Widget build(context) {
final questionNumer = questionIndex + 1;
return Container(
width: 30,
height: 30,
alignment: Alignment.center,
decoration: BoxDecoration(
color: isCorrectAnswer
? const Color.fromARGB(255, 140, 203, 255)
: const Color.fromARGB(255, 255, 150, 142),
borderRadius: BorderRadius.circular(100),
),
child: Text(
questionNumer.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromARGB(255, 0, 0, 0),
),
),
);
}
}
SizedBox는 물론 padding 대신에 UI간 padding 값을 줄 때고 사용되긴 한다.
하지만 결국 둘다 어떠한 UI를 warpping한다는 점에서 동일하다.
이때 위 Container의 가장 큰 장점은 decoration이 가능하다는 것이다.
import 'package:first_app/questions_summary/question_identifier.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class SummaryItem extends StatelessWidget {
const SummaryItem(this.itemData, {super.key});
final Map<String, Object> itemData;
Widget build(context) {
final isCorrectAnswer =
itemData['user_anwer'] == itemData['correct_answer'];
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
QuestionIdentifier(
questionIndex: itemData['question_index'] as int,
isCorrectAnswer: isCorrectAnswer,
),
const SizedBox(width: 20),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
itemData['question'] as String,
style: GoogleFonts.bebasNeue(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold),
),
Text(
itemData['user_answer'] as String,
style: const TextStyle(
color: Color.fromARGB(255, 241, 174, 253),
),
),
Text(
itemData['correct_answer'] as String,
style: const TextStyle(
color: Color.fromARGB(255, 197, 255, 199),
),
),
],
),
),
],
);
}
}