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

how to use customtextstyle to change the font size and line height? #116

Closed
ADLsourceCode opened this issue Jun 21, 2019 · 22 comments
Closed
Assignees
Labels
bug Something isn't working high-priority
Milestone

Comments

@ADLsourceCode
Copy link

Hello,
How do I use customTextstyle to change the line height and font size of the text?
Below is my code:-

 Widget shortDesc(String data)
  {
   return Html(
      data: data,
      //Optional parameters:
      padding: EdgeInsets.all(2.0),
      backgroundColor: Colors.white70,
      defaultTextStyle: TextStyle(fontFamily: 'serif'),
      linkStyle: const TextStyle(
        color: Colors.redAccent,
      ),
      onLinkTap: (url) {
        // open url in a webview
      },
      onImageTap: (src) {
        // Display the image in large form.
      },
    );
  }
@The-Redhat
Copy link
Contributor

The-Redhat commented Jun 21, 2019

You can use the customTextStyle parameter. The function gives you the dom node, which represents the html widget. (Like customTextAlign in Readme)

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Jun 21, 2019

@The-Redhat Thanks for your reply,

the code says

"Undefined class 'dom'"

Below is my code:-

Widget shortDesc(String data)
  {
   return Html(
      data: data,
      //Optional parameters:
      padding: EdgeInsets.all(2.0),
      backgroundColor: Colors.white70,
      defaultTextStyle: TextStyle(fontFamily: 'serif'),
      linkStyle: const TextStyle(
        color: Colors.redAccent,
      ),
      onLinkTap: (url) {
        // open url in a webview
      },
      onImageTap: (src) {
        // Display the image in large form.
      },
       useRichText: false,
       customTextStyle : (dom node,textstyle) {
         textstyle=TextStyle(height: 1);
         if (node is dom.Element) {
           switch (node.localName) {
             case "article":
               return textstyle;
           }
         }
       }
    );
  }

@The-Redhat
Copy link
Contributor

You need to import dom:

import 'package:html/dom.dart' as dom;

@ADLsourceCode
Copy link
Author

@The-Redhat Thanks you so much..

the Code works..but the custom styles do not get seen ... basically, there is no change on the text even after implementing custom styles

@The-Redhat
Copy link
Contributor

The code you posted doesn't really change the TextStyle, or am I wrong ?

@ADLsourceCode
Copy link
Author

@The-Redhat I tried changing the line height using textstyle=TextStyle(height: 1); in the code..

@The-Redhat
Copy link
Contributor

But isn't 1 the default ?

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Jun 21, 2019

@The-Redhat yes... even if i change it to 2 or 2.5 ... No effect is shown...

@The-Redhat
Copy link
Contributor

Ah okay does it work with other elements ?

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Jun 21, 2019

@The-Redhat nope... I tried using with p tag also... It does not...even the font size does not change

@The-Redhat
Copy link
Contributor

Ok .. I haven't used the customTextStyle, the owner of this package for help should be able to help you

@ADLsourceCode
Copy link
Author

@Sub6Resources pls help

@The-Redhat
Copy link
Contributor

The-Redhat commented Jun 21, 2019

One question: to what is useRichText set ? If set to false try set it to true.

@ADLsourceCode
Copy link
Author

@The-Redhat no use... nothing changes

@ADLsourceCode
Copy link
Author

@Sub6Resources pls help

@Sub6Resources
Copy link
Owner

@ADLsourceCode please post your current code so we can take a look and see if there's anything not quite right.

@Sub6Resources
Copy link
Owner

Here is the correct way to use customTextStyle:

customTextStyle: (dom.Node node, TextStyle baseStyle) {
         if (node is dom.Element) {
           switch (node.localName) {
             case "article":
               return baseStyle.merge(TextStyle(height: 2, fontSize: 32));
           }
         }
       },

Note that useRichText must be set to true for customTextStyle to have any effect.

@ADLsourceCode
Copy link
Author

ADLsourceCode commented Jun 22, 2019

@Sub6Resources
it does not work...

Below is my code :-


Widget shortDesc(String data) {
    return Html(
      data: data,
      padding: EdgeInsets.all(2.0),
      backgroundColor: Colors.white70,
      //defaultTextStyle: TextStyle(fontFamily: 'serif'),
      onLinkTap: (url) {
        // open url in a webview
      },
      onImageTap: (src) {
        // Display the image in large form.
      },
      useRichText: true,
      customTextStyle: (dom.Node node, TextStyle baseStyle) {
        if (node is dom.Element) {
          switch (node.localName) {
            case "p":
              return baseStyle.merge(TextStyle(height: 2, fontSize: 20));
          }
        }
      },
    );


 Container(
                      margin: EdgeInsets.only(top: 10),
                      width: size.width * 0.85,
                      child: shortDesc("""<h2>Short Desc of the book</h2>
                    <p>asdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadf
                     <ul>
                      <li>Coffee</li>
                       <li>Tea</li>
                      <li>Milk</li>
                      </ul> 
                    <p>slfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollView<b>asdadadadadadfslfsfsflsksd</b>sksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNeste</p><p>dScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScro</p>
                    <p>llViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrollViewasdadadadadadfslfsfsflsksdsksdfsNestedScrw</p>
                    """))

@Sub6Resources Sub6Resources reopened this Jun 22, 2019
@Sub6Resources
Copy link
Owner

Hmm, this is odd. I'm able to replicate the issue, so I'll look into it.

@Sub6Resources Sub6Resources added bug Something isn't working high-priority labels Jun 22, 2019
@Sub6Resources Sub6Resources added this to the Next Version milestone Jun 22, 2019
@Sub6Resources Sub6Resources self-assigned this Jun 22, 2019
@Sub6Resources
Copy link
Owner

I've identified the issue. A fix will be released asap.

@Sub6Resources
Copy link
Owner

A fix has been released in Version 0.10.4. The README now also contains example code for using customTextStyle. Thank you for your patience.

@ADLsourceCode
Copy link
Author

@Sub6Resources It works... Thank you so much for your support.

@The-Redhat Thanks to you too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority
Projects
None yet
Development

No branches or pull requests

3 participants