initialize method

Future<bool> initialize()

Initializes the TypeMate plugin.

This method must be called before using any other functionality. It sets up the communication bridge with the native platform and prepares the event listeners for text field focus events.

Returns true if initialization was successful, false otherwise. Multiple calls to this method are safe - subsequent calls will return true immediately if already initialized.

Example:

final typeMate = TypeMate.instance;
if (await typeMate.initialize()) {
  print('TypeMate initialized successfully!');
  // Continue with setup...
} else {
  print('Failed to initialize TypeMate');
}

Note: Initialization only sets up the Dart-side components. You still need to handle permissions and start services separately.

See also:

Implementation

Future<bool> initialize() async {
  if (_isInitialized) return true;

  try {
    // Set up the text field focus listeners
    TypeMatePlatform.instance.setTextFieldFocusListener(
      () => _textFieldFocusedController.add(null),
      () => _textFieldUnfocusedController.add(null),
    );

    _isInitialized = true;
    return true;
  } catch (e) {
    return false;
  }
}