From 14a417cbf388f9a804b38c5a38bbef933343021f 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 +++++++++++++- pubspec.lock | 47 ++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/app/pubspec.lock b/app/pubspec.lock index 58320fd0e..25012d30b 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 36cfc378b..6a388ed82 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') diff --git a/pubspec.lock b/pubspec.lock index 10c6a87a8..09ae8cdc1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.5.0-nullsafety.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.3" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.1" collection: dependency: "direct main" description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.15.0-nullsafety.3" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" flutter: dependency: "direct main" description: flutter @@ -107,34 +107,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.10-nullsafety.1" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.0-nullsafety.3" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.0-nullsafety.1" pedantic: dependency: transitive description: @@ -188,42 +181,42 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.0-nullsafety.2" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0" + version: "1.10.0-nullsafety.1" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.1" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.0-nullsafety.1" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.0-nullsafety.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.2.19-nullsafety.2" tuple: dependency: "direct main" description: @@ -237,7 +230,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.0-nullsafety.3" url_launcher: dependency: "direct main" description: @@ -286,7 +279,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.0-nullsafety.3" sdks: - dart: ">=2.12.0-0.0 <3.0.0" - flutter: ">=1.22.0" + dart: ">=2.10.0-110 <2.11.0" + flutter: ">=1.22.0 <2.0.0"