feature: Rework responsive layout (#217)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-02-07 15:55:01 +01:00 committed by GitHub
parent e07f280124
commit 8012fdcea8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 1468 additions and 1040 deletions

View file

@ -1,31 +1,53 @@
import 'package:flutter/material.dart';
Future<void> openOptionDialogue<T>(
Future<List<T>> openMultiSelectOptions<T>(
BuildContext context, {
required String label,
bool allowMultiSelection = false,
bool forceAtleastOne = true,
required List<T> selected,
required List<T> items,
bool isNullable = false,
required Widget Function(T? type) itemBuilder,
}) {
return showDialog(
Function(List<T> values)? onChanged,
required Widget Function(T type, bool selected, Function onTap) itemBuilder,
}) async {
Set<T> currentSelection = selected.toSet();
await showDialog(
context: context,
builder: (context) {
return AlertDialog(
builder: (context) => StatefulBuilder(
builder: (context, setState) => AlertDialog(
title: Text(label),
content: SizedBox(
width: MediaQuery.of(context).size.width * 0.65,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
shrinkWrap: true,
children: [
if (isNullable) itemBuilder(null),
...items.map(
(e) => itemBuilder(e),
)
],
children: items.map((item) {
bool isSelected = currentSelection.contains(item);
return itemBuilder(
item,
isSelected,
() {
setState(() {
if (allowMultiSelection) {
if (isSelected) {
if (!forceAtleastOne || currentSelection.length > 1) {
currentSelection.remove(item);
}
} else {
currentSelection.add(item);
}
} else {
currentSelection = {item};
}
});
onChanged?.call(currentSelection.toList());
},
);
}).toList(),
),
),
);
},
),
),
);
return currentSelection.toList();
}