Wir präsentieren Ihnen die Übersetzung des Artikels, in dem die Veröffentlichung von Dart 2.12 angekündigt wird. Ja, wir wissen, dass wir mit der Veröffentlichung sehr spät gekommen sind: Das Original wurde am 3. März veröffentlicht. Dart 2.12 ist jedoch eine wichtige Version und wir haben beschlossen, sie zu veröffentlichen.
Dart 2.12 veröffentlicht. Es enthält stabile Versionen von Sound Null Safety und Dart FFI .
Nullsicherheit ist unser jüngstes umfangreiches Feature. Ziel ist es, die Leistung zu verbessern, um Nullfehler zu vermeiden. Die durch diesen Fehler verursachten Probleme sind in Ihrem Code oft schwer zu erkennen. Wir haben im Einführungsvideo ausführlich darüber gesprochen .
FFI ist ein Interoperabilitätsmechanismus, mit dem Sie vorhandenen C-Code aufrufen können. Greifen Sie beispielsweise auf die Windows Win32-API zu . Dart 2.12 ist bereits verfügbar.
Einzigartige Funktionalität der Plattform, auf der Dart ausgeführt wird
sound null safety FFI, , Dart. . , web. .
|
||
: JS , |
hot reload
|
null-safe |
Dart :
. x86 ARM JavaScript web. Dart : , , . API, : .
. Dart hot reload, . , Dart , async/await - .
. null-safe Dart . , . , , , Google Ads Google Assistant, .
Sound null safety . Dart FFI C. C , .
Sound null safety
Sound null safety – Dart , Dart 2.0 . Null safety . null error , , , . Sound null safety .
Non-nullable :
null safety , , null, , null.
Flutter. Flutter null error: The method '>=' was called on null
. :
final int major = version?.major;
final int minor = version?.minor;
if (globals.platform.isMacOS) {
// plugin path of Android Studio changed after version 4.1.
if (major >= 4 && minor >= 1) {
...
final int major = version?.major; final int minor = version?.minor; if (globals.platform.isMacOS) { // plugin path of Android Studio changed after version 4.1. if (major >= 4 && minor >= 1) { ... ? version
null, major
, minor
. , , , , , Flutter. null safety . , DartPad.
. null safety Google, . , null safety. :
, null , null. , protobuf, , , null. : null.
Google Pay Flutter, Flutter
State
Widget.
null safety null ; null safety , null , .
Flutter , Flutter ,
scene
Window.render
()null
. null safety — mark Scene as non-nullable, , null.
non-nullable
null safety , non-nullable:
// In null-safe Dart, none of these can ever be null.
var i = 42; // Inferred to be an int.
String name = getFileName();
final b = Foo();
, null, , ? :
// aNullableInt can hold either an integer or null.
int? aNullableInt = null;
Null safety : nullable . , null, Dart nullable non-nullable:
int definitelyInt(int? aNullableInt) {
if (aNullableInt == null) {
return 0;
}
// aNullableInt has now promoted to a non-null int.
return aNullableInt;
}
, required
. , required
( API Flutter) , :
null safety
Null safety – . , : , .
Null safety – : Dart 2.12 null safety. , null safety, , null safety .
. null . - , . .
, dart create
flutter create,
sound null safety. , , . null safety dart migrate
.
null safety Dart
- sound null safety, , null safety. , sound null safety : null safety , .
null-safe- Dart, Flutter, Firebase Material. : pub.dev null safety.
, : 98% 100 , 78% 250, 57% 500 null safety . , pub.dev null safety. , pub.dev .
sound null safety
, Dart (sound). Dart 100% , non-nullable null. Dart non-nullable, non-nullable. Dart, sound null safety Swift, .
Sound null safety Dart : . Dart , non-nullable null, . , (AOT) Dart , nulls: , null.
Dart FFI Dart C
Dart FFI C , C , . Dart 2.12, Dart FFI - . , (struct) .
C , . FFI , Dart 2.12 . C, , :
struct Link {
double value;
Link* next;
};
void MoveByReference(Link* link) {
link->value = link->value + 10.0;
}
Coord MoveByValue(Link link) {
link.value = link.value + 10.0;
return link;
}
C API . . :
struct Wheel {
int spokes;
};
struct Bike {
struct Wheel front;
struct Wheel rear;
int buildYear;
};
Dart 2.12 FFI .
API
FFI, , API.
( #44622), . , Opaque
. dart:ffi
– sizeOf
, elementAt
ref
, ( #44621). package:ff
i , . :
// Allocate a pointer to an Utf8 array, fill it from a Dart string,
// pass it to a C function, convert the result, and free the arg.
//
// Before API change:
final pointer = allocate<Int8>(count: 10);
free(pointer);
final arg = Utf8.toUtf8('Michael');
var result = helloWorldInC(arg);
print(Utf8.fromUtf8(result);
free(arg);
// After API change:
final pointer = calloc<Int8>(10);
calloc.free(pointer);
final arg = 'Michael'.toNativeUtf8();
var result = helloWorldInC(arg);
print(result.toDartString);
calloc.free(arg);
FFI
API , Dart , C. , , FFI C. , : package:ffigen.
FFI
, FFI , FFI , . :
FFI
Dart FFI API C. :
open_file API, . FFI API (Windows, macOS Linux).
win32 API Win32, API Windows Dart.
objectbox – «» , C.
tflite_flutter FFI Dart TensorFlow Lite API.
Dart ?
Sound null safety – , Dart . , . , .
(type aliases) (#65): , . , typedef :
typedef IntList = List<int>;
IntList il = [1,2,3];
(triple-shift operator) (#120): , >>>, .
- (Generic metadata annotations) (#1297): - , .
(Static meta-programming) (#1482): — Dart, Dart , Rust function builder- Swift. . , , .
Dart 2.12
Dart 2.12 sound null safety FFI SDK Dart 2.12 Flutter 2.0. null safety Dart Flutter. , , Dart issue tracker.
, pub.dev, , sound null safety. null safety, , .
, !
sound null safety FFI. , : @dart_lang.