|
| 1 | +import 'package:dart_eval/dart_eval_bridge.dart'; |
| 2 | +import 'package:flutter/material.dart' show TextSpan; |
| 3 | +import 'package:flutter_eval/painting.dart' show $TextStyle; |
| 4 | +import 'package:flutter_eval/src/painting/inline_span.dart'; |
| 5 | +import 'package:flutter_eval/src/sky_engine/ui/locale.dart'; |
| 6 | + |
| 7 | +/// dart_eval wrapper binding for [TextSpan] |
| 8 | +class $TextSpan implements $Instance { |
| 9 | + /// Configure this class for use in a [Runtime] |
| 10 | + static void configureForRuntime(Runtime runtime) { |
| 11 | + runtime.registerBridgeFunc( |
| 12 | + 'package:flutter/src/painting/text_span.dart', |
| 13 | + 'TextSpan.', |
| 14 | + $TextSpan.$new, |
| 15 | + ); |
| 16 | + } |
| 17 | + |
| 18 | + /// Compile-time type specification of [$TextSpan] |
| 19 | + static const $spec = BridgeTypeSpec( |
| 20 | + 'package:flutter/src/painting/text_span.dart', |
| 21 | + 'TextSpan', |
| 22 | + ); |
| 23 | + |
| 24 | + /// Compile-time type declaration of [$TextSpan] |
| 25 | + static const $type = BridgeTypeRef($spec); |
| 26 | + |
| 27 | + /// Compile-time class declaration of [$TextSpan] |
| 28 | + static const $declaration = BridgeClassDef( |
| 29 | + BridgeClassType($type, $extends: $InlineSpan.$type), |
| 30 | + constructors: { |
| 31 | + '': BridgeConstructorDef( |
| 32 | + BridgeFunctionDef( |
| 33 | + returns: BridgeTypeAnnotation($type), |
| 34 | + namedParams: [ |
| 35 | + BridgeParameter( |
| 36 | + 'text', |
| 37 | + BridgeTypeAnnotation( |
| 38 | + BridgeTypeRef(CoreTypes.string, []), |
| 39 | + nullable: true, |
| 40 | + ), |
| 41 | + true, |
| 42 | + ), |
| 43 | + BridgeParameter( |
| 44 | + 'children', |
| 45 | + BridgeTypeAnnotation( |
| 46 | + BridgeTypeRef( |
| 47 | + CoreTypes.list, [BridgeTypeAnnotation($InlineSpan.$type)]), |
| 48 | + nullable: true, |
| 49 | + ), |
| 50 | + true, |
| 51 | + ), |
| 52 | + BridgeParameter( |
| 53 | + 'style', |
| 54 | + BridgeTypeAnnotation( |
| 55 | + $TextStyle.$type, |
| 56 | + nullable: true, |
| 57 | + ), |
| 58 | + true, |
| 59 | + ), |
| 60 | + BridgeParameter( |
| 61 | + 'semanticsLabel', |
| 62 | + BridgeTypeAnnotation( |
| 63 | + BridgeTypeRef(CoreTypes.string, []), |
| 64 | + nullable: true, |
| 65 | + ), |
| 66 | + true, |
| 67 | + ), |
| 68 | + BridgeParameter( |
| 69 | + 'semanticsIdentifier', |
| 70 | + BridgeTypeAnnotation( |
| 71 | + BridgeTypeRef(CoreTypes.string, []), |
| 72 | + nullable: true, |
| 73 | + ), |
| 74 | + true, |
| 75 | + ), |
| 76 | + BridgeParameter( |
| 77 | + 'locale', |
| 78 | + BridgeTypeAnnotation($Locale.$type, nullable: true), |
| 79 | + true, |
| 80 | + ), |
| 81 | + BridgeParameter( |
| 82 | + 'spellOut', |
| 83 | + BridgeTypeAnnotation( |
| 84 | + BridgeTypeRef(CoreTypes.bool, []), |
| 85 | + nullable: true |
| 86 | + ), |
| 87 | + true, |
| 88 | + ), |
| 89 | + ], |
| 90 | + params: [], |
| 91 | + ), |
| 92 | + ), |
| 93 | + }, |
| 94 | + wrap: true, |
| 95 | + bridge: false, |
| 96 | + ); |
| 97 | + |
| 98 | + /// Wrapper for the [TextSpan.new] constructor |
| 99 | + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { |
| 100 | + return $TextSpan.wrap( |
| 101 | + TextSpan( |
| 102 | + text: args[0]?.$value, |
| 103 | + children: (args[1]?.$reified as List?)?.cast(), |
| 104 | + style: args[2]?.$value, |
| 105 | + semanticsLabel: args[3]?.$value, |
| 106 | + semanticsIdentifier: args[4]?.$value, |
| 107 | + locale: args[5]?.$value, |
| 108 | + spellOut: args[6]?.$value, |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + final $Instance _superclass; |
| 114 | + |
| 115 | + @override |
| 116 | + final TextSpan $value; |
| 117 | + |
| 118 | + @override |
| 119 | + TextSpan get $reified => $value; |
| 120 | + |
| 121 | + /// Wrap a [TextSpan] in a [$TextSpan] |
| 122 | + $TextSpan.wrap(this.$value) : _superclass = $InlineSpan.wrap($value); |
| 123 | + |
| 124 | + @override |
| 125 | + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); |
| 126 | + |
| 127 | + @override |
| 128 | + $Value? $getProperty(Runtime runtime, String identifier) { |
| 129 | + return _superclass.$getProperty(runtime, identifier); |
| 130 | + } |
| 131 | + |
| 132 | + @override |
| 133 | + void $setProperty(Runtime runtime, String identifier, $Value value) { |
| 134 | + return _superclass.$setProperty(runtime, identifier, value); |
| 135 | + } |
| 136 | +} |
0 commit comments