Refactored the code so that DifficultyDropdown

is not longer needed
This commit is contained in:
SomnusVeritas
2023-10-17 18:17:59 +02:00
parent e69aab7a04
commit 11266b9ab4
3 changed files with 15 additions and 34 deletions

View File

@@ -1,29 +0,0 @@
import 'package:flutter/material.dart';
import '../models/difficulty.dart';
typedef Intcallback = void Function(int);
class DifficultyDropdown extends StatelessWidget {
const DifficultyDropdown({super.key, this.onChanged});
final Intcallback? onChanged;
@override
Widget build(BuildContext context) {
List<DropdownMenuEntry<Difficulty>> dropdownMenuEntryList =
Difficulty.values.map((e) => _toDropdownMenuEntry(e, e.name)).toList();
return DropdownMenu<Difficulty?>(
dropdownMenuEntries: dropdownMenuEntryList,
onSelected: (value) {
if (onChanged != null) {
onChanged!(value?.index ?? -1);
}
},
);
}
DropdownMenuEntry<Difficulty> _toDropdownMenuEntry(
Difficulty difficulty, String text) =>
DropdownMenuEntry(value: difficulty, label: text);
}