Sobes.tech
Junior — Middle

Kas saaksite selgitada external kontseptsiooni Dart keeles ja kuidas seda kasutatakse?

sobes.tech AI

Vastus AI-lt

In the Dart language, the external keyword is used to declare functions, methods, or variables whose implementation is located outside the current Dart code. This allows linking Dart with native code (e.g., C/C++), platform APIs, or generated code.

For example, if you are writing a plugin for Flutter, you can declare a method as external, and its implementation will be on the platform side (Android/iOS).

Example:

external int nativeAdd(int a, int b);

Here, nativeAdd is declared but not implemented in Dart — the implementation will be provided externally.

Thus, external helps to integrate Dart with external libraries and platform capabilities.