Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom style button #81

Closed
alirezaemami opened this issue Jun 30, 2021 · 4 comments
Closed

Custom style button #81

alirezaemami opened this issue Jun 30, 2021 · 4 comments
Labels
question Further information is requested

Comments

@alirezaemami
Copy link

I want to use my own custom buttons to bold a word.
Is there a way to change the style of the selected words (without using the toolbar)?

@alirezaemami alirezaemami added the question Further information is requested label Jun 30, 2021
@tneotia
Copy link
Owner

tneotia commented Jun 30, 2021

Yes you can totally do that! There are two ways;

  1. You can remove the default bold button in the toolbar and add your own to display in the toolbar section

  2. You can remove the default bold button in the toolbar and add your own widget wherever you want

Which one are you trying to do? I can send an example for that.

@alirezaemami
Copy link
Author

Thanks for your prompt reply
I want to create a button outside the toolbar and change the style of the selected word (s) through it.
It will be nice if you send me an example code.

@tneotia
Copy link
Owner

tneotia commented Jul 3, 2021

Sorry for the late response. Here is how to do that:

bool isBold = false;

IconButton(
   icon: Icon(Icons.format_bold, color: isBold ? Colors.blue : Colors.black),
   onPressed: () => controller.execCommand('bold'),
);

HtmlEditor(
   htmlToolbarOptions: HtmlToolbarOptions(
      defaultToolbarButtons: [
            //add buttons here, but remove the bold button because you have a custom one. See README for more details
      ]
    ),
    callbacks: Callbacks(
       onChangeSelection: (EditorSettings settings) => setState(() { isBold = settings.isBold }),
    )
);

It isn't super difficult. You can use the same approach for any other button or dropdown. onChangeSelection is important so you can update your UI dynamically when the user puts the cursor on bold text or when the user puts the cursor on regular text.

Let me know if you have any issues or other questions.

@tneotia
Copy link
Owner

tneotia commented Jul 8, 2021

@alirezaemami I hope the above code was helpful. Closing for now, let me know if you have any other questions.

@tneotia tneotia closed this as completed Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants