Created
April 6, 2023 05:26
-
-
Save mikkomcmenamin/cedced284a7e298d53a2d29aa563c691 to your computer and use it in GitHub Desktop.
LabelDropDown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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