error: The name 'Image' is defined in the libraries 'package:flutter/src/widgets/image.dart' and 'package:image/src/image.dart'. -- ambiguous_import

16,174

Solution 1

If you have a file named import such as:

Import ‘package:image/image.dart’ as Image;

Then the class in that package will be Image.image.

Solution 2

import 'package:image/image.dart' as img;

Solution 3

You may try by deleting (i.e. by not importing) the -

Import ‘package:image/image.dart’ 

to remove the ambiguity and keeping the code same as before -

Image.file(_image),

Deleting the ‘package:image/image.dart’ worked fine for me since there was no ambiguity and this time 'Image' was purely provided by 'package:flutter/material.dart'.

Solution 4

import 'package:image/image.dart' as brendanImage;

var image = await receivePort.first as brendanImage.Image;
var resized = brendanImage.copyResize(image, width: ..);
Share:
16,174
Rajath
Author by

Rajath

MCA Graduate, with 4+ years of work experience, ReactJS, NodeJS, VueJS. Love to explore and Learn!

Updated on November 26, 2022

Comments

  • Rajath
    Rajath 12 months

    How to resolve this Ambiguity error in Dart.

    import 'dart:io';
    import 'package:flutter/material.dart';
    import 'package:camera/camera.dart';
    import 'package:image/image.dart';
    
    return MaterialApp(
      title: 'Camera',
      home: Scaffold(
        body: new Container(
          child: _image == null ? Text('No Image to display') : Image.file(_image),
        ),
        floatingActionButton: new FloatingActionButton(onPressed:() {
          picker();
        },
        tooltip: 'Pick image',
        child: new Icon(Icons.camera)),
      ),
    );
    

    ERROR:

    The name 'Image' is defined in the libraries 'package:flutter/src/widgets/image.dart' and 'package:image/src/image.dart'. (ambiguous_import at [camera] lib\packs\reg.certificate.dart:45)

    Image is defined in the Flutter Widget library, and also in the 'package:image/image.dart'. But I want to refer it from Flutter Widget library how to do this?

    Here is the image of package:image/image.dart--> library used for decoding the image.

    **package:image/image.dart**

  • iKK
    iKK over 4 years
    Thank you, that helped. Do you know how to convert form Widget-Image (coming from material.dart) to Image-Image (coming from Image.dart) - or vice-versa ??
  • Yash Singh
    Yash Singh over 3 years
    import 'package:image/image.dart' as img;