-
Notifications
You must be signed in to change notification settings - Fork 345
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
how can I add a dropdown with custom font style choices for editor text #59
Comments
If you want custom toolbar buttons then simply do this: HtmlEditor(
controller: controller,
htmlToolbarOptions: HtmlToolbarOptions(
defaultToolbarButtons: [
StyleButtons(),
FontSettingButtons(fontName: false),
FontButtons(),
ListButtons(),
ParagraphButtons(),
InsertButtons(),
OtherButtons(),
],
customToolbarButtons: [
CustomFont(),
CustomTextColor(),
],
),
),
For implementing a custom font picker or custom color picker I highly recommend checking out how I did the default version in toolbar_widget.dart at lines 500 and 905. Now that I think about it, there is no way for custom implementations to be updated when the font family/color/font size, etc changes in the editor. Internally I handle this with a method listening to changes sent in JSON, but I think its a good idea to add some sort of callback/listener/stream to the package so custom UI elements can be updated. Therefore I am adding the "enhancement" tag to this issue. Let me know if you need more help with the implementation |
hi, thanks for your reply, I added them here
and here
pubspec.yaml
later I tried to add a new custom button also and call this controller.execCommand('fontName', argument: 'AlexBrush'); |
and one more thing, on real device, it not showing the editor, tool are showing and it's working perfectly in emulator |
2 things you are doing wrong I think:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="description" content="Flutter Summernote HTML Editor">
<meta name="author" content="tneotia">
<title>Summernote Text Editor HTML</title>
<script src="assets/packages/html_editor_enhanced/assets/jquery.min.js"></script>
<link href="assets/packages/html_editor_enhanced/assets/summernote-lite.min.css" rel="stylesheet">
<script src="assets/packages/html_editor_enhanced/assets/summernote-lite.min.js"></script>
<style>
<!--your font faces go here-->
</style>
<!--darkCSS-->
</head>
<body>
<div id="summernote-2"></div>
<!--headString-->
<!--summernoteScripts-->
</body>
</html> Then pass the file location in your
FYI I didn't test this, don't have much time right now. If it still doesn't work I'll try to get a working solution tomorrow.
Can you try loading the example app? If the example app works then there is some issue in your configuration. |
Hmm do you get any logs when opening up the editor? I have no issues on my samsung device |
Okay I tried to come up with an example and I was successful. I also figured out why nothing was showing on the editor. Change your app like this: flutter:
assets:
- assets/ create <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="description" content="Flutter Summernote HTML Editor">
<meta name="author" content="tneotia">
<title>Summernote Text Editor HTML</title>
<script src="file:///android_asset/flutter_assets/packages/html_editor_enhanced/assets/jquery.min.js"></script>
<link href="file:///android_asset/flutter_assets/packages/html_editor_enhanced/assets/summernote-lite.min.css" rel="stylesheet">
<script src="file:///android_asset/flutter_assets/packages/html_editor_enhanced/assets/summernote-lite.min.js"></script>
<style>
@font-face {
font-family: 'Billabong';
font-style: normal;
font-weight: 400;
src: local('Billabong'), url('https://fonts.cdnfonts.com/s/13949/Billabong.woff') format('woff');
}
you need to add the other fonts here!!
</style>
</head>
<body>
<div id="summernote-2"></div>
</body>
</html>
HtmlEditor(
controller: controller,
htmlEditorOptions: HtmlEditorOptions(
filePath: "assets/summernote.html",
),
htmlToolbarOptions: HtmlToolbarOptions(
defaultToolbarButtons: [
StyleButtons(),
],
customToolbarButtons: [
Container(
padding: const EdgeInsets.only(left: 8.0),
height: kMinInteractiveDimension,
decoration:
BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
border: Border.all(
color: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.12))),
child: CustomDropdownButtonHideUnderline(
child: CustomDropdownButton<String>(
menuMaxHeight: MediaQuery.of(context).size.height / 3,
menuDirection: DropdownMenuDirection.down,
items: [
CustomDropdownMenuItem(
value: 'Courier New',
child: PointerInterceptor(
child: Text('Courier New',
style: TextStyle(fontFamily: 'Courier'))),
),
CustomDropdownMenuItem(
value: 'sans-serif',
child: PointerInterceptor(
child: Text('Sans Serif',
style: TextStyle(fontFamily: 'sans-serif'))),
),
CustomDropdownMenuItem(
value: 'Times New Roman',
child: PointerInterceptor(
child: Text('Times New Roman',
style: TextStyle(fontFamily: 'Times'))),
),
CustomDropdownMenuItem(
value: 'Billabong',
child: PointerInterceptor(
child: Text('Billabong',
style: TextStyle(
fontFamily: 'Billabong',
))),
),
//add your other fonts here!!
],
value: 'Courier New',
onChanged: (String? changed) async {
if (changed != null) {
controller.execCommand('fontName', argument: changed);
}
},
),
),
)
//add the other widgets here!!
],
),
), To simplify my testing I didn't include font asset files in the Flutter app and I did not make it so that updating the font style changes the selected item for the dropdown. You should re-implement those functionalities. Edit:
This has been added to the package to make your code a bit easier when you make the custom button :) |
bingo, it's worked, thanks bro, you are the best. :) |
@tneotia @Ashish-Raturi hey , looks like this code is not work, may i know need copy those resource to my project's asset ? i am using ios device to do the POC
|
The package asset path may be different on iOS. You can copy those assets to your project if you'd like, then the code becomes <script src="assets/jquery.min.js"></script>
<link href="assets/summernote-lite.min.css" rel="stylesheet">
<script src="assets/summernote-lite.min.js"></script> |
@tneotia but i am afraid if copy those assets to my project, the plugin's version upgrade need more effort to do that, for i believe that those source file have a big chance will be updated in the future. |
Actually no, those source files are hardly ever updated. They will likely only be updated when there is a Summernote version upgrade, which is very infrequent. |
How to get those file names that you are using in your custom html code? we are using that and it is not doing anything. |
I used this example, but it doesn't show the editor :/ |
These are bundled into the package itself, if you are building Android (not web or iOS), it should work fine. Web and iOS will have different paths.
Check the logs, there might be some error that provides a clue what the issue is |
I tried using the web, but it didn't work. does anyone have an idea how I can customize font style on the web? |
For the web, the solution of tneotia is correct, but it is important to import the font in summernote.html in the ttf format. |
like this |
Can you give me example code for this?
|
Hi, you guys are great,
I have a question, how can I add my custom fonts on text editor
and custom text color, or custom color widget
thanks in advance.
The text was updated successfully, but these errors were encountered: