Search packages, repositories and app categories

Package detailsv7.0.0

sprintf

Dart implementation of sprintf. Provides simple printf like formatting such as sprintf("hello %s", ["world"]);

AndroidiOSWebmacOSWindowsLinux
30-day downloads
9.5M
Likes
139
Pub points
130

Install package

flutter pub add sprintf

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Dart implementation of the sprintf function, enabling printf-style string formatting. It allows developers to create formatted strings using placeholders like %s, %d, and %f, with values passed in a list. This package is lightweight and ideal for generating dynamic messages, logs, or error outputs with consistent formatting across platforms. It supports all major Flutter platforms including Android, iOS, Web, macOS, Windows, and Linux.

Use cases

  • Formatting log messages
  • Generating dynamic error messages
  • Creating user-friendly output strings
  • Building debug information
  • String interpolation with control
  • Template-based text generation

Key features

  • printf-style formatting syntax
  • Supports %s, %d, %f placeholders
  • Simple API with single function call
  • Cross-platform compatibility
  • Lightweight and minimal dependencies
  • Easy integration via pub add

Suitable for

  • Developers needing printf-like formatting
  • Logging and debugging utilities
  • Internationalization-ready string templates
  • Apps requiring consistent string output
  • Teams preferring C-style formatting
  • Simple text generation needs

Considerations

  • Does not support advanced formatting options
  • Limited to basic placeholder types
  • No built-in localization support
  • Not suitable for complex internationalized strings
  • Requires manual handling of type conversion
  • May be less readable than named interpolations

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

dart-sprintf

Dart implementation of sprintf.

Build Status

ChangeLog

ChangeLog.md

Getting Started

Add the following to your pubspec.yaml:

dependencies:
  sprintf: "^7.0.0"

then run pub install.

Next, import dart-sprintf:

import 'package:sprintf/sprintf.dart';
Example
import 'package:sprintf/sprintf.dart';

void main() {
	print(sprintf("%04i", [-42]));
	print(sprintf("%s %s", ["Hello", "World"]));
	print(sprintf("%#04x", [10]));
}
-042
Hello World
0x0a

Limitations

  • Negative numbers are wrapped as 64bit ints when formatted as hex or octal.

Differences to C's printf

  • When using fixed point printing of numbers with large exponents, C introduces errors after 20 decimal places. Dart-printf will just print 0s.

Categories

Source repository

Projects using this package