mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-15 02:05:58 -07:00
feature: Rework responsive layout (#217)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
e07f280124
commit
8012fdcea8
48 changed files with 1468 additions and 1040 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue