getDots method
List<AnimatedPositioned>
getDots(
- int amount,
- int targetAmount,
- BoxConstraints constraints,
- int avatarSize,
Implementation
List<AnimatedPositioned> getDots(
int amount,
int targetAmount,
BoxConstraints constraints,
int avatarSize,
) {
List<AnimatedPositioned> tDots = [];
for (var i = 0; i < amount; i++) {
tDots.add(AnimatedPositioned(
duration: trackingSpeed,
left: avatarSize +
(constraints.biggest.width - 2 * avatarSize) / 100.0 * positions[i],
top: avatarSize +
(constraints.biggest.height - 2 * avatarSize) /
100.0 *
positions[(i + amount) + 5],
child: GestureDetector(
onTap: () async {
if (guess) {
setState(() {
distractors[i] = true;
wrong += 1;
mistakes[conCurrentNum] = mistakes[conCurrentNum] + 1;
});
await Future<dynamic>.delayed(
const Duration(milliseconds: 250));
setState(() {
distractors[i] = false;
});
}
},
child: CircleAvatar(
radius: avatarSize / 2,
backgroundColor:
distractors[i] ? const Color(0xffFF0000) : Colors.grey,
)),
));
}
for (var i = 0; i < targetAmount; i++) {
tDots.add(AnimatedPositioned(
duration: trackingSpeed,
left: avatarSize +
(constraints.biggest.width - 2 * avatarSize) /
100.0 *
positions[i + amount],
top: avatarSize +
(constraints.biggest.height - 2 * avatarSize) /
100.0 *
positions[i + amount + 5],
child: GestureDetector(
onTap: () {
if (guess) {
setState(() {
dots[i] = true;
var targetsFound = dots.where((item) => item == true).length;
if (targetsFound == targetAmount) {
makeGuess();
}
});
}
},
child: CircleAvatar(
radius: avatarSize / 2,
backgroundColor: dots[i] ? const Color(0xff1F669B) : Colors.grey,
)),
));
}
return tDots;
}