simple_preprocessor 0.0.3

  • Installing
  • Versions
  • 35

Simple Preprocessor

This Transformer modifies code according to directives similar to those found in C preprocessors. The syntax should be familiar.

Let's start with an example:

_coreAjax = $['core-ajax'];  // Get <core-ajax> element.
/* #if DEBUG */
_coreAjax.url = "mock.json";  // Change actual prod URL to a mock file.
/* #endif */

The URL-changing line will only be included in debug builds (which is also the default mode for pub serve). The line will not exist in release builds.

Since you can change build mode to any custom string by running pub build --mode=<mode>, you can have things like this:

/* #if LOCALHOST */
baseUrl = "http://localhost/";
/* #endif */

How to use this

In your pubspec.yaml, add simple_preprocessor as a dependency and as a Transformer. Like this:

  simple_preprocessor: any
- simple_preprocessor

Try to include it before any other transformer (it's a pre-processor, after all).


This is not a best practice. You're changing semantics of your program by a non-standard control mechanism that — worse still — lives in a comment. The only thing that kind of makes this almost okay is that the #if directive is so well recognized.

Even so, if you choose to use it, you shouldn't probably use it for anything more than a few simple #if DEBUG statements.

Supported directives

Currently, there's only #if, #else and #endif.

The #if directive takes one argument, which must be all upper case. This will be compared to the mode of pub build ("release" by default) or pub serve ("debug" by default). When there's a match, anything between #if and #endif (or #else) will be included. If not, it will be stripped.

The #elif directive is on my TODO, but probably not anything else. This shouldn't be a simplified programming language like that of a C preprocessor. If you need to do something more complex than #if DEBUG, you're better off using Dart.

There is no #define – the only definition is made by the transformer mode.

Commenting out branches

Sometimes, to play better with static analysis tooling, you might want to hide some of the lines from it. Here's a solution:

  /* #if DEBUG *//*
  var speed = 1000;
*//* #else */
  var speed = 100;
  /* #endif */

Without the extra /* and */, your IDE would probably display an error about defining the speed variable twice. But simple_preprocessor correctly identifies this syntax and will uncomment the contents between #if end #else for debug builds.

Note that the extra comment must come immediately after the #if or #else comment and directly before the #else or #endif comment. No whitespace is permitted.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  simple_preprocessor: "^0.0.3"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:simple_preprocessor/simple_preprocessor.dart';
Version Uploaded Documentation Archive
0.0.3 Feb 7, 2017 Go to the documentation of simple_preprocessor 0.0.3 Download simple_preprocessor 0.0.3 archive
0.0.2 Nov 12, 2014 Go to the documentation of simple_preprocessor 0.0.2 Download simple_preprocessor 0.0.2 archive
0.0.1 Nov 11, 2014 Go to the documentation of simple_preprocessor 0.0.1 Download simple_preprocessor 0.0.1 archive


We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
83 / 100
Reflects how tidy and up-to-date the package is. [more]
51 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:simple_preprocessor/simple_preprocessor.dart.


  • Maintain

    Changelog entries help clients to follow the progress in your code.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 error 5 hints.

    Strong-mode analysis of lib/src/modes.dart failed with the following error:

    line: 16 col: 3
    Invalid override. The type of '_SourceMode.==' ('(_SourceMode) → bool') isn't a subtype of 'Object.==' ('(dynamic) → bool').

    Run dartfmt to format lib/simple_preprocessor.dart.

  • Package is getting outdated.

    The package was released 70 weeks ago.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use simple_preprocessor.dart.


Package Constraint Resolved Available
Direct dependencies
barback >=0.15.2+9 <1.0.0 0.15.2+16
string_scanner >=1.0.1 <2.0.0 1.0.2
Transitive dependencies
async 2.0.7
charcode 1.1.1
collection 1.14.10
path 1.6.1
pool 1.3.5
source_span 1.4.0
stack_trace 1.9.2
Dev dependencies
unittest ^0.11.7