error: The name 'Image' is defined in the

2020-04-02 17:42发布

问题:

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.

回答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.



回答2:

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



回答3:

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

var image = await receivePort.first as brendanImage.Image;
var resized = brendanImage.copyResize(image, width: ..);


标签: dart flutter