Skip to content

Commit

Permalink
feat: minor refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
jvenin committed Feb 25, 2024
1 parent 219fe76 commit 2e134ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
15 changes: 4 additions & 11 deletions lib/widgets/header/widgets/model_infos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,10 @@ class __SoundIndicesDisplayState extends ConsumerState<_SoundIndicesDisplay> {
itemBuilder: (context, index) {
final soundIndex = widget.soundIndices[index];
final relatedSoundInfo = widget.soundInfos[soundIndex.value];
return ListTile(
dense: true,
visualDensity: const VisualDensity(
horizontal: 0,
vertical: VisualDensity.minimumDensity,
),
contentPadding: const EdgeInsets.only(left: 5, right: 5),
selected: soundIndex == _selectedSoundIndex,
selectedTileColor: Colors.grey.shade400,
title: Label.regular(
"${soundIndex.value}: ${relatedSoundInfo.name}"),

return ListTileWrapper(
isSelected: soundIndex == _selectedSoundIndex,
label: "${soundIndex.value}: ${relatedSoundInfo.name}",
onTap: () {
setState(() {
_selectedSoundIndex = soundIndex;
Expand Down
51 changes: 36 additions & 15 deletions lib/widgets/utils/data_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,13 @@ class PartSelector extends StatelessWidget {
cacheExtent: 50,
itemBuilder: (context, index) {
final part = parts[index];
return ListTile(
dense: true,
visualDensity: const VisualDensity(
horizontal: 0,
vertical: VisualDensity.minimumDensity,
),
contentPadding: const EdgeInsets.only(left: 5, right: 5),
selected: part == value,
selectedTileColor: Colors.grey.shade400,
title: Label.regular(
"$index. ${part.name} (0x${part.offset.toRadixString(16)})"),
onTap: () {
onSelected(part);
},
);
return ListTileWrapper(
isSelected: part == value,
label:
"$index. ${part.name} (0x${part.offset.toRadixString(16)})",
onTap: () {
onSelected(part);
});
},
),
);
Expand Down Expand Up @@ -172,3 +164,32 @@ class ListViewWrapper extends StatelessWidget {
);
}
}

class ListTileWrapper extends StatelessWidget {
const ListTileWrapper({
super.key,
required this.isSelected,
required this.label,
this.onTap,
});

final bool isSelected;
final String label;
final void Function()? onTap;

@override
Widget build(BuildContext context) {
return ListTile(
dense: true,
visualDensity: const VisualDensity(
horizontal: 0,
vertical: VisualDensity.minimumDensity,
),
contentPadding: const EdgeInsets.only(left: 5, right: 5),
selected: isSelected,
selectedTileColor: Colors.grey.shade400,
title: Label.regular(label),
onTap: onTap,
);
}
}

0 comments on commit 2e134ac

Please sign in to comment.