Clicking on an icon of a custom component (task item) to change its type (open/done) #249
-
Hi everyone I created a custom component similar to a list item (ordered/unordered) to represent a task (open/done). Depending on what type a task item is, there's a leading checkbox icon that's unchecked or checked. Now I can't figure out how to implement the user interaction ,i.e. clicking the checkbox, so that the taskItem type converts from e.g. open to done, or from done to open resp. So far I've wrapped the leading checkbox in the respective widget with a GestureDetector which works alright for printing anything to console but I'm missing how to convert the taskItem type to a different one. I suspected I would have to use an extension method on CommonEditorOperations (see here), but it looks like I need access to the EditContext in order to get to the selection and the specific node within the document to change the task item's type. And that's where I hit a wall. As I understand it, in order to stay within the SuperEditor.custom setup, I can't just pass in the EditContext, right? Can anyone point me in the right direction, how would you go about it? Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @siuvoniazzi I had a similar use case before where the user can click on an image to replace it while preserving the node's data (e.g. index in the document). The main issue was: updating the node's data from the component. While Simply, I wrapped Here's how the Widget build(BuildContext context) {
return Provider(
create: (context) => MyCustomController(editor: _docEditor, composer: _composer),
child: SuperEditor.custom(
editor: _docEditor,
composer: _composer,
),
); As you may have noticed above, And here's the Widget? myCustomComponentBuilder(ComponentContext componentContext) {
final myCustomNode = componentContext.documentNode;
if (myCustomNode is! MyCustomNode) return null;
return MyCustomComponent(
data: myCustomNode.data,
onTap: () {
// access the controller
final myCustomController = Provider.of<MyCustomController>(componentContext.context, listen: false);
// do what you gotta do
myCustomController.onTap(........);
},
);
} Here's a full simplified example: Screen.Recording.2021-06-16.at.2.06.50.AM.mov |
Beta Was this translation helpful? Give feedback.
Hi @siuvoniazzi
I had a similar use case before where the user can click on an image to replace it while preserving the node's data (e.g. index in the document). The main issue was: updating the node's data from the component.
While
SuperEditor
still doesn't provide any direct approach to the problem, having theBuildContext
accessible (throughComponentContext
ofComponentBuilder
) makes theInheritedWidget
approach a viable option. I implemented this approach using the Provider package which is just a sugarcoat forInheritedWidget
.Simply, I wrapped
SuperEditor.custom
with a Provider for a custom controller, and I accessed that controller inside theComponentBuilder
through theBuildContext