daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
639 stars 239 forks source link

Images cannot render on web #767

Closed glaceon2000 closed 2 years ago

glaceon2000 commented 2 years ago

Most images cannot render on web while being rendered normally on mobile Sample code:

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

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'HTML Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyStatefulWidget(),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  @override
  Widget build(BuildContext context) {
    const temp =
        r"""<h3>Network png</h3>      <img alt="Why is it no working" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">""";
    return Center(
      child: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            HtmlWidget(temp),
          ],
        ),
      ),
    );
  }
}

Result on web:

image

Result on mobile:

simulator_screenshot_54383D9D-52E9-48B5-828C-7FB97AD4AB73

daohoangson commented 2 years ago

Please check the browser console. This is most likely a CORS error.

anggaaryas commented 2 months ago

@daohoangson can you use HtmlElementView ?