feat: enhance category selection flow by adding preselection support and a select button
This commit is contained in:
@@ -49,18 +49,28 @@ class CategoryThenProductPicker {
|
||||
int? preselectedCategoryId,
|
||||
Future<ProductOption?> Function(String name, int categoryId)? onCreate,
|
||||
}) async {
|
||||
// Steg 1 — välj kategori
|
||||
final selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (ctx) => _CategoryPickerSheet(
|
||||
tree: categoryTree,
|
||||
preselectedId: preselectedCategoryId,
|
||||
onSelected: (node) => Navigator.pop(ctx, node),
|
||||
),
|
||||
);
|
||||
if (selectedCategory == null || !context.mounted) return null;
|
||||
AdminCategoryNode? selectedCategory;
|
||||
|
||||
if (preselectedCategoryId != null) {
|
||||
// AI-föreslagen kategori — hoppa direkt till produktpickern
|
||||
selectedCategory = _findNode(categoryTree, preselectedCategoryId);
|
||||
}
|
||||
|
||||
if (selectedCategory == null) {
|
||||
// Steg 1 — visa kategoriträd
|
||||
if (!context.mounted) return null;
|
||||
selectedCategory = await showModalBottomSheet<AdminCategoryNode>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
useSafeArea: true,
|
||||
builder: (ctx) => _CategoryPickerSheet(
|
||||
tree: categoryTree,
|
||||
preselectedId: preselectedCategoryId,
|
||||
onSelected: (node) => Navigator.pop(ctx, node),
|
||||
),
|
||||
);
|
||||
if (selectedCategory == null || !context.mounted) return null;
|
||||
}
|
||||
|
||||
// Samla alla kategori-IDs i den valda grenen (inkl. ättlingar)
|
||||
final categoryIds = _collectIds(selectedCategory);
|
||||
@@ -319,6 +329,16 @@ class _CategoryTileState extends State<_CategoryTile> {
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
trailing: TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
minimumSize: const Size(0, 32),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
onPressed: () => widget.onLeafTap(node),
|
||||
child: const Text('Välj'),
|
||||
),
|
||||
onTap: () => setState(() => _expanded = !_expanded),
|
||||
),
|
||||
if (_expanded)
|
||||
|
||||
Reference in New Issue
Block a user