Initial commit: 91dj android client dev_1.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// ignore_for_file: undefined_class, undefined_identifier, undefined_method, uri_does_not_exist
|
||||
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
/// Dynamic JavaScript interop helpers for Dart 3.10 and WebAssembly builds.
|
||||
Object? getJsProperty(Object object, Object property) {
|
||||
final value = (object as JSObject).getProperty<JSAny?>(
|
||||
_propertyToJs(property),
|
||||
);
|
||||
return _toDartValue(value);
|
||||
}
|
||||
|
||||
bool hasJsProperty(Object object, String property) =>
|
||||
(object as JSObject).has(property);
|
||||
|
||||
Object? callJsMethod(
|
||||
Object object,
|
||||
String method, [
|
||||
List<Object?> arguments = const [],
|
||||
]) {
|
||||
final value = (object as JSObject).callMethodVarArgs<JSAny?>(
|
||||
method.toJS,
|
||||
arguments.map(_valueToJs).toList(),
|
||||
);
|
||||
return _toDartValue(value);
|
||||
}
|
||||
|
||||
Object? constructJsObject(
|
||||
Object constructor, [
|
||||
List<Object?> arguments = const [],
|
||||
]) =>
|
||||
(constructor as JSFunction).callAsConstructorVarArgs<JSObject>(
|
||||
arguments.map(_valueToJs).toList(),
|
||||
);
|
||||
|
||||
JSAny _propertyToJs(Object property) {
|
||||
if (property is String) return property.toJS;
|
||||
if (property is num) return property.toJS;
|
||||
throw ArgumentError.value(property, 'property', 'Must be a string or number');
|
||||
}
|
||||
|
||||
JSAny? _valueToJs(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is JSAny) return value;
|
||||
if (value is String) return value.toJS;
|
||||
if (value is num) return value.toJS;
|
||||
if (value is bool) return value.toJS;
|
||||
throw ArgumentError.value(value, 'value', 'Unsupported JavaScript argument');
|
||||
}
|
||||
|
||||
Object? _toDartValue(JSAny? value) {
|
||||
if (value is JSString) return value.toDart;
|
||||
if (value is JSNumber) return value.toDartDouble;
|
||||
if (value is JSBoolean) return value.toDart;
|
||||
return value;
|
||||
}
|
||||
Reference in New Issue
Block a user