App: dark-aware HTML views, run cards, changed/missing file notes, one card width, dense diff rows

show_html documents that declare dark support follow the app theme; others
stay light. Tool description and skill docs say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 19:54:58 +00:00
parent d204ce3187
commit f02ff56dfe
27 changed files with 1086 additions and 61 deletions
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import '../domain/artifact_html_theme.dart';
import 'artifact_fullscreen.dart';
import 'artifact_html_view_native.dart'
if (dart.library.js_interop) 'artifact_html_view_web.dart'
@@ -16,11 +17,19 @@ typedef ArtifactHtmlBuilder =
/// live frame. The mobile web views pinch natively and offer none.
const bool artifactHtmlZoomButtons = impl.inertHtmlZoomButtons;
/// Whether a recorded HTML document at [context] is shown in the dark scheme
/// (when it supports one): the app's own theme, not the system's.
bool artifactHtmlDark(BuildContext context) =>
Theme.of(context).brightness == Brightness.dark;
/// Renders a recorded HTML document inertly: on the web in an iframe whose
/// empty `sandbox` blocks scripts, forms, popups and navigation; on Android and
/// iOS in a web view with JavaScript disabled and navigation refused. The
/// document never runs code with the app's origin or credentials.
///
/// A document that supports dark mode follows the app's theme
/// ([artifactHtmlForScheme]); any other keeps a white page.
///
/// The preview stops at the floating bars instead of passing behind them: on
/// the web the iframe is a platform view that takes every click over its
/// area, even where a bar is drawn on top, which left the viewer's actions
@@ -40,6 +49,7 @@ Widget defaultArtifactHtml(BuildContext context, String html) {
html: html,
interactive: fullscreen != null,
zoom: fullscreen?.htmlZoom,
dark: artifactHtmlDark(context),
),
),
);
@@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../domain/artifact_html_links.dart';
import '../domain/artifact_html_theme.dart';
import 'artifact_external_open.dart';
/// The mobile web views pinch-zoom natively (Android's built-in zoom, which
@@ -29,10 +30,15 @@ class InertHtmlView extends StatefulWidget {
this.interactive = false,
this.zoom,
this.openExternal = openArtifactExternally,
this.dark = false,
});
final String html;
/// Whether the app is in its dark theme: a document that supports dark mode
/// is loaded in it ([artifactHtmlForScheme]).
final bool dark;
/// Opens a link's http(s)/mailto address outside the artifact.
final ArtifactExternalOpen openExternal;
final bool interactive;
@@ -66,7 +72,9 @@ class _InertHtmlViewState extends State<InertHtmlView> {
onNavigationRequest: _decide,
),
)
..loadHtmlString(widget.html);
..loadHtmlString(_document);
String get _document => artifactHtmlForScheme(widget.html, dark: widget.dark);
/// Links: a place in the document scrolls there; an http(s)/mailto address
/// opens in the system's handler, never inside this view; anything else
@@ -91,9 +99,9 @@ class _InertHtmlViewState extends State<InertHtmlView> {
@override
void didUpdateWidget(covariant InertHtmlView oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.html != widget.html) {
if (oldWidget.html != widget.html || oldWidget.dark != widget.dark) {
_loaded = false;
_controller.loadHtmlString(widget.html);
_controller.loadHtmlString(_document);
}
}
@@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:web/web.dart' as web;
import '../domain/artifact_html_theme.dart';
import 'artifact_html_links_web.dart';
/// The frame's document cannot be pinched: a pinch over it is a page zoom,
@@ -23,6 +24,10 @@ const bool inertHtmlZoomButtons = true;
/// document reflows and still scrolls inside it. In the app, Chrome returns
/// the frame's document to its top when a zoom step resizes it.
///
/// The document follows the app's theme ([dark]) when it supports dark mode
/// ([artifactHtmlForScheme]); the frame's own `color-scheme` matches, so the
/// browser paints the page's canvas in that scheme rather than always white.
///
/// While another route covers this one (a menu, a sheet) the frame stops
/// taking pointers: a platform view takes every click over its area, even
/// where Flutter draws that menu on top.
@@ -32,10 +37,14 @@ class InertHtmlView extends StatefulWidget {
required this.html,
this.interactive = false,
this.zoom,
this.dark = false,
});
final String html;
/// Whether the app is in its dark theme.
final bool dark;
/// The full-screen view's frame. Pointers already reach the frame directly
/// on the web, inline as in full screen.
final bool interactive;
@@ -91,16 +100,20 @@ class _InertHtmlViewState extends State<InertHtmlView> {
_covered = covered;
_style();
}
final scheme = artifactHtmlScheme(widget.html, dark: widget.dark);
return HtmlElementView.fromTagName(
key: ValueKey<int>(widget.html.hashCode),
key: ValueKey<(int, String)>((widget.html.hashCode, scheme)),
tagName: 'iframe',
onElementCreated: (element) {
final frame = element as web.HTMLIFrameElement;
frame.setAttribute('sandbox', artifactHtmlSandbox);
frame.srcdoc = artifactHtmlWithInertLinks(widget.html).toJS;
frame.srcdoc = artifactHtmlWithInertLinks(
artifactHtmlForScheme(widget.html, dark: widget.dark),
).toJS;
frame.style
..border = 'none'
..backgroundColor = 'white';
..colorScheme = scheme
..backgroundColor = scheme == 'dark' ? 'Canvas' : 'white';
_frame = frame;
_style();
},