我使用 flutter 制作了一个基本的测验应用程序,在结果屏幕中显示了正确答案和用户答案,但颜色和字体未按预期显示,就像用于设置答案样式的代码不起作用。
我在这里提供完整的代码,有人可以告诉我为什么这不起作用。
import 'package:adv_basics/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;
@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: GoogleFont.lato(
color: Color.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),
),
),
],
),
),
],
),
);
}
}
问题就在这里:
您的代码:
GoogleFont.lato(
color: Color.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
更正:
GoogleFonts.lato(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
您只需将“s”添加到
GoogleFonts.lato
和Colors
即可。