-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
214 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:reciper/models/tag.dart'; | ||
import 'package:reciper/utilities/database.dart'; | ||
|
||
class NewTagDialog extends StatelessWidget { | ||
const NewTagDialog({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
TextEditingController newTagInputController = TextEditingController(); | ||
|
||
return AlertDialog( | ||
title: const Text("New Tag"), | ||
content: TextField( | ||
controller: newTagInputController, | ||
decoration: const InputDecoration(hintText: "Tag name"), | ||
), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text("cancel"), | ||
onPressed: () { | ||
Navigator.pop(context); | ||
}), | ||
TextButton( | ||
child: const Text("save"), | ||
onPressed: () { | ||
DatabaseService.createTag(Tag(name: newTagInputController.text)); | ||
|
||
Navigator.pop(context); | ||
}, | ||
), | ||
]); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:reciper/models/tag.dart'; | ||
import 'package:reciper/widgets/newTagDialog.dart'; | ||
|
||
class RecipeTagSelector extends StatefulWidget { | ||
final List<Tag> tags; | ||
final List<int> selectedTagsId; | ||
|
||
final Function onTagsSelectionUpdate; | ||
final Function onTagsUpdate; | ||
|
||
const RecipeTagSelector( | ||
{super.key, | ||
required this.tags, | ||
required this.onTagsUpdate, | ||
required this.selectedTagsId, | ||
required this.onTagsSelectionUpdate}); | ||
|
||
@override | ||
State<RecipeTagSelector> createState() => _RecipeTagSelectorState(); | ||
} | ||
|
||
class _RecipeTagSelectorState extends State<RecipeTagSelector> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Row(children: [ | ||
ListView.builder( | ||
itemCount: widget.tags.length, | ||
shrinkWrap: true, | ||
scrollDirection: Axis.horizontal, | ||
itemBuilder: ((context, index) { | ||
return FilledButton( | ||
style: FilledButton.styleFrom( | ||
backgroundColor: | ||
widget.selectedTagsId.contains(widget.tags[index].id) | ||
? Theme.of(context).colorScheme.primary | ||
: Theme.of(context).colorScheme.secondary), | ||
// : | ||
// ? Theme.of(context).primaryColor | ||
// : Colors.transparent, | ||
child: Row(children: [ | ||
widget.selectedTagsId.contains(widget.tags[index].id) | ||
? const Icon(Icons.check) | ||
: const Text(""), | ||
Text(widget.tags[index].name ?? "") | ||
]), | ||
onPressed: () { | ||
bool value = | ||
!widget.selectedTagsId.contains(widget.tags[index].id); | ||
if (value) { | ||
widget.selectedTagsId.add(widget.tags[index].id!); | ||
} else { | ||
widget.selectedTagsId.remove(widget.tags[index].id); | ||
} | ||
widget.onTagsSelectionUpdate(widget.selectedTagsId); | ||
widget.onTagsUpdate(widget.tags); | ||
}); | ||
})), | ||
IconButton( | ||
icon: const Icon( | ||
Icons.add, | ||
), | ||
onPressed: () { | ||
showDialog( | ||
context: context, | ||
builder: (context) => const NewTagDialog()) | ||
.then((value) => widget.onTagsUpdate()); | ||
}) | ||
]); | ||
} | ||
} | ||
|
||
/* | ||
DropdownButton( | ||
onChanged: (value) {}, | ||
items: widget.tags.map<DropdownMenuItem<String>>((Tag tag) { | ||
return DropdownMenuItem<String>( | ||
value: tag.id.toString(), | ||
child: Row( | ||
children: [ | ||
Checkbox( | ||
value: widget.selectedTagsId.contains(tag.id), | ||
onChanged: (value) { | ||
if (value ?? false) { | ||
widget.selectedTagsId.add(tag.id!); | ||
} else { | ||
widget.selectedTagsId.remove(tag.id); | ||
} | ||
widget.onTagsSelectionUpdate(widget.selectedTagsId); | ||
widget.onTagsUpdate(widget.tags); | ||
}), | ||
Text(tag.name ?? "") | ||
], | ||
), | ||
); | ||
}).toList(), | ||
); | ||
*/ |
This file contains 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