Skip to content

Commit

Permalink
Dart null safety (#6696)
Browse files Browse the repository at this point in the history
* Dart null-safety - prepare migration annotations in library files

* Dart null-safety - apply migration

* Dart null-safety - update flatc to generate valid code

* Dart null-safety - fix flatc generated code and adjust tests

* Dart null-safety - update example and the generated code in the tests folder

* Dart null safety - minor review changes

* Dart - apply `dartfmt -w .`
  • Loading branch information
vaind authored Jun 22, 2021
1 parent 71d43f3 commit a6ee335
Show file tree
Hide file tree
Showing 23 changed files with 3,352 additions and 2,649 deletions.
16 changes: 7 additions & 9 deletions dart/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void main() {

void builderTest() {
final builder = new fb.Builder(initialSize: 1024);
final int weaponOneName = builder.writeString("Sword");
final int? weaponOneName = builder.writeString("Sword");
final int weaponOneDamage = 3;

final int weaponTwoName = builder.writeString("Axe");
final int? weaponTwoName = builder.writeString("Axe");
final int weaponTwoDamage = 5;

final swordBuilder = new myGame.WeaponBuilder(builder)
Expand All @@ -45,7 +45,7 @@ void builderTest() {
final int axe = axeBuilder.finish();

// Serialize a name for our monster, called "Orc".
final int name = builder.writeString('Orc');
final int? name = builder.writeString('Orc');

// Create a list representing the inventory of the Orc. Each number
// could correspond to an item that can be claimed after he is slain.
Expand Down Expand Up @@ -122,27 +122,25 @@ bool verify(List<int> buffer) {
assert(monster.name == "MyMonster");

// Get and test a field of the FlatBuffer's `struct`.
var pos = monster.pos;
assert(pos != null);
var pos = monster.pos!;
assert(pos.z == 3.0);

// Get a test an element from the `inventory` FlatBuffer's `vector`.
var inv = monster.inventory;
assert(inv != null);
var inv = monster.inventory!;
assert(inv.length == 10);
assert(inv[9] == 9);

// Get and test the `weapons` FlatBuffers's `vector`.
var expected_weapon_names = ["Sword", "Axe"];
var expected_weapon_damages = [3, 5];
var weps = monster.weapons;
var weps = monster.weapons!;
for (int i = 0; i < weps.length; i++) {
assert(weps[i].name == expected_weapon_names[i]);
assert(weps[i].damage == expected_weapon_damages[i]);
}

// Get and test the `Equipment` union (`equipped` field).
assert(monster.equippedType.value == myGame.EquipmentTypeId.Weapon.value);
assert(monster.equippedType!.value == myGame.EquipmentTypeId.Weapon.value);
assert(monster.equippedType == myGame.EquipmentTypeId.Weapon);

assert(monster.equipped is myGame.Weapon);
Expand Down
Loading

0 comments on commit a6ee335

Please sign in to comment.