Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Action creation issue #417

Open
alejandro-rios opened this issue Aug 16, 2024 · 1 comment
Open

fix: Action creation issue #417

alejandro-rios opened this issue Aug 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@alejandro-rios
Copy link

Description

I'm trying to implement a new action based in this issue, I'm following the expect_environment_text example on the examples project, but, when I run this new action I'm getting

Steps To Reproduce

  1. Clone example project from Fluttium repo
  2. Copy and paste expect_environment_text in order to create a new action with alt_write_text as name.
  3. Rename files according to the action.
  4. Replace writeText with altWriteText
  5. Run fluttium test flows/text_flow.yaml --flavor development --target lib/main_development.dart
  6. See error.

Expected Behavior

The fluttium action should work.

Screenshots

Screenshot 2024-08-16 at 15 45 08

Additional Context

Here's the version of AltWriteText that I'm using:

import 'package:flutter/services.dart';
import 'package:fluttium/fluttium.dart';
import 'package:fluttium/src/text_input_controller.dart';

/// {@template alt_write_text}
/// workaround for typing in a textField.
///
/// This action can be invoked using the short-hand version:
///
/// ```yaml
/// - altWriteText:
/// ```
/// {@endtemplate}
class AltWriteText extends Action {
  /// {@macro alt_write_text}
  AltWriteText({
    required this.text,
  });

  final _textInputController = TextInputController();
  final String text;

  Future<void> _enterText(Tester tester, String text) async {
    _textInputController.value = _textInputController.value.copyWith(
      text: text,
      selection: TextSelection.collapsed(offset: text.length),
    );

    tester.emitPlatformMessage(
      SystemChannels.textInput.name,
      SystemChannels.textInput.codec.encodeMethodCall(
        MethodCall(
          'TextInputClient.updateEditingState',
          [-1, _textInputController.value.toJSON()],
        ),
      ),
    );
  }

  /// Called when it executes the action in a flow file.
  @override
  Future<bool> execute(Tester tester) async {
    TextInput.setInputControl(_textInputController);
    tester.emitPlatformMessage(
      SystemChannels.textInput.name,
      SystemChannels.textInput.codec.encodeMethodCall(
        const MethodCall('TextInputClient.requestExistingInputState'),
      ),
    );
    TextInput.restorePlatformInputControl();

    // Temporary workaround, enter whole text instead of character by character
    await _enterText(tester, text);
    await tester.pumpAndSettle();

    return true;
  }

  @override
  String description() => 'Some text to write "$text"';
}
@alejandro-rios alejandro-rios added the bug Something isn't working label Aug 16, 2024
@alejandro-rios
Copy link
Author

After looking the source code of fluttium found a solution by declaring shortHandIs: #text where the action is registered, like this:

void register(Registry registry) {
  registry.registerAction(
    'altWriteText',
    AltWriteText.new,
    shortHandIs: #text,
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant