| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import 'package:flutter/material.dart';
- import '../models/problem.dart';
- /// 题目列表卡片
- class ProblemCard extends StatelessWidget {
- final Problem problem;
- final bool isSelected;
- final bool isInCart;
- final VoidCallback onTap;
- final ValueChanged<String> onAddToCart;
- final ValueChanged<String>? onRemoveFromCart;
- const ProblemCard({
- super.key,
- required this.problem,
- this.isSelected = false,
- this.isInCart = false,
- required this.onTap,
- required this.onAddToCart,
- this.onRemoveFromCart,
- });
- @override
- Widget build(BuildContext context) {
- return Card(
- margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
- color: isSelected ? Theme.of(context).colorScheme.primaryContainer : null,
- child: ListTile(
- dense: true,
- leading: _typeIcon(),
- title: Text(
- '${problem.questionType} · ${problem.difficultyLabel}(${problem.difficulty})',
- style: const TextStyle(fontSize: 13),
- ),
- subtitle: Text(
- 'ID: ${problem.id}',
- style: TextStyle(fontSize: 11, color: Colors.grey.shade600),
- ),
- trailing: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (!problem.isAnnotated)
- const Icon(Icons.warning_amber, size: 16, color: Colors.orange),
- if (isInCart)
- IconButton(
- icon: const Icon(Icons.remove_shopping_cart, size: 18, color: Colors.red),
- onPressed: () => onRemoveFromCart?.call(problem.id),
- tooltip: '从试题篮移除',
- )
- else
- IconButton(
- icon: const Icon(Icons.add_shopping_cart, size: 18),
- onPressed: () => onAddToCart(problem.id),
- tooltip: '加入试题篮',
- ),
- ],
- ),
- onTap: onTap,
- ),
- );
- }
- Widget _typeIcon() {
- IconData icon;
- Color color;
- switch (problem.questionType) {
- case '单选题':
- icon = Icons.radio_button_checked;
- color = Colors.blue;
- break;
- case '多选题':
- icon = Icons.check_box;
- color = Colors.purple;
- break;
- case '填空题':
- icon = Icons.edit_note;
- color = Colors.orange;
- break;
- case '解答题':
- icon = Icons.assignment;
- color = Colors.green;
- break;
- default:
- icon = Icons.question_mark;
- color = Colors.grey;
- }
- return Icon(icon, color: color, size: 20);
- }
- }
|