web_image.dart 888 B

123456789101112131415161718192021222324252627282930
  1. import 'dart:html';
  2. import 'dart:ui' as ui;
  3. import 'package:flutter/cupertino.dart';
  4. class WebImage extends StatelessWidget {
  5. String url;
  6. double width,height;
  7. double _borderRadius = 0.0;
  8. WebImage({Key? key,required this.url,required this.width,required this.height,double? borderRadius}) : super(key: key){
  9. if (borderRadius!=null){
  10. _borderRadius = borderRadius;
  11. }
  12. }
  13. @override
  14. Widget build(BuildContext context) {
  15. String _divId = "web_image_"+DateTime.now().toIso8601String();
  16. ui.platformViewRegistry.registerViewFactory(
  17. _divId,
  18. (int viewId) => ImageElement(src: url)..style.width='100%'..style.height='100%'..style.borderRadius='${_borderRadius}px'..style.objectFit='cover',
  19. );
  20. return SizedBox(
  21. width: width,
  22. height: height,
  23. child: HtmlElementView(key: UniqueKey(),
  24. viewType: _divId,),
  25. );
  26. }
  27. }