f46b82e207
Keep the Material implementation while preserving public parameters needed by callers. Remove Cupertino-only tests and variants because the app runs exclusively under MaterialApp.
58 lines
1.9 KiB
Dart
58 lines
1.9 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'artifact_fullscreen.dart';
|
|
|
|
/// Lets a viewer page open its own content as the full-screen view.
|
|
///
|
|
/// The full-screen route lives on the root navigator, outside the page's
|
|
/// subtree, yet draws from the page's state: [buildFrame] builds either
|
|
/// presentation, and every [setState] redraws the full-screen route too, so
|
|
/// paging, loading and status messages show in both.
|
|
mixin ArtifactFullscreenHost<T extends StatefulWidget> on State<T> {
|
|
final ValueNotifier<int> _revision = ValueNotifier<int>(0);
|
|
|
|
/// The full-screen view's HTML zoom; each full-screen visit starts at 1.
|
|
final ValueNotifier<double> htmlZoom = ValueNotifier<double>(1);
|
|
Route<void>? _fullscreen;
|
|
|
|
/// The page's scaffold, inline or as the full-screen view.
|
|
Widget buildFrame(BuildContext context, {required bool fullscreen});
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
super.setState(fn);
|
|
_revision.value++;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// The full-screen route closes with the page, once the tree unlocks.
|
|
final route = _fullscreen;
|
|
if (route != null) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (route.isActive) route.navigator?.removeRoute(route);
|
|
});
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
/// Opens the full-screen view; it returns when the view closes.
|
|
Future<void> enterFullscreen() async {
|
|
if (_fullscreen != null) return;
|
|
htmlZoom.value = 1;
|
|
final route = artifactFullscreenRoute(
|
|
cupertino: false,
|
|
builder: (_) => ArtifactFullscreenScope(
|
|
htmlZoom: htmlZoom,
|
|
child: ListenableBuilder(
|
|
listenable: Listenable.merge([_revision, htmlZoom]),
|
|
builder: (context, _) => buildFrame(context, fullscreen: true),
|
|
),
|
|
),
|
|
);
|
|
_fullscreen = route;
|
|
await Navigator.of(context, rootNavigator: true).push(route);
|
|
_fullscreen = null;
|
|
}
|
|
}
|