Example how to build a interactive CLI application in Dart
This file contains hidden or 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 String name = "Adam"; | |
| print("=== ?? ==="); | |
| // does not execute defaultValue() | |
| print(name ?? defaultValue()); | |
| print("=== orDefault ==="); | |
| // executes defaultValue() | |
| print(name.orDefault(defaultValue())); |
This file contains hidden or 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
| #!/bin/sh | |
| # Usage: ./tool/run_coverage.sh test/all_tests.dart | |
| (pub global list | grep coverage) || { | |
| # install coverage when not found | |
| pub global activate coverage | |
| } | |
| pub global run coverage:collect_coverage \ |
This file contains hidden or 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 Object something = TypeA(); | |
| something.matchTypes({ | |
| TypeA : () => print("found A"), | |
| TypeB : () => print("found B"), | |
| }); | |
| } |
This file contains hidden or 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:flutter/material.dart'; | |
| Future<void> main() async { | |
| runApp(Builder( | |
| builder: (context) => const MyApp(), | |
| )); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({ |
This file contains hidden or 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
| // @dart=2.12 | |
| /// A const implementation of Uri which crashes at first access in case the uri is invalid | |
| class ConstUri implements Uri { | |
| /// Caches the static parsed uri | |
| /// | |
| /// The parsed uri can't be a mutable member field because that's not allowed for const classes | |
| static final _cache = <String, Uri>{}; | |
| const ConstUri(String uri) : _uri = uri; |
This file contains hidden or 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 'dart:async'; | |
| void main() async { | |
| // start future | |
| final future = doHardWork(); | |
| // continously post progress | |
| final sub = showProgress().listen((_) {}); | |
| // wait for completion | |
| await future; | |
| // stop progress |
This file contains hidden or 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 'dart:math'; | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(Kata()); | |
| } | |
| class Kata extends StatelessWidget { | |
| @override |
This file contains hidden or 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 'dart:async'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/rendering.dart'; | |
| /// Written by PHNTM GmbH | |
| void main() { | |
| runApp(const AdvancedOverlaySample()); | |
| } |
