Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve package conflict in Flutter?

I am trying to use an external package for generating a PDF document. I have used this library but when I import the below packages, I get en error

The name 'StatelessWidget' is defined in the libraries 'package:flutter/src/widgets/framework.dart' and 'package:pdf/widgets.dart'.

Error screen shot is attached.

Import statements:

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';

Error:

enter image description here

Can anyone help me in this?

Thank You.

like image 427
Ashish Tiwari Avatar asked Jul 04 '19 09:07

Ashish Tiwari


People also ask

How do you fix the conflict in flutter?

Whenever conflicts between dependencies occur, the simplest solution is to just remove the version number of both that dependencies and type 'any' without quotes in front of them.

How do you resolve dependency conflicts in flutter?

So to resolve this conflict we have to either match the version in plugin and project or override dependency in pubspec. yaml file.

What are package conflicts?

A conflict exists when a Project has dependencies on a package with different versions. A conflict can only exist between two indirect dependencies, when neither is added explicitly in the dependencies of the Project's manifest file.


1 Answers

Classes defined in package:pdf are conflicting with those defined in package:flutter. Dart allows you to import a package under a namespace to avoid such conflicts.

Change your second import statement to:

import 'package:pdf/widgets.dart' as pdf;

then you can access anything defined in the package with pdf. before it:

pdf.SomeWidgetName
like image 96
Michael Pfaff Avatar answered Sep 19 '22 20:09

Michael Pfaff