From fcfe062943f427efbe7f580f5c9fefe1e59dd1a6 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 15 Jul 2023 12:26:56 +0200 Subject: [PATCH] style(neon_notes): cleanup NotesCategorySelect --- .../neon_notes/lib/widgets/category_select.dart | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/neon/neon_notes/lib/widgets/category_select.dart b/packages/neon/neon_notes/lib/widgets/category_select.dart index 4d51d2d3..14f3a555 100644 --- a/packages/neon/neon_notes/lib/widgets/category_select.dart +++ b/packages/neon/neon_notes/lib/widgets/category_select.dart @@ -11,6 +11,13 @@ class NotesCategorySelect extends StatelessWidget { if (initialValue != null) { onChanged(initialValue!); } + + categories.sort(); + + // After sorting the empty category '' should be at the first place + if (!categories.first.isNotEmpty) { + categories.insert(0, ''); + } } final List categories; @@ -18,8 +25,6 @@ class NotesCategorySelect extends StatelessWidget { final Function(String category) onChanged; final Function() onSubmitted; - late final _categories = categories..sort((final a, final b) => a.compareTo(b)); - @override Widget build(final BuildContext context) => Autocomplete( initialValue: initialValue != null @@ -28,13 +33,6 @@ class NotesCategorySelect extends StatelessWidget { ) : null, optionsBuilder: (final value) { - final categories = [ - if (!_categories.contains('')) ...{ - '', - }, - ..._categories, - ]; - if (value.text.isEmpty) { return categories; }