Skip to content

Instantly share code, notes, and snippets.

@mikkomcmenamin
Created April 6, 2023 05:26
Show Gist options
  • Save mikkomcmenamin/cedced284a7e298d53a2d29aa563c691 to your computer and use it in GitHub Desktop.
Save mikkomcmenamin/cedced284a7e298d53a2d29aa563c691 to your computer and use it in GitHub Desktop.
LabelDropDown
class LabelDropdown extends ConsumerWidget {
const LabelDropdown({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final project = ref.watch(projectControllerProvider);
return PopupMenuButton<String>(
onSelected: (String value) {
if (value == "AddNewLabel") {
return;
} else {
// Update other views with selected label
}
},
itemBuilder: (BuildContext context) {
return [
...project.labels.map<PopupMenuItem<String>>(
(String label) => PopupMenuItem<String>(
key: Key(project.labels.join(',')),
value: label,
child: Text(label),
),
),
PopupMenuItem<String>(
value: "AddNewLabel",
child: TextField(
style: const TextStyle(color: AppColors.textPrimary),
cursorColor: AppColors.accentPrimary,
decoration: const InputDecoration(
hintText: "Add new label",
hintStyle: TextStyle(color: AppColors.textPrimary),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.accentPrimary),
),
),
onSubmitted: (value) {
if (value.isNotEmpty) {
ref.read(projectControllerProvider.notifier).addLabel(value);
}
},
),
),
];
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment