registerWithImage method

  1. @override
Future<void> registerWithImage({
  1. required String uri,
  2. required double width,
  3. required double height,
  4. Color? color = Colors.black,
  5. Duration? timeAfterResume = const Duration(milliseconds: 1000),
  6. Alignment? alignment,
  7. double? top,
  8. double? left,
  9. double? bottom,
  10. double? right,
})
override

iOS 13+, Android 8+ activate a screenshot blocking with an image effect view color color of the background

uri (required) uri of the image

width (required) width of the image

height (required) height of the image

alignment Alignment of the image, default Alignment.center

timeAfterResume (Android only) Time delayed for the view to stop displaying when going back to the application (in milliseconds). Default = 1000ms

function will throw warning when timeAfterResume bigger than 3000ms, users have to wait for the application to turn off the filter before going back to the main view, which is a very bad user experiences.

Throws a PlatformException if there were technical problems on native side

Implementation

@override
Future<void> registerWithImage(
    {required String uri,
    required double width,
    required double height,
    Color? color = Colors.black,
    Duration? timeAfterResume = const Duration(milliseconds: 1000),
    Alignment? alignment,
    double? top,
    double? left,
    double? bottom,
    double? right}) async {
  final colorHex =
      '#${color?.value.toRadixString(16).padLeft(8, '0').substring(2)}';
  final align = alignments.indexWhere(
    (element) => element == alignment,
  );
  await methodChannel
      .invokeMethod<void>('registerWithImage', <String, dynamic>{
    'uri': uri,
    'width': width.toString(),
    'height': height.toString(),
    'alignment': align == -1 ? 4 : align,
    'top': top,
    'left': left,
    'bottom': bottom,
    'right': right,
    'color': colorHex,
    'timeAfterResume': (timeAfterResume ?? const Duration(milliseconds: 1000))
        .inMilliseconds,
  });
}