From ac0b57365d715a2c76cf544976015f25201c3774 Mon Sep 17 00:00:00 2001 From: tanay Date: Wed, 5 May 2021 17:58:24 -0400 Subject: [PATCH] Add shim for dart:ui (increase pub score) --- lib/shims/dart_ui.dart | 10 ++++++++++ lib/shims/dart_ui_fake.dart | 19 +++++++++++++++++++ lib/shims/dart_ui_real.dart | 5 +++++ lib/src/widgets/iframe_web.dart | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/shims/dart_ui.dart create mode 100644 lib/shims/dart_ui_fake.dart create mode 100644 lib/shims/dart_ui_real.dart diff --git a/lib/shims/dart_ui.dart b/lib/shims/dart_ui.dart new file mode 100644 index 0000000000..bce4ad1b17 --- /dev/null +++ b/lib/shims/dart_ui.dart @@ -0,0 +1,10 @@ +// Copyright 2019 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// This file shims dart:ui in web-only scenarios, getting rid of the need to +/// suppress analyzer warnings. + +// TODO: flutter/flutter#55000 Remove this file once web-only dart:ui APIs +// are exposed from a dedicated place. +export 'dart_ui_fake.dart' if (dart.library.html) 'dart_ui_real.dart'; diff --git a/lib/shims/dart_ui_fake.dart b/lib/shims/dart_ui_fake.dart new file mode 100644 index 0000000000..4e528a7337 --- /dev/null +++ b/lib/shims/dart_ui_fake.dart @@ -0,0 +1,19 @@ +// Copyright 2019 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Fake interface for the logic that this package needs from (web-only) dart:ui. +// This is conditionally exported so the analyzer sees these methods as available. + +/// Shim for web_ui engine.PlatformViewRegistry +/// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L62 +// ignore: camel_case_types +class platformViewRegistry { + /// Shim for registerViewFactory + /// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L72 + static void registerViewFactory( + String viewTypeId, dynamic Function(int viewId) viewFactory) {} +} + +/// Signature of callbacks that have no arguments and return no data. +typedef VoidCallback = void Function(); diff --git a/lib/shims/dart_ui_real.dart b/lib/shims/dart_ui_real.dart new file mode 100644 index 0000000000..90ecd7d002 --- /dev/null +++ b/lib/shims/dart_ui_real.dart @@ -0,0 +1,5 @@ +// Copyright 2019 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'dart:ui'; diff --git a/lib/src/widgets/iframe_web.dart b/lib/src/widgets/iframe_web.dart index a70de148da..6e2ec6e9a1 100644 --- a/lib/src/widgets/iframe_web.dart +++ b/lib/src/widgets/iframe_web.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_html/html_parser.dart'; +import 'package:flutter_html/shims/dart_ui.dart' as ui; import 'package:flutter_html/src/replaced_element.dart'; import 'package:flutter_html/src/utils.dart'; import 'package:flutter_html/style.dart'; @@ -7,7 +8,6 @@ import 'package:webview_flutter/webview_flutter.dart'; import 'package:html/dom.dart' as dom; // ignore: avoid_web_libraries_in_flutter import 'dart:html' as html; -import 'dart:ui' as ui; /// [IframeContentElement is a [ReplacedElement] with web content. class IframeContentElement extends ReplacedElement {