Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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**

like image 712
Rajath Avatar asked Nov 28 '18 07:11

Rajath


2 Answers

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.

like image 91
Chris Reynolds Avatar answered Oct 11 '22 02:10

Chris Reynolds


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

like image 35
Rajath Avatar answered Oct 11 '22 00:10

Rajath