Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ab130f1

Browse files
authored
[web] Clean up lib/ui.dart (#30925)
1 parent 5b67a7d commit ab130f1

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

lib/web_ui/lib/initialization.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,61 @@ set debugEmulateFlutterTesterEnvironment(bool value) {
9595
bool _debugEmulateFlutterTesterEnvironment = false;
9696
engine.AssetManager get webOnlyAssetManager => _assetManager!;
9797
engine.FontCollection get webOnlyFontCollection => _fontCollection!;
98+
99+
/// Provides a compile time constant to customize flutter framework and other
100+
/// users of ui engine for web runtime.
101+
const bool isWeb = true;
102+
103+
/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM
104+
/// is not supported on Web platform.
105+
const int kMaxUnsignedSMI = -1;
106+
107+
void webOnlyInitializeEngine() {
108+
engine.initializeEngine();
109+
}
110+
111+
void webOnlySetPluginHandler(Future<void> Function(String, ByteData?, PlatformMessageResponseCallback?) handler) {
112+
engine.pluginMessageCallHandler = handler;
113+
}
114+
115+
// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart
116+
// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD
117+
// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine`
118+
// is migrated, we can move it back.
119+
120+
/// A function which takes a unique `id` and creates an HTML element.
121+
typedef PlatformViewFactory = html.Element Function(int viewId);
122+
123+
/// A registry for factories that create platform views.
124+
class PlatformViewRegistry {
125+
/// Register [viewTypeId] as being creating by the given [factory].
126+
bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory,
127+
{bool isVisible = true}) {
128+
// TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?)
129+
return engine.platformViewManager
130+
.registerFactory(viewTypeId, viewFactory, isVisible: isVisible);
131+
}
132+
}
133+
134+
/// The platform view registry for this app.
135+
final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry();
136+
137+
// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only
138+
// because the analyzer wasn't able to infer the correct types during
139+
// NNBD migration.
140+
typedef _Callback<T> = void Function(T result);
141+
typedef _Callbacker<T> = String? Function(_Callback<T> callback);
142+
Future<T> _futurize<T>(_Callbacker<T> callbacker) {
143+
final Completer<T> completer = Completer<T>.sync();
144+
final String? error = callbacker((T t) {
145+
if (t == null) {
146+
completer.completeError(Exception('operation failed'));
147+
} else {
148+
completer.complete(t);
149+
}
150+
});
151+
if (error != null) {
152+
throw Exception(error);
153+
}
154+
return completer.future;
155+
}

lib/web_ui/lib/ui.dart

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,61 +35,3 @@ part 'semantics.dart';
3535
part 'text.dart';
3636
part 'tile_mode.dart';
3737
part 'window.dart';
38-
39-
/// Provides a compile time constant to customize flutter framework and other
40-
/// users of ui engine for web runtime.
41-
const bool isWeb = true;
42-
43-
/// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM
44-
/// is not supported on Web platform.
45-
const int kMaxUnsignedSMI = -1;
46-
47-
void webOnlyInitializeEngine() {
48-
engine.initializeEngine();
49-
}
50-
51-
void webOnlySetPluginHandler(Future<void> Function(String, ByteData?, PlatformMessageResponseCallback?) handler) {
52-
engine.pluginMessageCallHandler = handler;
53-
}
54-
55-
// TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart
56-
// during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD
57-
// does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine`
58-
// is migrated, we can move it back.
59-
60-
/// A function which takes a unique `id` and creates an HTML element.
61-
typedef PlatformViewFactory = html.Element Function(int viewId);
62-
63-
/// A registry for factories that create platform views.
64-
class PlatformViewRegistry {
65-
/// Register [viewTypeId] as being creating by the given [factory].
66-
bool registerViewFactory(String viewTypeId, PlatformViewFactory viewFactory,
67-
{bool isVisible = true}) {
68-
// TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?)
69-
return engine.platformViewManager
70-
.registerFactory(viewTypeId, viewFactory, isVisible: isVisible);
71-
}
72-
}
73-
74-
/// The platform view registry for this app.
75-
final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry();
76-
77-
// TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only
78-
// because the analyzer wasn't able to infer the correct types during
79-
// NNBD migration.
80-
typedef _Callback<T> = void Function(T result);
81-
typedef _Callbacker<T> = String? Function(_Callback<T> callback);
82-
Future<T> _futurize<T>(_Callbacker<T> callbacker) {
83-
final Completer<T> completer = Completer<T>.sync();
84-
final String? error = callbacker((T t) {
85-
if (t == null) {
86-
completer.completeError(Exception('operation failed'));
87-
} else {
88-
completer.complete(t);
89-
}
90-
});
91-
if (error != null) {
92-
throw Exception(error);
93-
}
94-
return completer.future;
95-
}

0 commit comments

Comments
 (0)