From e8201677be0b574d7129fbe49576b2e91cc32bef Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Fri, 18 Apr 2025 11:37:39 -0700 Subject: [PATCH 1/2] - --- pkgs/dartpad_ui/lib/editor/editor.dart | 3 ++- pkgs/dartpad_ui/lib/execution/execution.dart | 3 ++- pkgs/dartpad_ui/lib/html_view/_stub.dart | 21 ++++++++++++++++++++ pkgs/dartpad_ui/lib/html_view/_web.dart | 21 ++++++++++++++++++++ pkgs/dartpad_ui/lib/html_view/html_view.dart | 7 +++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 pkgs/dartpad_ui/lib/html_view/_stub.dart create mode 100644 pkgs/dartpad_ui/lib/html_view/_web.dart create mode 100644 pkgs/dartpad_ui/lib/html_view/html_view.dart diff --git a/pkgs/dartpad_ui/lib/editor/editor.dart b/pkgs/dartpad_ui/lib/editor/editor.dart index 032945ce4..6d623be19 100644 --- a/pkgs/dartpad_ui/lib/editor/editor.dart +++ b/pkgs/dartpad_ui/lib/editor/editor.dart @@ -14,6 +14,7 @@ import 'package:google_fonts/google_fonts.dart'; import 'package:pretty_diff_text/pretty_diff_text.dart'; import 'package:web/web.dart' as web; +import '../html_view/html_view.dart'; import '../local_storage/local_storage.dart'; import '../model.dart'; import 'codemirror.dart'; @@ -320,7 +321,7 @@ class _EditorWidgetState extends State implements EditorService { // LogicalKeySet(LogicalKeyboardKey.shift, LogicalKeyboardKey.escape): // VoidCallbackIntent(_focusNode.previousFocus), // }, - child: HtmlElementView( + child: DartPadHtmlView( key: _elementViewKey, viewType: _viewType, onPlatformViewCreated: diff --git a/pkgs/dartpad_ui/lib/execution/execution.dart b/pkgs/dartpad_ui/lib/execution/execution.dart index 985445a05..514a18a5d 100644 --- a/pkgs/dartpad_ui/lib/execution/execution.dart +++ b/pkgs/dartpad_ui/lib/execution/execution.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; +import '../html_view/html_view.dart'; import '../model.dart'; import '../theme.dart'; @@ -43,7 +44,7 @@ class _ExecutionWidgetState extends State { return Container( color: theme.scaffoldBackgroundColor, padding: const EdgeInsets.all(denseSpacing), - child: HtmlElementView( + child: DartPadHtmlView( key: _elementViewKey, viewType: viewType, onPlatformViewCreated: (int id) { diff --git a/pkgs/dartpad_ui/lib/html_view/_stub.dart b/pkgs/dartpad_ui/lib/html_view/_stub.dart new file mode 100644 index 000000000..4cff67b65 --- /dev/null +++ b/pkgs/dartpad_ui/lib/html_view/_stub.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; + +class DartPadHtmlViewImpl extends StatelessWidget { + final String viewType; + final void Function(int)? onPlatformViewCreated; + + const DartPadHtmlViewImpl({ + super.key, + required this.viewType, + this.onPlatformViewCreated, + }); + + @override + Widget build(BuildContext context) { + return Text('Placeholder for HtmlElementView, available on web only.'); + } +} diff --git a/pkgs/dartpad_ui/lib/html_view/_web.dart b/pkgs/dartpad_ui/lib/html_view/_web.dart new file mode 100644 index 000000000..ed3a1ddab --- /dev/null +++ b/pkgs/dartpad_ui/lib/html_view/_web.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'package:flutter/material.dart'; +import '_stub.dart' as stub; + +class DartPadHtmlViewImpl extends stub.DartPadHtmlViewImpl { + const DartPadHtmlViewImpl({ + super.key, + required super.viewType, + super.onPlatformViewCreated, + }); + + @override + Widget build(BuildContext context) => HtmlElementView( + key: key, + viewType: viewType, + onPlatformViewCreated: onPlatformViewCreated, + ); +} diff --git a/pkgs/dartpad_ui/lib/html_view/html_view.dart b/pkgs/dartpad_ui/lib/html_view/html_view.dart new file mode 100644 index 000000000..026d3df98 --- /dev/null +++ b/pkgs/dartpad_ui/lib/html_view/html_view.dart @@ -0,0 +1,7 @@ +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import '_stub.dart' if (dart.library.js_util) '_web.dart'; + +typedef DartPadHtmlView = DartPadHtmlViewImpl; From 2b07260de95644d89d15583ea415f9ef7cea2a9a Mon Sep 17 00:00:00 2001 From: Polina Cherkasova Date: Fri, 18 Apr 2025 13:27:30 -0700 Subject: [PATCH 2/2] - --- pkgs/dartpad_ui/lib/embed/embed.dart | 2 +- pkgs/dartpad_ui/lib/execution/view_factory/view_factory.dart | 2 +- pkgs/dartpad_ui/lib/html_view/html_view.dart | 2 +- pkgs/dartpad_ui/lib/local_storage/local_storage.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/dartpad_ui/lib/embed/embed.dart b/pkgs/dartpad_ui/lib/embed/embed.dart index 5ea329e28..542ca7a37 100644 --- a/pkgs/dartpad_ui/lib/embed/embed.dart +++ b/pkgs/dartpad_ui/lib/embed/embed.dart @@ -4,7 +4,7 @@ import '../model.dart'; -import '_stub.dart' if (dart.library.js_util) '_web.dart'; +import '_stub.dart' if (dart.library.js_interop) '_web.dart'; /// Listen to frame messages if embedded as an iFrame /// to accept injected snippets. diff --git a/pkgs/dartpad_ui/lib/execution/view_factory/view_factory.dart b/pkgs/dartpad_ui/lib/execution/view_factory/view_factory.dart index 4d040417d..f14509912 100644 --- a/pkgs/dartpad_ui/lib/execution/view_factory/view_factory.dart +++ b/pkgs/dartpad_ui/lib/execution/view_factory/view_factory.dart @@ -2,6 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import '_stub.dart' if (dart.library.js_util) '_web.dart'; +import '_stub.dart' if (dart.library.js_interop) '_web.dart'; void initViewFactory() => initViewFactoryImpl(); diff --git a/pkgs/dartpad_ui/lib/html_view/html_view.dart b/pkgs/dartpad_ui/lib/html_view/html_view.dart index 026d3df98..89e9a283f 100644 --- a/pkgs/dartpad_ui/lib/html_view/html_view.dart +++ b/pkgs/dartpad_ui/lib/html_view/html_view.dart @@ -2,6 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import '_stub.dart' if (dart.library.js_util) '_web.dart'; +import '_stub.dart' if (dart.library.js_interop) '_web.dart'; typedef DartPadHtmlView = DartPadHtmlViewImpl; diff --git a/pkgs/dartpad_ui/lib/local_storage/local_storage.dart b/pkgs/dartpad_ui/lib/local_storage/local_storage.dart index cc62cfd03..341edfe12 100644 --- a/pkgs/dartpad_ui/lib/local_storage/local_storage.dart +++ b/pkgs/dartpad_ui/lib/local_storage/local_storage.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import '_stub.dart' if (dart.library.js_util) '_web.dart'; +import '_stub.dart' if (dart.library.js_interop) '_web.dart'; abstract class DartPadLocalStorage { static DartPadLocalStorageImpl instance = DartPadLocalStorageImpl();