You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decky/lib/widgets/answer_option.dart

82 lines
2.2 KiB

import 'package:flutter/material.dart';
class AnswerOption extends StatelessWidget {
final String text;
final bool isSelected;
final VoidCallback onTap;
final bool? isCorrect;
const AnswerOption({
super.key,
required this.text,
required this.isSelected,
required this.onTap,
this.isCorrect,
});
@override
Widget build(BuildContext context) {
Color? backgroundColor;
Color? borderColor;
IconData? icon;
if (isCorrect != null) {
if (isCorrect == true) {
backgroundColor = Colors.green.withValues(alpha: 0.1);
borderColor = Colors.green;
icon = Icons.check_circle;
} else {
backgroundColor = Colors.red.withValues(alpha: 0.1);
borderColor = Colors.red;
icon = Icons.cancel;
}
} else if (isSelected) {
backgroundColor = Theme.of(context).colorScheme.primaryContainer;
borderColor = Theme.of(context).colorScheme.primary;
}
return Card(
color: backgroundColor,
elevation: isSelected ? 4 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: borderColor != null
? BorderSide(color: borderColor, width: 2)
: BorderSide.none,
),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
if (icon != null) ...[
Icon(icon, color: borderColor),
const SizedBox(width: 12),
],
Expanded(
child: Text(
text,
style: Theme.of(context).textTheme.bodyLarge,
),
),
if (isSelected && icon == null)
Icon(
Icons.radio_button_checked,
color: Theme.of(context).colorScheme.primary,
)
else if (!isSelected)
Icon(
Icons.radio_button_unchecked,
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.5),
),
],
),
),
),
);
}
}

Powered by TurnKey Linux.