Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Fluttering

Tomek Polański tomaszpolanski

💭
Fluttering
View GitHub Profile
View main_safe.dart
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
],
);
@tomaszpolanski
tomaszpolanski / fields_error.dart
Last active Nov 7, 2021
Error when accessing
View fields_error.dart
void main() {
final A example = B();
if (example.text != null) {
print(example.text!.length); // Throws null reference exception
}
}
@tomaszpolanski
tomaszpolanski / fields.dart
Created Nov 7, 2021
Not truly final fields
View fields.dart
class A {
A(this.text);
final String? text; // Final field
}
class B implements A {
bool _first = true;
@override
View main_non_safe.dart
final String? text;
@override
Widget build(BuildContext context) {
return Column(
children: [
if (text != null) Text(text!), // Won't compile without `!` in `text!`
],
);
}
@tomaszpolanski
tomaszpolanski / fields.dart
Last active Nov 7, 2021
Issue With dart null safety 1
View fields.dart
class A {
A(this.text);
final String? text; // Final field
}
class B implements A {
bool _first = true;
@override
View gist:8d895f0df41ea28c7b54d405750d8e07
### 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
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
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
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 {
@tomaszpolanski
tomaszpolanski / time_test.dart
Created Apr 5, 2021
Testing time with Widget and Driver tests
View time_test.dart
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);