r/dartlang
Why do Dart developers prefer this HORRIBLE style?
Why do Dart developers prefer this HORRIBLE style? See here: https://dart.dev/learn/tutorial/object-oriented#task-3-create-a-helpcommand
Why don’t they write the constructor like this?
HelpCommand() {
addFlag('verbose', abbr: 'v', help: 'When true, this command will print each command and its options.');
addOption('command', abbr: 'c', help: "When a command is passed as an argument, prints only that command's verbose usage.");
}
This is MUCH more readable!
Why aren’t the properties placed at the top of the class (before the constructor)??? Why is there an empty line before the return statement inside the run method???
This is simply terrible and VERY difficult to read.
edit: I'm coming from Java, and the idiomatic Java code is much more readable.
Learning Dart; wrapping my head around types
Hi everyone. I'm learning Dart and Flutter, and I'm trying to wrap my head around the types. I come from the web dev world, but I'm trying to approach Dart from a fresh perspective.
While trying to figure out the difference between records and the collection types, I made the follow in my notes. I tried to use clear example data to make it obvious when to use each. Is it correct or have I misunderstood anything?
--------
List
Basically an array; All values have the same type
typedef AnimalsList = List<String>;
AnimalsList animals = ['cat', 'dog'];
print(animals[0]); // 'cat'
Map
Maps keys to values; All keys and values have the same type
typedef NumeralsMap = Map<String, int>;
NumeralsMap numerals = {
  'I': 1,
  'V': 5,
};
print(numerals['I']); // 1
Set
Fixed set of values; unordered; can't get a set's items by index (position)
typedef Directions = Set<String>;
Directions directions = {'up', 'down', 'left', 'right'};
print(directions.contains('home')); // false
Record
Basically an standard object; Values and keys can be any type
typedef Dog = ({String name, int age});
Dog dog = (
  name: 'Jeff',
  age: 3,
);
print(dog.name); // 'Jeff'
dart 3.12.0 release tagged on github
https://github.com/dart-lang/sdk/releases/tag/3.12.0
It is also available on Dart SDK Archive Stable Channel.
Tip: Improving JSON Encode/Decode Performance
Using file.readAsString or accessing the body of a HTTP response in text always requires a pass through the utf8 decoder. If you're simply passing the decoded utf8 string through jsonDecode, you can combine them for much better performance.
> utf8.decoder.fuse(jsonDecoder).convert(source)
The inverse works as well: fuse jsonEncoder with utf8 encoder to get a List<int> from input Map<String, dynamic>.
Source and relevant discussion: https://github.com/dart-lang/sdk/issues/55522
Dart VM + analyzer + compiler with stateful hot reload in the browser via WebAssembly.
Hello everybody đź‘‹ ,
I managed to compile the Dart VM, runtime, compiler & analyzer to WebAssembly and it runs in the browser! It also supports hot reload and you can invoke and hot reload functions by clicking a button in the editor and state is preserved!
It's crazy fast, compiling and analyzing is instant because there's no server communication like with DartPad.
It's essentially a single static page (7.6 MB gzipped) runs on the iPad, iPhone, Mac, everywhere!
Here's the github repo: https://github.com/modulovalue/dart-live
I built a Flutter client specifically for Laravel Reverb – would love your feedback!
Hi everyone,
I’ve been working with Laravel Reverb lately and realized that while it’s compatible with the Pusher protocol, there were a few minor friction points when trying to get everything synced perfectly in a Flutter environment. To help bridge that gap, I decided to build pusher_reverb_flutter.
The goal was to provide a "plug-and-play" experience that handles the connection nuances out of the box so you can focus on building features rather than debugging handshake issues.
🚀 Key Features
- Native Dart Implementation: No platform-specific wrappers, optimized specifically for Flutter/Dart.
- Automatic Reconnection: Built-in exponential backoff to keep your users connected without manual logic.
- Multiple Channel Types: Support for Public, Private, and even Encrypted (AES-256-CBC) channels.
- Stream-Based API: Uses idiomatic Dart streams for listening to events, making it very "Fluttery."
- Custom Configurations: Easy support for custom WebSocket paths and dynamic authentication headers.
- Well-Tested: Currently maintaining over 90% test coverage to ensure stability.
đź’ˇ Why check it out?
If you're moving away from Pusher’s pricing and hosting your own Reverb server, this package aims to be the most reliable bridge for your mobile apps. It’s designed to be lightweight, typesafe, and follows a singleton pattern so you can access your client from anywhere in your app with ease.
I built this to give back to the community that has helped me so much. If you're working with the Laravel/Flutter stack, I’d be incredibly grateful if you could check it out and let me know if it helps your workflow.
Pub.dev:https://pub.dev/packages/pusher_reverb_flutter
GitHub:https://github.com/shadatrahman/pusher_reverb_flutter
Thanks for taking a look!
Opened Dart SDK discussion on server runtime hot-path overhead (dart-zig PoC + benchmarks)
I opened a Dart SDK issue here: https://github.com/dart-lang/sdk/issues/63352
This is a discussion about backend runtime architecture for high-concurrency HTTP workloads.
I built an experimental PoC (dart-zig) where Dart stays at handler/business-logic level, and some HTTP hot-path runtime work is native- side (event loop, request framing/parsing, batched completions, process-per-worker with SO_REUSEPORT).
Initial HttpArena snapshot (AOT, throughput-focused):
| Test | Conn | dart:io RPS | dart-zig RPS | Relative |
|---|---|---|---|---|
| baseline | 512 | 601,780 | 1,353,265 | ~2.25x |
| baseline | 4096 | 583,020 | 1,665,927 | ~2.86x |
| pipelined | 512 | 998,153 | 1,364,400 | ~1.37x |
| pipelined | 4096 | 997,674 | 1,477,162 | ~1.48x |
Notes:
- This is an initial PoC snapshot for directional signal.
- Memory footprint is not optimized yet.
- Claims are limited to HTTP hot-path behavior.
Also important: this is not a “replace dart:io” claim. I’m trying to discuss whether an official/experimental server-optimized runtime profile could make sense for Dart backend workloads, and what upstream criteria/hook points would be appropriate.
Would love feedback from people doing high-load Dart backend work.
I implemented a Dart code generator for Skir, a modern alternative to Protobuf
The goal is to make it easy to share data between a Dart/Flutter application and an application written in another language (one of the 12 languages that Skir supports).
I would love to hear what the Dart community thinks of it.