Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright (c) 2019 formation-dart-flutter. All rights reserved
- *
- * REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
- * WITH OR WITHOUT MODIFICATION, ARE NOT PERMITTED.
- *
- * DO NOT ALTER OR REMOVE THIS HEADER.
- *
- * Author : rushio consulting
- */
- // main() - The special entry point, required, top-level function where app execution starts.
- // This is where the app starts executing.
- // Returns void and has an optional List<String> parameter for arguments.
- main(List<String> args) {
- print('Result with ??');
- print(nullaware_1(null));
- print(nullaware_1(456));
- print('----------------');
- //
- print('Result with ??=');
- print(nullaware_2(1234, 0909));
- print(nullaware_2(null, 0909));
- print('----------------');
- //
- print('Result with ?.');
- print(nullaware_3("je dois être en uppercase"));
- print(nullaware_3(null));
- print('----------------');
- //
- print('Result with ...?');
- print(nullaware_4([1, 2, 3, 4], null));
- print(nullaware_4([1, 2, 3, 4], [5, 6, 7]));
- print('----------------');
- }
- // ??
- // Use ?? when you want to evaluate and return an expression
- // IFF another expression resolves to null
- // ((x) => x == null ? otherExp : x)(exp)
- //
- // Example
- int nullaware_1(int input) => input ?? 12345;
- // ??=
- // Use ??= when you want to assign a value to an object IFF
- // that object is null. Otherwise, return the object.
- // Assign the value only if the variable is null
- //
- // Example
- int nullaware_2(int firstValue, int secondValue) {
- int result = firstValue;
- result ??= secondValue;
- return result;
- }
- // ?.
- //Use ?. when you want to call a method/getter on an object IFF
- // that object is not null (otherwise, return null).
- // ((x) => x == null ? null : x.method())(obj)
- // You can chain it
- // obj?.child?.child?.getter
- //
- // Example
- String nullaware_3(String firstValue) => firstValue?.toUpperCase();
- // ...? Spread Operator with null aware [dart 2.3]
- //
- //
- /*
- List numbers = [];
- numbers.addAll(lowerNumbers);
- if(upperNumbers != null){
- numbers.addAll(upperNumbers);
- }
- */
- List<dynamic> nullaware_4(List<dynamic> lowerList, List<dynamic> upperList) =>
- [...lowerList, ...?upperList];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement