Dart2.12のリリースを発表した記事の翻訳を紹介します。はい、私たちは出版に非常に遅れたことを知っています:オリジナルは3月3日にリリースされました。ただし、Dart 2.12は重要なリリースであり、投稿することにしました。
Dart2.12がリリースされました。サウンドヌルセーフティとDartFFIの安定バージョンが含まれています。
ヌルセーフティは、最新の大規模機能です。その目標は、パフォーマンスを向上させることです。つまり、nullエラーを回避するのに役立ちます。このエラーによって引き起こされる問題は、コードで見つけるのが難しいことがよくあります。これについては、紹介ビデオで詳しく説明しました。
FFIは、既存のCコードを呼び出すことができる相互運用性メカニズムです。たとえば、Windows Win32APIにアクセスします。Dart2.12はすでに利用可能です。
Dartが実行されるプラットフォームの独自の機能
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.