跪拜 Guibai
← All articles
Front-end · Android · Flutter

Dart Proposals Conditional Parts and `concrete` to End Cross-Platform Implementation Boilerplate

By 恋猫de小郭 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Flutter plugin and FFI developers currently juggle separate libraries, abstract classes, factories, and proxy layers to support multiple platforms; this proposal collapses that into a single class with platform `augment`s, and the analyzer guarantees no platform silently diverges from the agreed API.

Summary

Dart's language team has opened a draft PR (#4827) for conditional parts and a `concrete` modifier. Conditional parts let a `part` directive choose different implementation files based on the compilation target, just like conditional imports do today. The `concrete` keyword tells the analyzer that an abstract-looking method will actually have a body supplied by a platform-specific `augment`, so subclasses can call `super.close()` without error.

The proposal addresses a real pain point in Flutter plugins and FFI wrappers. With conditional imports, each platform implementation lives in a separate library, so private state like `_name` can't be shared, and nothing enforces API consistency across those files. Conditional parts keep everything in one library: `channel_io.dart` remains `part of 'channel.dart'`, can access private fields, and uses `augment` to fill in the method body. Each platform part can also import its own dependencies, like `dart:io`.

To keep static analysis deterministic, the proposal forbids conditional parts from adding new top-level declarations, new class members, `extends`/`implements`/`with` clauses, enum values, or changing parameter defaults. The analyzer checks the common public structure first, then validates that each platform's `augment` provides the required implementations. The author expects this to cut out abstract classes, factories, and proxy code for Flutter native/Web plugins, and to make FFI and JS interop wrappers far simpler.

Takeaways
— Dart PR #4827 is in draft status and proposes two changes: conditional `part` directives and a `concrete` modifier.
— Conditional parts work like conditional imports: a `part` line can pick different files based on `dart.library.io`, `dart.library.js_interop`, or other conditions.
— The `concrete` modifier lets the analyzer treat a method as non-abstract even when its body comes from a platform-specific `augment`, enabling `super.close()` calls.
— Platform part files remain in the same library as the main class, so they can access private fields and can each import their own platform dependencies.
— The proposal forbids conditional parts from adding top-level declarations, new class members, `extends`/`implements`/`with`, enum values, or changing parameter defaults, preserving identical public API structure across platforms.
— If the analyzer finds a missing or incomplete `augment` implementation for a chosen platform, compilation fails.
— Intended uses: Flutter native/Web plugins, FFI and JS interop wrappers, and code generation via augmentations.
Conclusions

The restriction table makes the trade-off explicit: platforms get to swap implementations but cannot extend the public shape of a class, which is exactly what enables the analyzer to check API consistency before platform selection happens.

The proposal mirrors Kotlin's expect/actual but avoids splitting the class declaration; instead of two separate declarations, Dart's `augment` modifies the same class, which keeps private state and type relationships in one place.

A `concrete` modifier is a clever reserve: it lets the analyzer infer existence of a method body without ever reading the conditional file, so subclasses can legally call `super` without a compile-time error on the common declaration.

Concepts & terms
Conditional Parts
A proposed Dart feature that lets a `part` directive choose implementation files based on compile-time conditions, mirroring the existing conditional `import` syntax.
concrete modifier
A new Dart modifier that declares a method has a real implementation provided by a platform-specific `augment`, even though the analyzer doesn't see the body in the common declaration. It permits calls like `super.close()` and triggers per-platform verification that the implementation exists.
augmentations
Dart's upcoming meta-programming mechanism that lets code modify or complete existing declarations from outside the defining library; here it's used to fill in method bodies for specific platforms.
From the discussion

The two remarks question whether Dart's new proposal arrives too late to matter. One notes Flutter's overall development has fallen behind expectations, and the other doubts that a feature this long in the making will inspire much adoption momentum. Both share a pessimistic outlook on timing and community eagerness.

— Flutter's pace of development has lagged behind what was expected, undermining confidence in timely language improvements.
— A feature introduced only after many years risks dampening developers' willingness to follow along, as the window for enthusiastic uptake may have already passed.
Featured comments
栈与烟火

To be honest, Flutter's progress is much slower than expected.

茶树米

It's taken this many years to only now do this; the enthusiasm to follow up probably won't be strong, will it?

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗