ClassifyCard class
On-device Card Gate V3: decides whether a photo holds an identity document before you spend a network round trip on your classify/OCR backend.
Typical use:
final gate = ClassifyCard();
await gate.warmUp(); // once, e.g. when the capture screen mounts
final decision = await gate.evaluate(photoPath, mode: CardGateMode.enforce);
if (!decision.allow) {
showRetakeGuidance();
return; // no backend call
}
await myBackend.classify(photoPath);
Two rules that are not negotiable:
- Fail open. Only CardGateReason.other ever blocks. A missing plugin, a corrupt model, a timeout or a decode error all allow the request through. Never turn a failure into "no document found".
- Start in shadow. CardGateMode.shadow is the default. Run it against real traffic and compare with your backend before switching to CardGateMode.enforce.
The class holds no state; construct it wherever it is convenient. The native interpreter is a singleton behind the method channel and is shared.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
classify(
String imagePath, {Duration timeout = defaultTimeout, bool crop = true}) → Future< CardGateResult> - Runs one inference and returns the raw result.
-
classifyFrame(
CardGateFrame frame, {Duration timeout = defaultFrameTimeout}) → Future< CardGateResult> - Runs one inference on a live camera frame.
-
evaluate(
String imagePath, {CardGateMode mode = CardGateMode.shadow, Duration timeout = defaultTimeout}) → Future< CardGateDecision> - Runs the gate and reports whether you should continue to your backend.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → Future< void> - Frees the native interpreter. Optional - call it when the capture flow is finished and you want the ~4 MB back. Never throws.
-
toString(
) → String -
A string representation of this object.
inherited
-
warmUp(
) → Future< String?> - Builds the native classifier ahead of the first photo so the user is not charged the cold-start cost.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultFrameTimeout → const Duration
- Frames are disposable - waiting two seconds for one is pointless when another is 33ms away.
- defaultTimeout → const Duration
- Warm inference is roughly 20 ms. This only guards against a wedged native call, it is not a performance budget.