Skip to content

[BUG] Simple non-wrapped children are not rendered #1252

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

Closed
michalsrutek opened this issue May 8, 2023 · 1 comment · Fixed by #1273
Closed

[BUG] Simple non-wrapped children are not rendered #1252

michalsrutek opened this issue May 8, 2023 · 1 comment · Fixed by #1273
Labels
bug Something isn't working extensions
Milestone

Comments

@michalsrutek
Copy link
Contributor

Describe the bug:

When using customRenders, simple non-wrapped text does not get rendered. It has to be wrapped in p, span or similar.

HTML to reproduce the issue:

<custom>Hello <span>there</span> <test></test> <p>new</p></custom>

Html widget configuration:

import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

class HtmlApp extends StatelessWidget {
  const HtmlApp({super.key});

  final _testTag = 'test';
  final _customWrapperTag = 'custom';

  CustomRender _testRender() {
    return CustomRender.widget(widget: (_, __) {
      return const Icon(Icons.abc);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('HTML example'),
        ),
        body: Html(
          data:
              '<custom>Hello <span>there</span> <test></test> <p>new</p></custom>',
          customRenders: {
            tagMatcher(_testTag): _testRender(),
            tagMatcher(_customWrapperTag): fallbackRender(),
          },
          tagsList: Html.tags
            ..addAll([
              _testTag,
              _customWrapperTag,
            ]),
        ),
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

Expected behavior:

I would expect the word Hello to be rendered. But it is not - as it does not appear in the buildChildren function. If I comment out the following line, it works as expected.

tagMatcher(_customWrapperTag): fallbackRender(),

Is this the correct behavior - am I just missing something?

Screenshots:

Expected Actual
Simulator Screen Shot - iPhone 14 Pro - 2023-05-08 at 12 13 19 Simulator Screen Shot - iPhone 14 Pro - 2023-05-08 at 12 13 27

Device details and Flutter/Dart/flutter_html versions:

  • Device: any
  • Flutter 3.7.12
  • Dart 2.19.6
  • flutter_html 3.0.0-alpha.6
@michalsrutek michalsrutek added the bug Something isn't working label May 8, 2023
@Sub6Resources Sub6Resources added the in-triage Issue's that I've seen but haven't had a chance to thoroughly review and/or categorize label May 9, 2023
@Sub6Resources Sub6Resources added this to the 3.0.0 milestone May 18, 2023
@Sub6Resources Sub6Resources added extensions and removed in-triage Issue's that I've seen but haven't had a chance to thoroughly review and/or categorize labels May 18, 2023
@Sub6Resources
Copy link
Owner

Once #1273 is merged, this is the proper way to get your expected behavior (in 3.0.0-beta.1 the API made accessing the children difficult):

    return Html(
      data: "<custom>Hello <span>there</span> <test></test> <p>new</p></custom>",
      extensions: [
        TagExtension(tagsToExtend: {"test"}, child: const Icon(Icons.abc)),
        TagExtension.inline(
          tagsToExtend: {"custom"},
          builder: (extContext) {
            return TextSpan(children: extContext.inlineSpanChildren!);
          },
        ),
      ],
    );

Still working on some better documentation!

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

Successfully merging a pull request may close this issue.

2 participants