Skip to content
pubscout

d4rt

0.2.6, released 4 weeks ago by an unverified publisher

An interpreter and runtime for executing Dart code dynamically.

$ flutter pub add d4rt
Source repository

What it does

d4rt is a Dart-written interpreter and runtime that allows you to execute Dart code dynamically in your applications. It includes AST caching, execution limits, code introspection, and a security sandboxing system.

AI-written summary of version 0.2.6, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to execute user-provided or dynamically loaded Dart code at runtime.
  • You want to build scripting or plugin systems within your Dart/Flutter application.
  • You require execution limits and sandboxing to restrict dangerous operations like filesystem or network access.

Skip it when

  • You are looking for standard ahead-of-time (AOT) or just-in-time (JIT) compilation for performance-critical production code.
  • You do not need dynamic script interpretation or runtime code evaluation.

Strengths

  • Full generics support and runtime type validation
  • Security sandboxing with permission-based module restrictions
  • Precompiled scripts and AST caching for better performance

Weaknesses

  • Interpreted code execution is inherently slower than native compiled code
  • Certain advanced native interactions require specific permission grants

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
4

Add d4rt to pubspec.yaml and configure security permissions via code if executing restricted operations.

import 'package:d4rt/d4rt.dart';

void main() {
  final code = '''
    int fib(int n) {
      if (n <= 1) return n;
      return fib(n - 1) + fib(n - 2);
    }
    main() {
      return fib(6);
    }
  ''';

  final interpreter = D4rt();
  final result = interpreter.execute(source: code);
  print('Result: $result'); // Result: 8
}

Alternatives

Packages that do the same job and could replace d4rt.

  • io

    Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.

  • async_extension

    Dart async extensions for Future, FutureOr, and performance improvements.

  • dart_eval

    A flexible Dart bytecode compiler and interpreter for dynamic execution and code push.

  • antlr4

    Dart runtime libraries for ANTLR 4 parser generator.

Works with

Packages commonly used together with d4rt: ones it builds on, ones built on it, and its own family.