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

Fix inline rendering of (text) links #499

Merged
merged 4 commits into from
Jan 18, 2021

Conversation

erickok
Copy link
Collaborator

@erickok erickok commented Jan 15, 2021

If non-text elements are used inside the we still need widget spans and if they are long you can still have clunky wrapping, but I'm not even sure that is a bug per se.

Screenshot 2021-01-15 at 12 48 49

Fixes #388, #488 and #495

If non-text elements are used inside the <a> we still need widget spans and if they are long you can still have clunky wrapping, but I'm not even sure that is a bug per se.

Fixes Sub6Resources#388, Sub6Resources#488 and Sub6Resources#495
@ryan-berger
Copy link
Collaborator

If we add a little bit to make sure that the direct child isn't an image, would this fix also be able to replace #322 @erickok?

@erickok
Copy link
Collaborator Author

erickok commented Jan 18, 2021

Could you reiterate the problem in that ticket?

@ryan-berger
Copy link
Collaborator

If an image is a child of a link, the there is still text-decoration (a blue underline) under the image when that should not be the case. It seems like this is the place where link text is built and where recursion for building children of links happens am I correct?

@erickok
Copy link
Collaborator Author

erickok commented Jan 18, 2021

Ah I see that's this problem:
Screenshot 2021-01-18 at 21 23 01

That is not directly fixed by this PR, but it's this code, yeah. I can take a look.

…ve the text style applied to it, not other content such as images
@erickok erickok mentioned this pull request Jan 18, 2021
@erickok
Copy link
Collaborator Author

erickok commented Jan 18, 2021

Fixed that too. The style is now only applied to the texts inside of the <a> tag, as it should have been in the first place. I also was able to further clean up (simplify) the code.

Copy link
Collaborator

@ryan-berger ryan-berger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. However, there are merge conflicts, so that just needs to be fixed and then I'll merge

@erickok
Copy link
Collaborator Author

erickok commented Jan 18, 2021

Done.

@ryan-berger ryan-berger merged commit e2a9933 into Sub6Resources:master Jan 18, 2021
@amanokerim
Copy link

Done.

Is it fixed?

How to use it, if currently, I am on a master branch?
flutter_html:
git:
url: https://github.com/Sub6Resources/flutter_html.git
ref: master

@erickok
Copy link
Collaborator Author

erickok commented Jan 25, 2021

Yes this should be fixed on master.

@DFelten
Copy link
Contributor

DFelten commented Jan 29, 2021

I think this MR has added a new bug.: #515

@amanokerim
Copy link

Yes this should be fixed on master.

My pubspec.yaml:

flutter_html: 
    git:
        url: https://github.com/Sub6Resources/flutter_html.git
        ref: master

Result:
screenchot

Is there something I am doing wrong?

@erickok
Copy link
Collaborator Author

erickok commented Feb 2, 2021

@amanokerim Can you provide the exact code/HTML you are using to create that output?

@amanokerim
Copy link

@erickok
HTML:

<p style="text-align:justify">Напомним, на состоявшемся 27 января выездном <a href="https://turkmenportal.com/blog/33872/prezident-turkmenistana-provel-rasshirennoe-zasedanie-gossoveta-bezopasnosti" target="_blank">расширенном заседании Государственного совета безопасности</a> Верховный Главнокомандующий Вооружёнными Силами дал поручения по дальнейшему укреплению и модернизации материально-технической базы военных и правоохранительных органов, подготовке новых, соответствующих климатическим условиям страны и высоким критериям комфортности, видов экипировки для военнослужащих.</p> 

Flutter side:

Html(
        style: {
          "body": Style(
            margin: EdgeInsets.zero,
            fontFamily: "Rubik",
            fontSize: FontSize(_s.fontSize * 19),
          ),
          "p": Style(
            margin: EdgeInsets.only(bottom: 20.0 * _s.fontSize),
            padding: EdgeInsets.symmetric(horizontal: 15.0 * _s.fontSize),
            lineHeight: 1.3,
            textAlign: TextAlign.start,
            fontSize: FontSize(18.0 * _s.fontSize),
            fontFamily: "Rubik",
            fontWeight: FontWeight.w400,
          ),
          "table": Style(
            border: Border.all(color: Colors.grey, width: .5),
            margin: EdgeInsets.all(10.0),
            // backgroundColor: Colors.blue[50],
          ),
          "tr": Style(
            border: Border.all(width: .5, color: Colors.grey),
            padding: EdgeInsets.symmetric(horizontal: 15.0 * _s.fontSize),
          ),
          "td": Style(
            padding: EdgeInsets.all(5.0 * _s.fontSize),
            height: 100.0,
          ),
          "strong": Style(
            fontWeight: FontWeight.w400,
          ),
          "a": Style(
            color: _highlightColor,
            textAlign: TextAlign.start,
          ),
          "li": Style(
            margin: const EdgeInsets.only(right: 10.0),
          ),
          "blockquote": Style(
            backgroundColor: Color(0xfff5fffc),
            color: Colors.black,
            fontWeight: FontWeight.w400,
            fontStyle: FontStyle.italic,
            margin: EdgeInsets.symmetric(horizontal: 0.0, vertical: 10.0),
            padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
            letterSpacing: 1.1,
            border: Border(
              left: BorderSide(
                width: 5.0,
                color: _highlightColor,
              ),
            ),
          ),
        },
        customRender: {
          'img': (renderContext, child, attributes, _) => _s.imagine
              ? GestureDetector(
                  onTap: () {
                    Navigator.of(context).push(
                      MaterialPageRoute(
                        builder: (_) => ZoomImage(
                          imageUrl: attributes["src"],
                        ),
                        settings: RouteSettings(name: "ZoomImage"),
                      ),
                    );
                  },
                  child: Center(
                    child: CachedNetworkImage(
                      placeholder: (context, url) => Container(
                        width: double.infinity,
                        height: 200.0,
                        child: SpinKitPulse(
                          color: Theme.of(context).highlightColor,
                          size: 30.0,
                        ),
                      ),
                      imageUrl: attributes['src'],
                      errorWidget: (context, url, error) => Container(),
                    ),
                  ),
                )
              : Container(),
        },
        data: content,
        onLinkTap: (String link) {
          Uri uri = Uri.parse(link);
          if (uri.host == "turkmenportal.com") {
            // open in app
            int _id = int.parse(uri.pathSegments[1]);
            String _rub = uri.pathSegments[0], _rubb = "";
            if (_rub == "blog") _rubb = "blogs";
            if (_rub == "compositions") _rubb = _rub;
            if (_rub == "catalog") _rubb = "posts";
            if (_rub == "photoreport") _rubb = "medias";

            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (BuildContext context) {
                  if (_rubb == 'medias')
                    return PhotoreportList(
                      id: _id,
                      ln: _s.ln,
                      rubrics: rubrics,
                    );
                  else
                    return DetailScreen(
                      id: _id,
                      ln: _s.ln,
                      rubrics: _rubb,
                      heroTag: _rubb + _id.toString(),
                    );
                },
                settings: RouteSettings(
                  name: _rubb == 'medias' ? "PhotoreportList" : "DetailScreen",
                ),
              ),
            );
          } else
            launchUrl(link);
        },
        onImageTap: (link) {
          Navigator.of(context).push(
            MaterialPageRoute(
              builder: (context) => ZoomImage(imageUrl: link),
              settings: RouteSettings(name: "ZoomImage"),
            ),
          );
        },
      )

@erickok
Copy link
Collaborator Author

erickok commented Feb 3, 2021

Screenshot 2021-02-03 at 21 54 07

Seems to be working just fine. Can you do a flutter clean and rebuild?

@amanokerim
Copy link

flutter clean didn't work for me.
I commented flutter_html from pubspec.yaml and tried to run, then uncommented and run. Then it started to download the latest commit. (In case this could be helpful for someone).

Thank you very much for all. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Long links are not rendered inline
4 participants