Umbrella Imports with Dart/Flutter

1,675

In your plugin, you have a lib folder. Create a lib/src sub-folder and move the bulk of your implementation files there. It's typical to be left with just one file in lib e.g. someplugin.dart.

In there you can have any top level classes or functions but this is where you include the implementation source files using the export directive.

Here's an example from the google_sign_in plugin, from google_sign_in.dart:

import 'dart:async';
import 'dart:ui' show hashValues;

import 'package:flutter/services.dart' show MethodChannel;
import 'package:meta/meta.dart' show visibleForTesting;

import 'src/common.dart'; // this import is only required if used by some top level
                          // class lower down this file

export 'src/common.dart'; // this export means that your plugin's users don't need
                          // to import it themselves
Share:
1,675
Brad Hesse
Author by

Brad Hesse

Updated on December 03, 2022

Comments

  • Brad Hesse
    Brad Hesse over 1 year

    I am developing a plugin for Dart (Flutter). I have split up the source into many different implementation files to keep things clean and avoid having one massive file.

    The problem is, I don't want users to have to import tons of source files whenever they want to use my package.

    Is there any way, in flutter or Dart itself, to be able to declare some sort of umbrella interface?