https://github.com/varuns2002/dart-interactive_print
A Dart library to simulate print() without adding a trailing newline for both Native and Web.
https://github.com/varuns2002/dart-interactive_print
console-log dart flutter interactive native print web without-linebreak without-newline
Last synced: about 2 months ago
JSON representation
A Dart library to simulate print() without adding a trailing newline for both Native and Web.
- Host: GitHub
- URL: https://github.com/varuns2002/dart-interactive_print
- Owner: VarunS2002
- License: gpl-3.0
- Created: 2021-07-05T06:35:35.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-05T07:30:43.000Z (almost 5 years ago)
- Last Synced: 2025-02-05T11:20:43.523Z (over 1 year ago)
- Topics: console-log, dart, flutter, interactive, native, print, web, without-linebreak, without-newline
- Language: Dart
- Homepage: https://pub.dev/packages/interactive_print
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dart-interactive_print
A Dart library to simulate print() without adding a trailing newline for both Native and Web.
> [](https://pub.dev/packages/interactive_print)
[](https://www.gnu.org/licenses/gpl-3.0)
## [Changelog](https://github.com/VarunS2002/Dart-interactive_print/blob/main/interactive_print/CHANGELOG.md)
## Usage
```yaml
dependencies:
interactive_print: ^1.0.0
```
A simple usage example:
```dart
import 'package:interactive_print/interactive_print.dart';
void main() {
write('Hello');
writeln('There');
write('General Kenobi');
writeln('.');
}
```
## Objective of this package
The `print()` function in Dart always adds a newline to the end, so you cannot print character by character. This is
particularly useful if you want to have a delay between printing characters or if you want to construct a line
dynamically using characters at runtime. Dart has 2 supported platforms namely Native and Web. On Native, you can
use `stdout.write()` to print without a newline, however this breaks support for Web as this function is not supported.
Web also doesn't have any method to print without a newline but this behaviour can be simulated
like [this](https://stackoverflow.com/a/41817778/13978447). This Dart library provides its own `write()` and `writeln()`
function which will dynamically use `stdout.write()` or the `console.log()` trick based on the platform you are running
on. More discussion [here](https://github.com/dart-lang/sdk/issues/46383).
## Note
- May not work correctly if you run your application in debug mode.
- If you face any issue or have suggestions then feel free to open an issue on GitHub.
- Majority of the code was contributed by [lrhn](https://github.com/lrhn).