Skip to content

[BUG] textColor in TextOptions Causes Serialization Error #420

@hbalxzdl

Description

@hbalxzdl

Description

The MLCustomInteractiveLivenessDetectionSetting object, which is used for custom liveness detection, accepts a TextOptions parameter. Within the TextOptions class, the textColor property is defined with the type Color.

When a Dart Color object (e.g., Colors.red) is assigned to this property and passed to the startCustomizedView method, the application throws a serialization exception. This occurs because the Flutter MethodChannel cannot encode the complex Color object into a primitive type that the native Android/iOS platform can understand. The native platform expects an integer (ARGB) representation for the color, not a Dart-specific object.

Expected behavior

I expected to be able to pass a standard Dart Color object to the textColor property. The startCustomizedView method should then execute without errors, launching the native UI where the text elements are rendered in the specified color.

Current behavior

The application crashes when startCustomizedView is called, throwing a Converting object to an encodable object failed: Instance of 'Color' exception. The custom liveness detection view fails to launch.

Screenshots

Not applicable, as this is a runtime exception, not a visual bug.

Logs

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'Color'

Other

This appears to be a design flaw in the plugin's public API. The Dart-side API should accept types that are directly serializable by the MethodChannel.

Proposed Solution:

  1. In the file lib/src/model/text_options.dart, change the type of the textColor field from Color? to int?.
  2. Update the documentation for the textColor field to clarify that it expects the 32-bit integer value of a color, which can be obtained from a Color object via the .value property (e.g., Colors.red.value).
  3. Update the example application (example/lib/screens/interactive_liveness_example.dart) to use Colors.red.value instead of Colors.red to demonstrate the correct usage and prevent confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions