14

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.

4 Answers 4

21

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
4

How about just hiding StatelessWidget from the imported library? Try using the hide keyword to resolve the conflict:

import 'package:pdf/widgets.dart' hide StatelessWidget;
0

I believe you are using the package that was made specifically for dart. This package may include functions already defined in flutter causing dart to have 2 definitions of the same function. Try this for flutter

-1

you need the dart: prefix in your imports it should work as

import 'dart:pdf';

no need to for anything else.

2
  • 1
    I have imported like import 'package:pdf/pdf.dart'; Jul 5, 2019 at 4:49
  • @FredGrott as you can see in this image, dart:pdf does not exist. Nov 10, 2019 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.