base64ImageRender function

CustomRender base64ImageRender()

Implementation

CustomRender base64ImageRender() =>
    CustomRender.widget(widget: (context, buildChildren) {
      final decodedImage = base64.decode(
          _src(context.tree.element!.attributes.cast())!
              .split("base64,")[1]
              .trim());
      precacheImage(
        MemoryImage(decodedImage),
        context.buildContext,
        onError: (exception, StackTrace? stackTrace) {
          context.parser.onImageError?.call(exception, stackTrace);
        },
      );
      final widget = Image.memory(
        decodedImage,
        frameBuilder: (ctx, child, frame, _) {
          if (frame == null) {
            return Text(_alt(context.tree.element!.attributes.cast()) ?? "",
                style: context.style.generateTextStyle());
          }
          return child;
        },
      );
      return Builder(
          key: context.key,
          builder: (buildContext) {
            return GestureDetector(
              child: widget,
              onTap: () {
                if (MultipleTapGestureDetector.of(buildContext) != null) {
                  MultipleTapGestureDetector.of(buildContext)!.onTap?.call();
                }
                context.parser.onImageTap?.call(
                    _src(context.tree.element!.attributes.cast())!
                        .split("base64,")[1]
                        .trim(),
                    context,
                    context.tree.element!.attributes.cast(),
                    context.tree.element);
              },
            );
          });
    });