Flutter_widget_from_html: Can the widgets built via 'customWidgetBuilder' go inline with the other element before and after it?

Created on 27 Sep 2020  路  3Comments  路  Source: daohoangson/flutter_widget_from_html

Most helpful comment

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

class HtmlCore extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Html Core')),
      body: HtmlWidget(
        'Hello <span class="name">World</span>!',
        factoryBuilder: () => InlineWidget(),
      ),
    );
  }
}

class InlineWidget extends WidgetFactory {
  @override
  void parse(BuildMetadata meta) {
    if (meta.element.classes.contains('name')) {
      meta.register(BuildOp(onTree: (meta, tree) => tree.replaceWith(WidgetBit.inline(tree, FlutterLogo()))));
    }
  }
}

All 3 comments

No, you'll need your own WidgetFactory for that. The
customWidgetBuilder is very simple and only supports basic use cases.

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

class HtmlCore extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Html Core')),
      body: HtmlWidget(
        'Hello <span class="name">World</span>!',
        factoryBuilder: () => InlineWidget(),
      ),
    );
  }
}

class InlineWidget extends WidgetFactory {
  @override
  void parse(BuildMetadata meta) {
    if (meta.element.classes.contains('name')) {
      meta.register(BuildOp(onTree: (meta, tree) => tree.replaceWith(WidgetBit.inline(tree, FlutterLogo()))));
    }
  }
}

Thanks @AlaaEldeenYsr

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shofi-ishraak picture shofi-ishraak  路  6Comments

ahmadkhedr picture ahmadkhedr  路  6Comments

forever84721 picture forever84721  路  4Comments

yerzhant picture yerzhant  路  7Comments

mamonraab picture mamonraab  路  7Comments