mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 13:03:15 +02:00
40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// A 0-5 grade widget with tappable stars and a "Blackout" (grade 0) button.
|
|
class GradeStars extends StatelessWidget {
|
|
/// Creates a [GradeStars].
|
|
const GradeStars({
|
|
required this.grade,
|
|
required this.onGrade,
|
|
super.key,
|
|
});
|
|
|
|
/// Current grade (0-5), null if not yet graded.
|
|
final int? grade;
|
|
|
|
/// Called with the selected grade (0-5).
|
|
final ValueChanged<int> onGrade;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => onGrade(0),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: grade == 0 ? Colors.red : null,
|
|
),
|
|
child: const Text('Blackout'),
|
|
),
|
|
for (var i = 1; i <= 5; i++)
|
|
IconButton(
|
|
icon: Icon(
|
|
grade != null && i <= grade! ? Icons.star : Icons.star_border,
|
|
color: Colors.amber,
|
|
),
|
|
onPressed: () => onGrade(i),
|
|
),
|
|
],
|
|
);
|
|
}
|