Why I can not import dart:ui library? why could not import the Image class from dart ui

55 views Asked by At

end of the code below which _generateMarkeresFromWidget called func. Inside of function ui.Image section doesn't see dart:ui library.

Undefined class 'Image'. Try changing the name to the name of an existing class, or creating a class with the name 'Image'.


import 'dart:async';
import 'dart:typed_data';

import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:rezyonapp/pages/map_page/widgets/custom_marker_widget.dart';
Future<Marker> _generateMarkersFromWidgets(
    Map<String, dynamic> data,
  ) async {
    RenderRepaintBoundary boundary = data["globalKey"].currentContext?.findRenderObject() as RenderRepaintBoundary;
    ui.Image image = await boundary.toImage();

    ByteData? byteData = await image.toByteData(
      format: ui.ImageByteFormat.png,
    );

    return Marker(
        markerId: MarkerId(data["id"]),
        position: data["position"],
        infoWindow: data["infoWindow"],
        icon: BitmapDescriptor.fromBytes(byteData.buffer.asUint8List()));
  }
1

There are 1 answers

0
Devon Ray On

You need to change it from

import 'dart:ui';

to

import 'dart:ui' as ui;