* make uses a private field for ConstructUses * expose capped list of uses in ConstructUses * filter capped construct uses in getUses
86 lines
2.5 KiB
Dart
86 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
import 'package:fluffychat/l10n/l10n.dart';
|
|
import 'package:fluffychat/pangea/analytics_misc/construct_use_model.dart';
|
|
import 'package:fluffychat/pangea/analytics_misc/construct_use_type_enum.dart';
|
|
import 'package:fluffychat/pangea/analytics_misc/constructs_model.dart';
|
|
import 'package:fluffychat/pangea/analytics_misc/learning_skills_enum.dart';
|
|
import 'package:fluffychat/pangea/constructs/construct_level_enum.dart';
|
|
|
|
class LemmaUsageDots extends StatelessWidget {
|
|
final ConstructUses construct;
|
|
final LearningSkillsEnum category;
|
|
|
|
final String tooltip;
|
|
final IconData icon;
|
|
|
|
const LemmaUsageDots({
|
|
required this.construct,
|
|
required this.category,
|
|
required this.tooltip,
|
|
required this.icon,
|
|
super.key,
|
|
});
|
|
|
|
/// Find lemma uses for the given exercise type, to create dot list
|
|
List<bool> sortedUses(LearningSkillsEnum category) {
|
|
final List<bool> useList = [];
|
|
for (final OneConstructUse use in construct.cappedUses) {
|
|
if (use.xp == 0) {
|
|
continue;
|
|
}
|
|
// If the use type matches the given category, save to list
|
|
// Usage with positive XP is saved as true, else false
|
|
if (category == use.useType.skillsEnumType) {
|
|
useList.add(use.xp > 0);
|
|
}
|
|
}
|
|
return useList;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final List<Widget> dots = [];
|
|
for (final bool use in sortedUses(category)) {
|
|
dots.add(
|
|
Container(
|
|
width: 15.0,
|
|
height: 15.0,
|
|
decoration: BoxDecoration(
|
|
color: use ? AppConfig.success : Colors.red,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
final Color textColor = (Theme.of(context).brightness != Brightness.light
|
|
? construct.lemmaCategory.color(context)
|
|
: construct.lemmaCategory.darkColor(context));
|
|
|
|
return ListTile(
|
|
leading: Tooltip(
|
|
triggerMode: TooltipTriggerMode.tap,
|
|
message: tooltip,
|
|
child: Icon(
|
|
icon,
|
|
size: 24,
|
|
color: textColor.withValues(alpha: 0.7),
|
|
),
|
|
),
|
|
title: dots.isEmpty
|
|
? Text(
|
|
L10n.of(context).noDataFound,
|
|
style: const TextStyle(
|
|
fontStyle: FontStyle.italic,
|
|
),
|
|
)
|
|
: Wrap(
|
|
spacing: 3,
|
|
runSpacing: 5,
|
|
children: dots,
|
|
),
|
|
);
|
|
}
|
|
}
|