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:
Can anyone help me in this?
Thank You.
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.
So to resolve this conflict we have to either match the version in plugin and project or override dependency in pubspec. yaml file.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With