View main_safe.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String? text; | |
@override | |
Widget build(BuildContext context) { | |
final _text = text; // Assign field to local final variable | |
return Column( | |
children: [ | |
if (_text != null) Text(_text), // The `!` is not longer needed | |
], | |
); |
View fields_error.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final A example = B(); | |
if (example.text != null) { | |
print(example.text!.length); // Throws null reference exception | |
} | |
} |
View fields.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
A(this.text); | |
final String? text; // Final field | |
} | |
class B implements A { | |
bool _first = true; | |
@override |
View main_non_safe.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String? text; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
if (text != null) Text(text!), // Won't compile without `!` in `text!` | |
], | |
); | |
} |
View fields.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
A(this.text); | |
final String? text; // Final field | |
} | |
class B implements A { | |
bool _first = true; | |
@override |
View gist:8d895f0df41ea28c7b54d405750d8e07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am tomaszpolanski on github. | |
* I am tomekpolanski (https://keybase.io/tomekpolanski) on keybase. | |
* I have a public key ASCKUlioKVilX-ZWBBM_SSeGjxkVO-nssaEU9BDiqg8bSQo | |
To claim this, I am signing this object: |
View main_tests.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:integration_test/integration_test.dart'; | |
import 'route_test.dart' as route; | |
import 'simple_test.dart' as simple; | |
import 'subfolder/sub_test.dart' as subfolder_sub; | |
import 'testing_test.dart' as testing; | |
void main() { | |
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | |
route.main(); |
View waiting.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final finder = find.text('Done'); | |
for (int i = 0; i < 10; i++) { | |
await tester.pump(const Duration(seconds: 1)); | |
if (findsOneWidget.matches(finder, {})) { | |
break; | |
} | |
} |
View time_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class TimeProvider { | |
Future<void> delayed(Duration duration); | |
} | |
class TimeProviderImpl implements TimeProvider { | |
@override | |
Future<void> delayed(Duration duration) => Future<void>.delayed(duration); | |
} | |
class MockTimeProvider implements TimeProvider { |
View time_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testWidgets('time test', (tester) async { | |
const done = Key('done'); | |
const pending = Key('pending'); | |
await tester.pumpWidget( | |
FutureBuilder( | |
future: Future<void>.delayed(const Duration(seconds: 10)), | |
builder: (context, sn) { | |
return sn.connectionState == ConnectionState.done | |
? const SizedBox(key: done) | |
: const SizedBox(key: pending); |
NewerOlder