From 3547e015e4156aedde21826588a8362244a37fa9 Mon Sep 17 00:00:00 2001 From: rish07 Date: Fri, 12 Feb 2021 22:59:07 +0530 Subject: [PATCH] image support added on web --- app/pubspec.lock | 2 +- lib/widgets/editor.dart | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/pubspec.lock b/app/pubspec.lock index 58320fd0..25012d30 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -82,7 +82,7 @@ packages: path: ".." relative: true source: path - version: "0.2.7" + version: "0.2.8" flutter_test: dependency: "direct dev" description: flutter diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index 36cfc378..6a388ed8 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -1,5 +1,7 @@ +import 'dart:html' as html; import 'dart:io'; import 'dart:math' as math; +import 'dart:ui' as ui; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; @@ -78,7 +80,19 @@ Widget _defaultEmbedBuilder(BuildContext context, leaf.Embed node) { switch (node.value.type) { case 'image': if (kIsWeb) { - return SizedBox.shrink(); + String imageUrl = node.value.data; + + ui.platformViewRegistry.registerViewFactory( + imageUrl, + (int viewId) => html.ImageElement()..src = imageUrl, + ); + return Container( + constraints: BoxConstraints(maxWidth: 300), + height: MediaQuery.of(context).size.height, + child: HtmlElementView( + viewType: imageUrl, + ), + ); } String imageUrl = node.value.data; return imageUrl.startsWith('http')