From 6ba28825b3e1a98b7a61d44783f7f7958ec5d6b9 Mon Sep 17 00:00:00 2001 From: Ilya Zverev Date: Wed, 14 Jan 2026 23:43:01 +0200 Subject: [PATCH 1/2] MaterialButton, Autocomplete, and related widgets. Does not work yet --- lib/flutter_eval.dart | 84 +- lib/material.dart | 3 + lib/services.dart | 1 + lib/src/material.dart | 3 + lib/src/material/autocomplete.dart | 486 ++++++++++++ lib/src/material/button_theme.dart | 78 ++ lib/src/material/material_button.dart | 428 ++++++++++ lib/src/services.dart | 1 + lib/src/services/text_input.dart | 1059 +++++++++++++++++++++++++ lib/src/sky_engine/ui/text.dart | 269 +++++++ lib/src/widgets.dart | 1 + lib/src/widgets/autocomplete.dart | 495 ++++++++++++ lib/widgets.dart | 1 + test/flutter_eval_test.dart | 93 +++ 14 files changed, 2975 insertions(+), 27 deletions(-) create mode 100644 lib/src/material/autocomplete.dart create mode 100644 lib/src/material/button_theme.dart create mode 100644 lib/src/material/material_button.dart create mode 100644 lib/src/services/text_input.dart create mode 100644 lib/src/widgets/autocomplete.dart diff --git a/lib/flutter_eval.dart b/lib/flutter_eval.dart index d5a8812..090a304 100644 --- a/lib/flutter_eval.dart +++ b/lib/flutter_eval.dart @@ -22,9 +22,11 @@ import 'package:flutter_eval/src/gestures/velocity_tracker.dart'; import 'package:flutter_eval/src/material.dart'; import 'package:flutter_eval/src/material/app.dart'; import 'package:flutter_eval/src/material/app_bar.dart'; +import 'package:flutter_eval/src/material/autocomplete.dart'; import 'package:flutter_eval/src/material/bottom_sheet.dart'; import 'package:flutter_eval/src/material/button_style.dart'; import 'package:flutter_eval/src/material/button_style_button.dart'; +import 'package:flutter_eval/src/material/button_theme.dart'; import 'package:flutter_eval/src/material/card.dart'; import 'package:flutter_eval/src/material/colors.dart'; import 'package:flutter_eval/src/material/drawer.dart'; @@ -34,6 +36,7 @@ import 'package:flutter_eval/src/material/icon_button.dart'; import 'package:flutter_eval/src/material/icons.dart'; import 'package:flutter_eval/src/material/ink_well.dart'; import 'package:flutter_eval/src/material/list_tile.dart'; +import 'package:flutter_eval/src/material/material_button.dart'; import 'package:flutter_eval/src/material/page.dart'; import 'package:flutter_eval/src/material/scaffold.dart'; import 'package:flutter_eval/src/material/snack_bar.dart'; @@ -73,6 +76,7 @@ import 'package:flutter_eval/src/sky_engine/ui/text.dart'; import 'package:flutter_eval/src/sky_engine/ui/ui.dart'; import 'package:flutter_eval/src/widgets.dart'; import 'package:flutter_eval/src/widgets/app.dart'; +import 'package:flutter_eval/src/widgets/autocomplete.dart'; import 'package:flutter_eval/src/widgets/basic.dart'; import 'package:flutter_eval/src/widgets/container.dart'; import 'package:flutter_eval/src/widgets/editable_text.dart'; @@ -104,7 +108,7 @@ class FlutterEvalPlugin implements EvalPlugin { @override void configureForCompile(BridgeDeclarationRegistry registry) { - final classes = [ + final classes = [ $Widget.$declaration, $StatelessWidget$bridge.$declaration, $StatefulWidget$bridge.$declaration, @@ -250,38 +254,54 @@ class FlutterEvalPlugin implements EvalPlugin { $KeyRepeatEvent.$declaration, $BottomSheet.$declaration, $SafeArea.$declaration, + $TextRange.$declaration, + $RawAutocomplete.$declaration, + $TextInputType.$declaration, + $TextEditingValue.$declaration, + $Autocomplete.$declaration, + $MaterialButton.$declaration, ]; for (final cls in classes) { registry.defineBridgeClass(cls); } - registry.defineBridgeEnum($MainAxisAlignment.$declaration); - registry.defineBridgeEnum($CrossAxisAlignment.$declaration); - registry.defineBridgeEnum($MainAxisSize.$declaration); - registry.defineBridgeEnum($FontWeight.$declaration); - registry.defineBridgeEnum($FontStyle.$declaration); - registry.defineBridgeEnum($TextDirection.$declaration); - registry.defineBridgeEnum($VerticalDirection.$declaration); - registry.defineBridgeEnum($TextBaseline.$declaration); - registry.defineBridgeEnum($Axis.$declaration); - registry.defineBridgeEnum($BorderStyle.$declaration); - registry.defineBridgeEnum($BoxFit.$declaration); - registry.defineBridgeEnum($FilterQuality.$declaration); - registry.defineBridgeEnum($PointerDeviceKind.$declaration); - registry.defineBridgeEnum($HitTestBehavior.$declaration); - registry.defineBridgeEnum($Clip.$declaration); - registry.defineBridgeEnum($StackFit.$declaration); - registry.defineBridgeEnum($AnimationStatus.$declaration); - registry.defineBridgeEnum($ColorSpace.$declaration); - registry.defineBridgeEnum($DiagnosticLevel.$declaration); - registry.defineBridgeEnum($DiagnosticsTreeStyle.$declaration); - registry.defineBridgeEnum($KeyEventResult.$declaration); - registry.defineBridgeEnum($FocusHighlightMode.$declaration); - registry.defineBridgeEnum($MaterialTapTargetSize.$declaration); - registry.defineBridgeEnum($IconAlignment.$declaration); - registry.defineBridgeEnum($WidgetState.$declaration); - registry.defineBridgeEnum($KeyEventResult.$declaration); + final enums = [ + $MainAxisAlignment.$declaration, + $CrossAxisAlignment.$declaration, + $MainAxisSize.$declaration, + $FontWeight.$declaration, + $FontStyle.$declaration, + $TextDirection.$declaration, + $VerticalDirection.$declaration, + $TextBaseline.$declaration, + $Axis.$declaration, + $BorderStyle.$declaration, + $BoxFit.$declaration, + $FilterQuality.$declaration, + $PointerDeviceKind.$declaration, + $HitTestBehavior.$declaration, + $Clip.$declaration, + $StackFit.$declaration, + $AnimationStatus.$declaration, + $ColorSpace.$declaration, + $DiagnosticLevel.$declaration, + $DiagnosticsTreeStyle.$declaration, + $KeyEventResult.$declaration, + $FocusHighlightMode.$declaration, + $MaterialTapTargetSize.$declaration, + $IconAlignment.$declaration, + $WidgetState.$declaration, + $KeyEventResult.$declaration, + $TextInputAction.$declaration, + $TextCapitalization.$declaration, + $ButtonTextTheme.$declaration, + $OptionsViewOpenDirection.$declaration, + ]; + + for (final cls in enums) { + registry.defineBridgeEnum(cls); + } registry.defineBridgeTopLevelFunction($showModalBottomSheetFn.$declaration); @@ -383,6 +403,16 @@ class FlutterEvalPlugin implements EvalPlugin { $IconAlignment.configureForRuntime(runtime); $BottomSheet.configureForRuntime(runtime); $SafeArea.configureForRuntime(runtime); + $TextRange.configureForRuntime(runtime); + $RawAutocomplete.configureForRuntime(runtime); + $TextInputType.configureForRuntime(runtime); + $TextInputAction.configureForRuntime(runtime); + $TextCapitalization.configureForRuntime(runtime); + $TextEditingValue.configureForRuntime(runtime); + $ButtonTextTheme.configureForRuntime(runtime); + $Autocomplete.configureForRuntime(runtime); + $MaterialButton.configureForRuntime(runtime); + $OptionsViewOpenDirection.configureForRuntime(runtime); $showModalBottomSheetFn.configureForRuntime(runtime); diff --git a/lib/material.dart b/lib/material.dart index 76f2ca8..ac4081c 100644 --- a/lib/material.dart +++ b/lib/material.dart @@ -3,9 +3,11 @@ library; export 'src/material/app.dart'; export 'src/material/app_bar.dart'; +export 'src/material/autocomplete.dart'; export 'src/material/bottom_sheet.dart'; export 'src/material/button_style.dart'; export 'src/material/button_style_button.dart'; +export 'src/material/button_theme.dart'; export 'src/material/card.dart'; export 'src/material/colors.dart'; export 'src/material/drawer.dart'; @@ -14,6 +16,7 @@ export 'src/material/floating_action_button.dart'; export 'src/material/icons.dart'; export 'src/material/icon_button.dart'; export 'src/material/list_tile.dart'; +export 'src/material/material_button.dart'; export 'src/material/switch_list_tile.dart'; export 'src/material/page.dart'; export 'src/material/scaffold.dart'; diff --git a/lib/services.dart b/lib/services.dart index 33f4e0e..1c9f17a 100644 --- a/lib/services.dart +++ b/lib/services.dart @@ -5,3 +5,4 @@ export 'src/services/hardware_keyboard.dart'; export 'src/services/keyboard_key.g.dart'; export 'src/services/message_codec.dart'; export 'src/services/platform_channel.dart'; +export 'src/services/text_input.dart'; diff --git a/lib/src/material.dart b/lib/src/material.dart index 758558f..f23a4ca 100644 --- a/lib/src/material.dart +++ b/lib/src/material.dart @@ -4,9 +4,11 @@ library material; export 'widgets.dart'; export 'src/material/app.dart'; export 'src/material/app_bar.dart'; +export 'src/material/autocomplete.dart'; export 'src/material/bottom_sheet.dart'; export 'src/material/button_style.dart'; export 'src/material/button_style_button.dart'; +export 'src/material/button_theme.dart'; export 'src/material/card.dart'; export 'src/material/colors.dart'; export 'src/material/drawer.dart'; @@ -15,6 +17,7 @@ export 'src/material/floating_action_button.dart'; export 'src/material/icons.dart'; export 'src/material/icon_button.dart'; export 'src/material/list_tile.dart'; +export 'src/material/material_button.dart'; export 'src/material/switch_list_tile.dart'; export 'src/material/page.dart'; export 'src/material/scaffold.dart'; diff --git a/lib/src/material/autocomplete.dart b/lib/src/material/autocomplete.dart new file mode 100644 index 0000000..91cf4fb --- /dev/null +++ b/lib/src/material/autocomplete.dart @@ -0,0 +1,486 @@ +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_eval/services.dart'; + +/// dart_eval wrapper binding for [Autocomplete] +class $Autocomplete implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'package:flutter/src/material/autocomplete.dart', + 'Autocomplete.', + $Autocomplete.$new, + ); + } + + /// Compile-time type specification of [$Autocomplete] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/material/autocomplete.dart', + 'Autocomplete', + ); + + /// Compile-time type declaration of [$Autocomplete] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$Autocomplete] + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + generics: { + 'T': BridgeGenericParam($extends: BridgeTypeRef(CoreTypes.object, [])), + }, + $extends: BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'StatelessWidget', + ), + [], + ), + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'key', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/foundation/key.dart', + 'Key', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'optionsBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [ + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + ]), + ), + ]), + ), + params: [ + BridgeParameter( + 'textEditingValue', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + ), + false, + ), + ], + namedParams: [], + ), + ), + ), + false, + ), + BridgeParameter( + 'displayStringForOption', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.string, []), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + ), + true, + ), + BridgeParameter( + 'fieldViewBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'Widget', + ), + [], + ), + ), + params: [ + BridgeParameter( + 'context', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'BuildContext', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'textEditingController', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/editable_text.dart', + 'TextEditingController', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'focusNode', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/focus_manager.dart', + 'FocusNode', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'onFieldSubmitted', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [], + namedParams: [], + ), + ), + ), + false, + ), + ], + namedParams: [], + ), + ), + ), + true, + ), + BridgeParameter( + 'focusNode', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/focus_manager.dart', + 'FocusNode', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'onSelected', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'optionsMaxHeight', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.double, [])), + true, + ), + BridgeParameter( + 'optionsViewBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'Widget', + ), + [], + ), + ), + params: [ + BridgeParameter( + 'context', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'BuildContext', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'onSelected', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + ), + false, + ), + BridgeParameter( + 'options', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + ]), + ), + false, + ), + ], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'optionsViewOpenDirection', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/autocomplete.dart', + 'OptionsViewOpenDirection', + ), + [], + ), + ), + true, + ), + BridgeParameter( + 'textEditingController', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/editable_text.dart', + 'TextEditingController', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'initialValue', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + nullable: true, + ), + true, + ), + ], + params: [], + ), + isFactory: false, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [Autocomplete.new] constructor + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { + if (args[3] == null) { + return $Autocomplete.wrap( + Autocomplete( + key: args[0]?.$value, + optionsBuilder: (TextEditingValue textEditingValue) async { + final future = (args[1]! as EvalCallable)(runtime, null, [ + $TextEditingValue.wrap(textEditingValue), + ]); + final value = await (future as Future); + return value; + }, + displayStringForOption: args[2] == null + ? RawAutocomplete.defaultStringForOption + : (dynamic option) { + return (args[2]! as EvalCallable?)?.call(runtime, null, [ + option is $Value ? option : $Object(option), + ])?.$value; + }, + focusNode: args[4]?.$value, + onSelected: args[5] == null + ? null + : (dynamic option) { + (args[5]! as EvalCallable?) + ?.call(runtime, null, [option is $Value ? option : $Object(option)]); + }, + optionsMaxHeight: args[6]?.$value ?? 200.0, + optionsViewBuilder: args[7] == null + ? null + : ( + BuildContext context, + void Function(Object option) onSelected, + Iterable options, + ) { + return (args[7]! as EvalCallable?)?.call(runtime, null, [ + runtime.wrapAlways(context), + $Function((runtime, target, args) { + onSelected(args[0]!.$value); + return const $null(); + }), + $Iterable.wrap(options), + ])?.$value; + }, + optionsViewOpenDirection: + args[8]?.$value ?? OptionsViewOpenDirection.down, + textEditingController: args[9]?.$value, + initialValue: args[10]?.$value, + ), + ); + } else { + return $Autocomplete.wrap( + Autocomplete( + key: args[0]?.$value, + optionsBuilder: (TextEditingValue textEditingValue) { + return (args[1]! as EvalCallable)(runtime, null, [ + $TextEditingValue.wrap(textEditingValue), + ])?.$value; + }, + displayStringForOption: args[2] == null + ? RawAutocomplete.defaultStringForOption + : (dynamic option) { + return (args[2]! as EvalCallable?)?.call(runtime, null, [ + $Object(option), + ])?.$value; + }, + fieldViewBuilder: ( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + void Function() onFieldSubmitted, + ) { + return (args[3]! as EvalCallable?)?.call(runtime, null, [ + runtime.wrapAlways(context), + runtime.wrapAlways(textEditingController), + runtime.wrapAlways(focusNode), + $Function((runtime, target, args) { + onFieldSubmitted(); + return const $null(); + }), + ])?.$value; + }, + focusNode: args[4]?.$value, + onSelected: args[5] == null + ? null + : (dynamic option) { + (args[5]! as EvalCallable?) + ?.call(runtime, null, [$Object(option)]); + }, + optionsMaxHeight: args[6]?.$value ?? 200.0, + optionsViewBuilder: args[7] == null + ? null + : ( + BuildContext context, + void Function(Object option) onSelected, + Iterable options, + ) { + return (args[7]! as EvalCallable?)?.call(runtime, null, [ + runtime.wrapAlways(context), + $Function((runtime, target, args) { + onSelected(args[0]!.$value); + return const $null(); + }), + $Iterable.wrap(options), + ])?.$value; + }, + optionsViewOpenDirection: + args[8]?.$value ?? OptionsViewOpenDirection.down, + textEditingController: args[9]?.$value, + initialValue: args[10]?.$value, + ), + ); + } + } + + @override + final Autocomplete $value; + + @override + Autocomplete get $reified => $value; + + /// Wrap a [Autocomplete] in a [$Autocomplete] + $Autocomplete.wrap(this.$value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + throw UnimplementedError(); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + throw UnimplementedError(); + } +} diff --git a/lib/src/material/button_theme.dart b/lib/src/material/button_theme.dart new file mode 100644 index 0000000..15d9c1a --- /dev/null +++ b/lib/src/material/button_theme.dart @@ -0,0 +1,78 @@ +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:flutter/material.dart' show ButtonTextTheme; + +/// dart_eval enum wrapper binding for [ButtonTextTheme] +class $ButtonTextTheme implements $Instance { + /// Configure this enum for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeEnumValues( + 'package:flutter/src/material/button_theme.dart', + 'ButtonTextTheme', + $ButtonTextTheme._$values, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/material/button_theme.dart', + 'ButtonTextTheme.values*g', + $ButtonTextTheme.$values, + ); + } + + /// Compile-time type specification of [$ButtonTextTheme] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/material/button_theme.dart', + 'ButtonTextTheme', + ); + + /// Compile-time type declaration of [$ButtonTextTheme] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$ButtonTextTheme] + static const $declaration = BridgeEnumDef( + $type, + + values: ['normal', 'accent', 'primary'], + + methods: {}, + getters: {}, + setters: {}, + fields: {}, + ); + + static final _$values = { + 'normal': $ButtonTextTheme.wrap(ButtonTextTheme.normal), + 'accent': $ButtonTextTheme.wrap(ButtonTextTheme.accent), + 'primary': $ButtonTextTheme.wrap(ButtonTextTheme.primary), + }; + + /// Wrapper for the [ButtonTextTheme.values] getter + static $Value? $values(Runtime runtime, $Value? target, List<$Value?> args) { + final value = ButtonTextTheme.values; + return $List.view(value, (e) => $ButtonTextTheme.wrap(e)); + } + + final $Instance _superclass; + + @override + final ButtonTextTheme $value; + + @override + ButtonTextTheme get $reified => $value; + + /// Wrap a [ButtonTextTheme] in a [$ButtonTextTheme] + $ButtonTextTheme.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + return _superclass.$getProperty(runtime, identifier); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} diff --git a/lib/src/material/material_button.dart b/lib/src/material/material_button.dart new file mode 100644 index 0000000..0013249 --- /dev/null +++ b/lib/src/material/material_button.dart @@ -0,0 +1,428 @@ +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:flutter/material.dart' show MaterialButton, Clip; + +/// dart_eval wrapper binding for [MaterialButton] +class $MaterialButton implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'package:flutter/src/material/material_button.dart', + 'MaterialButton.', + $MaterialButton.$new, + ); + } + + /// Compile-time type specification of [$MaterialButton] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/material/material_button.dart', + 'MaterialButton', + ); + + /// Compile-time type declaration of [$MaterialButton] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$MaterialButton] + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + $extends: BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'StatelessWidget', + ), + [], + ), + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'key', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/foundation/key.dart', + 'Key', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'onPressed', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [], + namedParams: [], + ), + ), + nullable: true, + ), + false, + ), + BridgeParameter( + 'onLongPress', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'onHighlightChanged', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [ + BridgeParameter( + 'value', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + false, + ), + ], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'textTheme', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/material/button_theme.dart', + 'ButtonTextTheme', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'textColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'disabledTextColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'color', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'disabledColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'focusColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'hoverColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'highlightColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'splashColor', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Color'), []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'elevation', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'focusElevation', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'hoverElevation', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'highlightElevation', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'disabledElevation', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'padding', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/painting/edge_insets.dart', + 'EdgeInsetsGeometry', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'visualDensity', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/material/theme_data.dart', + 'VisualDensity', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'shape', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/painting/borders.dart', + 'ShapeBorder', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'clipBehavior', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'Clip'), []), + ), + true, + ), + BridgeParameter( + 'focusNode', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/focus_manager.dart', + 'FocusNode', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'autofocus', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + true, + ), + BridgeParameter( + 'materialTapTargetSize', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/material/theme_data.dart', + 'MaterialTapTargetSize', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'animationDuration', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.duration, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'minWidth', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'height', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.double, []), + nullable: true, + ), + true, + ), + BridgeParameter( + 'enableFeedback', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + true, + ), + BridgeParameter( + 'child', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'Widget', + ), + [], + ), + nullable: true, + ), + true, + ), + ], + params: [], + ), + isFactory: false, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [MaterialButton.new] constructor + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { + return $MaterialButton.wrap( + MaterialButton( + key: args[0]?.$value, + onPressed: () { + (args[1]! as EvalCallable)(runtime, null, []); + }, + onLongPress: () { + (args[2]! as EvalCallable?)?.call(runtime, null, []); + }, + onHighlightChanged: (bool value) { + (args[3]! as EvalCallable?)?.call(runtime, null, [$bool(value)]); + }, + textTheme: args[4]?.$value, + textColor: args[5]?.$value, + disabledTextColor: args[6]?.$value, + color: args[7]?.$value, + disabledColor: args[8]?.$value, + focusColor: args[9]?.$value, + hoverColor: args[10]?.$value, + highlightColor: args[11]?.$value, + splashColor: args[12]?.$value, + elevation: args[13]?.$value, + focusElevation: args[14]?.$value, + hoverElevation: args[15]?.$value, + highlightElevation: args[16]?.$value, + disabledElevation: args[17]?.$value, + padding: args[18]?.$value, + visualDensity: args[19]?.$value, + shape: args[20]?.$value, + clipBehavior: args[21]?.$value ?? Clip.none, + focusNode: args[22]?.$value, + autofocus: args[23]?.$value ?? false, + materialTapTargetSize: args[24]?.$value, + animationDuration: args[25]?.$value, + minWidth: args[26]?.$value, + height: args[27]?.$value, + enableFeedback: args[28]?.$value ?? true, + child: args[29]?.$value, + ), + ); + } + + @override + final MaterialButton $value; + + @override + MaterialButton get $reified => $value; + + /// Wrap a [MaterialButton] in a [$MaterialButton] + $MaterialButton.wrap(this.$value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + throw UnimplementedError(); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + throw UnimplementedError(); + } +} diff --git a/lib/src/services.dart b/lib/src/services.dart index c91f3cc..b2eb62c 100644 --- a/lib/src/services.dart +++ b/lib/src/services.dart @@ -6,4 +6,5 @@ export 'src/services/hardware_keyboard.dart'; export 'src/services/keyboard_key.g.dart'; export 'src/services/message_codec.dart'; export 'src/services/platform_channel.dart'; +export 'src/services/text_input.dart'; '''; diff --git a/lib/src/services/text_input.dart b/lib/src/services/text_input.dart new file mode 100644 index 0000000..4523055 --- /dev/null +++ b/lib/src/services/text_input.dart @@ -0,0 +1,1059 @@ +// ignore_for_file: no_leading_underscores_for_local_identifiers + +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_eval/ui.dart'; + +/// dart_eval wrapper binding for [TextInputType] +class $TextInputType implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.numberWithOptions', + $TextInputType.$numberWithOptions, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.text*g', + $TextInputType.$text, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.multiline*g', + $TextInputType.$multiline, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.number*g', + $TextInputType.$number, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.phone*g', + $TextInputType.$phone, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.datetime*g', + $TextInputType.$datetime, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.emailAddress*g', + $TextInputType.$emailAddress, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.url*g', + $TextInputType.$url, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.visiblePassword*g', + $TextInputType.$visiblePassword, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.name*g', + $TextInputType.$name, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.streetAddress*g', + $TextInputType.$streetAddress, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.none*g', + $TextInputType.$none, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.webSearch*g', + $TextInputType.$webSearch, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.twitter*g', + $TextInputType.$twitter, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputType.values*g', + $TextInputType.$values, + ); + } + + /// Compile-time type specification of [$TextInputType] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ); + + /// Compile-time type declaration of [$TextInputType] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$TextInputType] + static const $declaration = BridgeClassDef( + BridgeClassType($type), + constructors: { + 'numberWithOptions': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'signed', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.bool, []), + nullable: true, + ), + true, + ), + + BridgeParameter( + 'decimal', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.bool, []), + nullable: true, + ), + true, + ), + ], + params: [], + ), + isFactory: false, + ), + }, + + methods: { + 'toJson': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.dynamic)), + ]), + ), + namedParams: [], + params: [], + ), + ), + }, + getters: {}, + setters: {}, + fields: { + 'index': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + isStatic: false, + ), + + 'signed': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), nullable: true), + isStatic: false, + ), + + 'decimal': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, []), nullable: true), + isStatic: false, + ), + + 'text': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'multiline': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'number': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'phone': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'datetime': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'emailAddress': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'url': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'visiblePassword': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'name': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'streetAddress': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'none': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'webSearch': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'twitter': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + isStatic: true, + ), + + 'values': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.list, [ + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputType', + ), + [], + ), + ), + ]), + ), + isStatic: true, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [TextInputType.numberWithOptions] constructor + static $Value? $numberWithOptions( + Runtime runtime, + $Value? thisValue, + List<$Value?> args, + ) { + return $TextInputType.wrap( + TextInputType.numberWithOptions( + signed: args[0]?.$value ?? false, + decimal: args[1]?.$value ?? false, + ), + ); + } + + /// Wrapper for the [TextInputType.text] getter + static $Value? $text(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.text; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.multiline] getter + static $Value? $multiline( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.multiline; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.number] getter + static $Value? $number(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.number; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.phone] getter + static $Value? $phone(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.phone; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.datetime] getter + static $Value? $datetime( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.datetime; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.emailAddress] getter + static $Value? $emailAddress( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.emailAddress; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.url] getter + static $Value? $url(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.url; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.visiblePassword] getter + static $Value? $visiblePassword( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.visiblePassword; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.name] getter + static $Value? $name(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.name; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.streetAddress] getter + static $Value? $streetAddress( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.streetAddress; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.none] getter + static $Value? $none(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.none; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.webSearch] getter + static $Value? $webSearch( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final value = TextInputType.webSearch; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.twitter] getter + static $Value? $twitter(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.twitter; + return $TextInputType.wrap(value); + } + + /// Wrapper for the [TextInputType.values] getter + static $Value? $values(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputType.values; + return $List.view(value, (e) => $TextInputType.wrap(e)); + } + + final $Instance _superclass; + + @override + final TextInputType $value; + + @override + TextInputType get $reified => $value; + + /// Wrap a [TextInputType] in a [$TextInputType] + $TextInputType.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + switch (identifier) { + case 'index': + final _index = $value.index; + return $int(_index); + + case 'signed': + final _signed = $value.signed; + return _signed == null ? const $null() : $bool(_signed); + + case 'decimal': + final _decimal = $value.decimal; + return _decimal == null ? const $null() : $bool(_decimal); + case 'toJson': + return __toJson; + } + return _superclass.$getProperty(runtime, identifier); + } + + static const $Function __toJson = $Function(_toJson); + static $Value? _toJson(Runtime runtime, $Value? target, List<$Value?> args) { + final self = target! as $TextInputType; + final result = self.$value.toJson(); + return $Map.wrap(result); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} + +/// dart_eval enum wrapper binding for [TextInputAction] +class $TextInputAction implements $Instance { + /// Configure this enum for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeEnumValues( + 'package:flutter/src/services/text_input.dart', + 'TextInputAction', + $TextInputAction._$values, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextInputAction.values*g', + $TextInputAction.$values, + ); + } + + /// Compile-time type specification of [$TextInputAction] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextInputAction', + ); + + /// Compile-time type declaration of [$TextInputAction] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$TextInputAction] + static const $declaration = BridgeEnumDef( + $type, + + values: [ + 'none', + 'unspecified', + 'done', + 'go', + 'search', + 'send', + 'next', + 'previous', + 'continueAction', + 'join', + 'route', + 'emergencyCall', + 'newline', + ], + + methods: {}, + getters: {}, + setters: {}, + fields: {}, + ); + + static final _$values = { + 'none': $TextInputAction.wrap(TextInputAction.none), + 'unspecified': $TextInputAction.wrap(TextInputAction.unspecified), + 'done': $TextInputAction.wrap(TextInputAction.done), + 'go': $TextInputAction.wrap(TextInputAction.go), + 'search': $TextInputAction.wrap(TextInputAction.search), + 'send': $TextInputAction.wrap(TextInputAction.send), + 'next': $TextInputAction.wrap(TextInputAction.next), + 'previous': $TextInputAction.wrap(TextInputAction.previous), + 'continueAction': $TextInputAction.wrap(TextInputAction.continueAction), + 'join': $TextInputAction.wrap(TextInputAction.join), + 'route': $TextInputAction.wrap(TextInputAction.route), + 'emergencyCall': $TextInputAction.wrap(TextInputAction.emergencyCall), + 'newline': $TextInputAction.wrap(TextInputAction.newline), + }; + + /// Wrapper for the [TextInputAction.values] getter + static $Value? $values(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextInputAction.values; + return $List.view(value, (e) => $TextInputAction.wrap(e)); + } + + final $Instance _superclass; + + @override + final TextInputAction $value; + + @override + TextInputAction get $reified => $value; + + /// Wrap a [TextInputAction] in a [$TextInputAction] + $TextInputAction.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + return _superclass.$getProperty(runtime, identifier); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} + +/// dart_eval enum wrapper binding for [TextCapitalization] +class $TextCapitalization implements $Instance { + /// Configure this enum for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeEnumValues( + 'package:flutter/src/services/text_input.dart', + 'TextCapitalization', + $TextCapitalization._$values, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextCapitalization.values*g', + $TextCapitalization.$values, + ); + } + + /// Compile-time type specification of [$TextCapitalization] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextCapitalization', + ); + + /// Compile-time type declaration of [$TextCapitalization] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$TextCapitalization] + static const $declaration = BridgeEnumDef( + $type, + + values: ['words', 'sentences', 'characters', 'none'], + + methods: {}, + getters: {}, + setters: {}, + fields: {}, + ); + + static final _$values = { + 'words': $TextCapitalization.wrap(TextCapitalization.words), + 'sentences': $TextCapitalization.wrap(TextCapitalization.sentences), + 'characters': $TextCapitalization.wrap(TextCapitalization.characters), + 'none': $TextCapitalization.wrap(TextCapitalization.none), + }; + + /// Wrapper for the [TextCapitalization.values] getter + static $Value? $values(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextCapitalization.values; + return $List.view(value, (e) => $TextCapitalization.wrap(e)); + } + + final $Instance _superclass; + + @override + final TextCapitalization $value; + + @override + TextCapitalization get $reified => $value; + + /// Wrap a [TextCapitalization] in a [$TextCapitalization] + $TextCapitalization.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + return _superclass.$getProperty(runtime, identifier); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} + +/// dart_eval wrapper binding for [TextEditingValue] +class $TextEditingValue implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue.', + $TextEditingValue.$new, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue.fromJSON', + $TextEditingValue.$fromJSON, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue.empty*g', + $TextEditingValue.$empty, + ); + } + + /// Compile-time type specification of [$TextEditingValue] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ); + + /// Compile-time type declaration of [$TextEditingValue] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$TextEditingValue] + static const $declaration = BridgeClassDef( + BridgeClassType($type), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'text', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + true, + ), + + BridgeParameter( + 'selection', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_editing.dart', + 'TextSelection', + ), + [], + ), + ), + true, + ), + + BridgeParameter( + 'composing', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'TextRange'), []), + ), + true, + ), + ], + params: [], + ), + isFactory: false, + ), + + 'fromJSON': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [], + params: [ + BridgeParameter( + 'encoded', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.dynamic)), + ]), + ), + false, + ), + ], + ), + isFactory: true, + ), + }, + + methods: { + 'copyWith': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + ), + namedParams: [ + BridgeParameter( + 'text', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.string, []), + nullable: true, + ), + true, + ), + + BridgeParameter( + 'selection', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_editing.dart', + 'TextSelection', + ), + [], + ), + nullable: true, + ), + true, + ), + + BridgeParameter( + 'composing', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'TextRange'), []), + nullable: true, + ), + true, + ), + ], + params: [], + ), + ), + + 'replaced': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + ), + namedParams: [], + params: [ + BridgeParameter( + 'replacementRange', + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'TextRange'), []), + ), + false, + ), + + BridgeParameter( + 'replacementString', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + false, + ), + ], + ), + ), + + 'toJSON': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.map, [ + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.dynamic)), + ]), + ), + namedParams: [], + params: [], + ), + ), + }, + getters: { + 'isComposingRangeValid': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + namedParams: [], + params: [], + ), + ), + }, + setters: {}, + fields: { + 'text': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + isStatic: false, + ), + + 'selection': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_editing.dart', + 'TextSelection', + ), + [], + ), + ), + isStatic: false, + ), + + 'composing': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef(BridgeTypeSpec('dart:ui', 'TextRange'), []), + ), + isStatic: false, + ), + + 'empty': BridgeFieldDef( + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + ), + isStatic: true, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [TextEditingValue.new] constructor + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { + return $TextEditingValue.wrap( + TextEditingValue( + text: args[0]?.$value ?? '', + selection: args[1]?.$value ?? const TextSelection.collapsed(offset: -1), + composing: args[2]?.$value ?? TextRange.empty, + ), + ); + } + + /// Wrapper for the [TextEditingValue.fromJSON] constructor + static $Value? $fromJSON( + Runtime runtime, + $Value? thisValue, + List<$Value?> args, + ) { + return $TextEditingValue.wrap( + TextEditingValue.fromJSON((args[0]!.$reified as Map).cast()), + ); + } + + /// Wrapper for the [TextEditingValue.empty] getter + static $Value? $empty(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextEditingValue.empty; + return $TextEditingValue.wrap(value); + } + + final $Instance _superclass; + + @override + final TextEditingValue $value; + + @override + TextEditingValue get $reified => $value; + + /// Wrap a [TextEditingValue] in a [$TextEditingValue] + $TextEditingValue.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + switch (identifier) { + case 'text': + final _text = $value.text; + return $String(_text); + + case 'selection': + final _selection = $value.selection; + return runtime.wrapAlways(_selection); + + case 'composing': + final _composing = $value.composing; + return $TextRange.wrap(_composing); + + case 'isComposingRangeValid': + final _isComposingRangeValid = $value.isComposingRangeValid; + return $bool(_isComposingRangeValid); + case 'copyWith': + return __copyWith; + + case 'replaced': + return __replaced; + + case 'toJSON': + return __toJSON; + } + return _superclass.$getProperty(runtime, identifier); + } + + static const $Function __copyWith = $Function(_copyWith); + static $Value? _copyWith( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final self = target! as $TextEditingValue; + final result = self.$value.copyWith( + text: args[0]?.$value, + selection: args[1]?.$value, + composing: args[2]?.$value, + ); + return $TextEditingValue.wrap(result); + } + + static const $Function __replaced = $Function(_replaced); + static $Value? _replaced( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final self = target! as $TextEditingValue; + final result = self.$value.replaced(args[0]!.$value, args[1]!.$value); + return $TextEditingValue.wrap(result); + } + + static const $Function __toJSON = $Function(_toJSON); + static $Value? _toJSON(Runtime runtime, $Value? target, List<$Value?> args) { + final self = target! as $TextEditingValue; + final result = self.$value.toJSON(); + return $Map.wrap(result); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} diff --git a/lib/src/sky_engine/ui/text.dart b/lib/src/sky_engine/ui/text.dart index 1c35981..ac1a8a4 100644 --- a/lib/src/sky_engine/ui/text.dart +++ b/lib/src/sky_engine/ui/text.dart @@ -1,4 +1,5 @@ import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; import 'package:flutter/painting.dart'; class $FontStyle implements $Instance { @@ -152,3 +153,271 @@ class $TextBaseline implements $Instance { throw UnimplementedError(); } } + +/// dart_eval wrapper binding for [TextRange] +class $TextRange implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'dart:ui', + 'TextRange.', + $TextRange.$new, + ); + + runtime.registerBridgeFunc( + 'dart:ui', + 'TextRange.collapsed', + $TextRange.$collapsed, + ); + + runtime.registerBridgeFunc( + 'dart:ui', + 'TextRange.empty*g', + $TextRange.$empty, + ); + } + + /// Compile-time type specification of [$TextRange] + static const $spec = BridgeTypeSpec( + 'dart:ui', + 'TextRange', + ); + + /// Compile-time type declaration of [$TextRange] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$TextRange] + static const $declaration = BridgeClassDef( + BridgeClassType($type), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'start', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + false, + ), + + BridgeParameter( + 'end', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + false, + ), + ], + params: [], + ), + isFactory: false, + ), + + 'collapsed': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [], + params: [ + BridgeParameter( + 'offset', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + false, + ), + ], + ), + isFactory: false, + ), + }, + + methods: { + 'textBefore': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + namedParams: [], + params: [ + BridgeParameter( + 'text', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + false, + ), + ], + ), + ), + + 'textAfter': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + namedParams: [], + params: [ + BridgeParameter( + 'text', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + false, + ), + ], + ), + ), + + 'textInside': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + namedParams: [], + params: [ + BridgeParameter( + 'text', + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.string, [])), + false, + ), + ], + ), + ), + }, + getters: { + 'isValid': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + namedParams: [], + params: [], + ), + ), + + 'isCollapsed': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + namedParams: [], + params: [], + ), + ), + + 'isNormalized': BridgeMethodDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.bool, [])), + namedParams: [], + params: [], + ), + ), + }, + setters: {}, + fields: { + 'empty': BridgeFieldDef( + BridgeTypeAnnotation( + $type, + ), + isStatic: true, + ), + + 'start': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + isStatic: false, + ), + + 'end': BridgeFieldDef( + BridgeTypeAnnotation(BridgeTypeRef(CoreTypes.int, [])), + isStatic: false, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [TextRange.new] constructor + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { + return $TextRange.wrap( + TextRange(start: args[0]!.$value, end: args[1]!.$value), + ); + } + + /// Wrapper for the [TextRange.collapsed] constructor + static $Value? $collapsed( + Runtime runtime, + $Value? thisValue, + List<$Value?> args, + ) { + return $TextRange.wrap(TextRange.collapsed(args[0]!.$value)); + } + + /// Wrapper for the [TextRange.empty] getter + static $Value? $empty(Runtime runtime, $Value? target, List<$Value?> args) { + final value = TextRange.empty; + return $TextRange.wrap(value); + } + + final $Instance _superclass; + + @override + final TextRange $value; + + @override + TextRange get $reified => $value; + + /// Wrap a [TextRange] in a [$TextRange] + $TextRange.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + switch (identifier) { + case 'start': + return $int($value.start); + + case 'end': + return $int($value.end); + + case 'isValid': + return $bool($value.isValid); + + case 'isCollapsed': + return $bool($value.isCollapsed); + + case 'isNormalized': + return $bool($value.isNormalized); + case 'textBefore': + return __textBefore; + + case 'textAfter': + return __textAfter; + + case 'textInside': + return __textInside; + } + return _superclass.$getProperty(runtime, identifier); + } + + static const $Function __textBefore = $Function(_textBefore); + static $Value? _textBefore( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final self = target! as $TextRange; + final result = self.$value.textBefore(args[0]!.$value); + return $String(result); + } + + static const $Function __textAfter = $Function(_textAfter); + static $Value? _textAfter( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final self = target! as $TextRange; + final result = self.$value.textAfter(args[0]!.$value); + return $String(result); + } + + static const $Function __textInside = $Function(_textInside); + static $Value? _textInside( + Runtime runtime, + $Value? target, + List<$Value?> args, + ) { + final self = target! as $TextRange; + final result = self.$value.textInside(args[0]!.$value); + return $String(result); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} diff --git a/lib/src/widgets.dart b/lib/src/widgets.dart index 687c945..03f3533 100644 --- a/lib/src/widgets.dart +++ b/lib/src/widgets.dart @@ -3,6 +3,7 @@ library widgets; export 'foundation.dart' show UniqueKey; export 'src/widgets/app.dart'; +export 'src/widgets/autocomplete.dart'; export 'src/widgets/basic.dart'; export 'src/widgets/container.dart'; export 'src/widgets/editable_text.dart'; diff --git a/lib/src/widgets/autocomplete.dart b/lib/src/widgets/autocomplete.dart new file mode 100644 index 0000000..343c6fa --- /dev/null +++ b/lib/src/widgets/autocomplete.dart @@ -0,0 +1,495 @@ +import 'package:dart_eval/dart_eval_bridge.dart'; +import 'package:dart_eval/stdlib/core.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_eval/src/services/text_input.dart'; + +/// dart_eval enum wrapper binding for [OptionsViewOpenDirection] +class $OptionsViewOpenDirection implements $Instance { + /// Configure this enum for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeEnumValues( + 'package:flutter/src/widgets/autocomplete.dart', + 'OptionsViewOpenDirection', + $OptionsViewOpenDirection._$values, + ); + + runtime.registerBridgeFunc( + 'package:flutter/src/widgets/autocomplete.dart', + 'OptionsViewOpenDirection.values*g', + $OptionsViewOpenDirection.$values, + ); + } + + /// Compile-time type specification of [$OptionsViewOpenDirection] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/widgets/autocomplete.dart', + 'OptionsViewOpenDirection', + ); + + /// Compile-time type declaration of [$OptionsViewOpenDirection] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$OptionsViewOpenDirection] + static const $declaration = BridgeEnumDef( + $type, + values: ['up', 'down'], + methods: {}, + getters: {}, + setters: {}, + fields: {}, + ); + + static final _$values = { + 'up': $OptionsViewOpenDirection.wrap(OptionsViewOpenDirection.up), + 'down': $OptionsViewOpenDirection.wrap(OptionsViewOpenDirection.down), + }; + + /// Wrapper for the [OptionsViewOpenDirection.values] getter + static $Value? $values(Runtime runtime, $Value? target, List<$Value?> args) { + final value = OptionsViewOpenDirection.values; + return $List.view(value, (e) => $OptionsViewOpenDirection.wrap(e)); + } + + final $Instance _superclass; + + @override + final OptionsViewOpenDirection $value; + + @override + OptionsViewOpenDirection get $reified => $value; + + /// Wrap a [OptionsViewOpenDirection] in a [$OptionsViewOpenDirection] + $OptionsViewOpenDirection.wrap(this.$value) : _superclass = $Object($value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + return _superclass.$getProperty(runtime, identifier); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + return _superclass.$setProperty(runtime, identifier, value); + } +} + +/// dart_eval wrapper binding for [RawAutocomplete] +class $RawAutocomplete implements $Instance { + /// Configure this class for use in a [Runtime] + static void configureForRuntime(Runtime runtime) { + runtime.registerBridgeFunc( + 'package:flutter/src/widgets/autocomplete.dart', + 'RawAutocomplete.', + $RawAutocomplete.$new, + ); + } + + /// Compile-time type specification of [$RawAutocomplete] + static const $spec = BridgeTypeSpec( + 'package:flutter/src/widgets/autocomplete.dart', + 'RawAutocomplete', + ); + + /// Compile-time type declaration of [$RawAutocomplete] + static const $type = BridgeTypeRef($spec); + + /// Compile-time class declaration of [$RawAutocomplete] + static const $declaration = BridgeClassDef( + BridgeClassType( + $type, + generics: { + 'T': BridgeGenericParam($extends: BridgeTypeRef(CoreTypes.object, [])), + }, + $extends: BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'StatefulWidget', + ), + [], + ), + ), + constructors: { + '': BridgeConstructorDef( + BridgeFunctionDef( + returns: BridgeTypeAnnotation($type), + namedParams: [ + BridgeParameter( + 'key', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/foundation/key.dart', + 'Key', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'optionsViewBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'Widget', + ), + [], + ), + ), + params: [ + BridgeParameter( + 'context', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'BuildContext', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'onSelected', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + ), + false, + ), + BridgeParameter( + 'options', + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + ]), + ), + false, + ), + ], + namedParams: [], + ), + ), + ), + false, + ), + BridgeParameter( + 'optionsBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.future, [ + BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.iterable, [ + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + ]), + ), + ]), + ), + params: [ + BridgeParameter( + 'textEditingValue', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + ), + false, + ), + ], + namedParams: [], + ), + ), + ), + false, + ), + BridgeParameter( + 'optionsViewOpenDirection', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/autocomplete.dart', + 'OptionsViewOpenDirection', + ), + [], + ), + ), + true, + ), + BridgeParameter( + 'displayStringForOption', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.string, []), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + ), + true, + ), + BridgeParameter( + 'fieldViewBuilder', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'Widget', + ), + [], + ), + ), + params: [ + BridgeParameter( + 'context', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/framework.dart', + 'BuildContext', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'textEditingController', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/editable_text.dart', + 'TextEditingController', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'focusNode', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/focus_manager.dart', + 'FocusNode', + ), + [], + ), + ), + false, + ), + BridgeParameter( + 'onFieldSubmitted', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [], + namedParams: [], + ), + ), + ), + false, + ), + ], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'focusNode', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/focus_manager.dart', + 'FocusNode', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'onSelected', + BridgeTypeAnnotation( + BridgeTypeRef.genericFunction( + BridgeFunctionDef( + returns: BridgeTypeAnnotation( + BridgeTypeRef(CoreTypes.voidType), + ), + params: [ + BridgeParameter( + 'option', + BridgeTypeAnnotation(BridgeTypeRef.ref('T')), + false, + ), + ], + namedParams: [], + ), + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'textEditingController', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/widgets/editable_text.dart', + 'TextEditingController', + ), + [], + ), + nullable: true, + ), + true, + ), + BridgeParameter( + 'initialValue', + BridgeTypeAnnotation( + BridgeTypeRef( + BridgeTypeSpec( + 'package:flutter/src/services/text_input.dart', + 'TextEditingValue', + ), + [], + ), + nullable: true, + ), + true, + ), + ], + params: [], + ), + isFactory: false, + ), + }, + wrap: true, + bridge: false, + ); + + /// Wrapper for the [RawAutocomplete.new] constructor + static $Value? $new(Runtime runtime, $Value? thisValue, List<$Value?> args) { + return $RawAutocomplete.wrap( + RawAutocomplete( + key: args[0]?.$value, + optionsViewBuilder: ( + BuildContext context, + void Function(Object option) onSelected, + Iterable options, + ) { + return (args[1]! as EvalCallable)(runtime, null, [ + runtime.wrapAlways(context), + $Function((runtime, target, args) { + onSelected(args[0]!.$value); + return const $null(); + }), + $Iterable.wrap(options), + ])?.$value; + }, + optionsBuilder: (TextEditingValue textEditingValue) { + return (args[2]! as EvalCallable)(runtime, null, [ + $TextEditingValue.wrap(textEditingValue), + ])?.$value; + }, + optionsViewOpenDirection: + args[3]?.$value ?? OptionsViewOpenDirection.down, + displayStringForOption: (dynamic option) { + return (args[4]! as EvalCallable?)?.call(runtime, null, [ + $Object(option), + ])?.$value; + }, + fieldViewBuilder: ( + BuildContext context, + TextEditingController textEditingController, + FocusNode focusNode, + void Function() onFieldSubmitted, + ) { + return (args[5]! as EvalCallable?)?.call(runtime, null, [ + runtime.wrapAlways(context), + runtime.wrapAlways(textEditingController), + runtime.wrapAlways(focusNode), + $Function((runtime, target, args) { + onFieldSubmitted(); + return const $null(); + }), + ])?.$value; + }, + focusNode: args[6]?.$value, + onSelected: (dynamic option) { + (args[7]! as EvalCallable?)?.call(runtime, null, [$Object(option)]); + }, + textEditingController: args[8]?.$value, + initialValue: args[9]?.$value, + ), + ); + } + + @override + final RawAutocomplete $value; + + @override + RawAutocomplete get $reified => $value; + + /// Wrap a [RawAutocomplete] in a [$RawAutocomplete] + $RawAutocomplete.wrap(this.$value); + + @override + int $getRuntimeType(Runtime runtime) => runtime.lookupType($spec); + + @override + $Value? $getProperty(Runtime runtime, String identifier) { + throw UnimplementedError(); + } + + @override + void $setProperty(Runtime runtime, String identifier, $Value value) { + throw UnimplementedError(); + } +} diff --git a/lib/widgets.dart b/lib/widgets.dart index e701513..b57a145 100644 --- a/lib/widgets.dart +++ b/lib/widgets.dart @@ -1,6 +1,7 @@ /// Bridge classes and wrappers for Flutter's basic widget library library; +export 'src/widgets/autocomplete.dart'; export 'src/widgets/basic.dart'; export 'src/widgets/container.dart'; export 'src/widgets/editable_text.dart'; diff --git a/test/flutter_eval_test.dart b/test/flutter_eval_test.dart index 58e0a57..1eb000e 100644 --- a/test/flutter_eval_test.dart +++ b/test/flutter_eval_test.dart @@ -441,4 +441,97 @@ void main() { await tester.pumpAndSettle(); expect(find.text('Hello'), findsOneWidget); }); + + testWidgets('Material button and Autocomplete', (WidgetTester tester) async { + final program = compiler.compile({ + 'example': { + 'main.dart': ''' + import 'package:flutter/material.dart'; + class MyWidget extends StatelessWidget { + final _options = [ + Option(1, 'Alice'), + Option(2, 'Bob'), + Option(3, 'Charlie'), + ]; + + final void Function(int) onSelect; + + MyWidget(this.onSelect, {super.key}); + + Iterable