Norbert
Norbert

Reputation: 7710

flutter package can not find classes in package

I am trying to create a flutter package.

Inside Lib(package) folder, I have MY-PACKAGE.dart file. I also have a folder Called src which contains some codes I will import for use in MY-PACKAGE.dart.

In my pubspec.yaml in Example folder I have added the package like below and run packages get.

onboardly:
  path: ../  

To use my package I do this

// THERE IS NOT ANY PROBLEM WITH THIS IMPORT STATEMENT
import 'package:onboardly/onboardly.dart';

        OnBoardly(       // THIS CLASS WORKS FINE
          screens: [
             OnBoardlyScreenItem(   // THIS CLASS CAN NOT BE FOUND EVEN THO IT EXISTS IN THE src FOLDER
             image: Image.asset("assets/loadicon.png"),
             description: Text("Hello There"),
             ),
          ],
        ),

The problem am facing is the fact that OnBoardlyScreenItem() which is in the src of the package can not be found.

I have ran flutter packages get flutter pub get restarted my IDE run flutter clean

The File Structure

Upvotes: 0

Views: 1739

Answers (1)

Norbert
Norbert

Reputation: 7710

Adding this for anyone later,

I had to export those classes or files that I wanted to be available to the Package to the "Entry file" since the folders in my case are regarded as private. Export all files or classes you'll want to be available to the user.

// Exporting all codes to be avaible to package
export 'package:onboardly/src/IntroScreen/OnBoardlyScreenItem.dart';

Upvotes: 2

Related Questions