I searched for "Dependency Injection" and looked at the [top ~10 or so on pub.dev][top-10].
class AppModule extends Module {| import 'dart:ffi'; | |
| import 'dart:io' as io show Platform; | |
| void main() { | |
| // Note these instructions were *only* tested on Linux or MacOS. | |
| if (!io.Platform.isLinux && !io.Platform.isMacOS) { | |
| throw UnsupportedError('This code was only tested on Linux and MacOS.'); | |
| } | |
| // First, you need access to a dynamic library. The default C library is |
| sealed class Result<T, E> { | |
| const Result(); | |
| const factory Result.value(T value) = ValueResult._; | |
| const factory Result.error(E error) = ErrorResult._; | |
| } | |
| final class ValueResult<T, E> extends Result<T, E> { | |
| final T value; |
| diff --git a/Comparing-AOT-Snapshot-Sizes.md b/Comparing-AOT-Snapshot-Sizes.md | |
| index 2355d82..a5631cc 100644 | |
| --- a/Comparing-AOT-Snapshot-Sizes.md | |
| +++ b/Comparing-AOT-Snapshot-Sizes.md | |
| @@ -1,10 +1,10 @@ | |
| These instructions can be used to prepare a tabulated summary of the differences in the sizes of two AOT snapshots. The instructions assume that the Flutter Engine has been [setup](https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment) on the host (at `FLUTTER_ENGINE` in these instructions). | |
| -Build the AOT snapshot (`flutter build aot`) for the application but pass in the `--verbose` flag. We need to find the `gen_snapshot` invocation and re-run it with an extra option (`--print-instructions-sizes-to`). If you are instrumenting with a local engine, the `flutter build` takes the `--local-engine` flag as well. | |
| +Build the AOT snapshot (`flutter build aot`) for the application but pass in the `--verbose` flag. We need to find the `gen_snapshot` invocation and re-run it with an ex |
| /// A short-lived [value] `T`, that conditionally is re-computed or re-fetched. | |
| class Ephemeral<T> { | |
| final Future<T> Function() _fetch; | |
| final bool Function(T) _isExpired; | |
| /// Returns [value] by invoking [fetch]. | |
| /// | |
| /// If [isExpired] returns `false` for a given value, the value is re-fetched. | |
| /// | |
| /// ``` |
| // An interface that defines two mutable fields. | |
| abstract class Ball { | |
| abstract int x; | |
| abstract int y; | |
| } | |
| // Implements the fields by initializing in constructor. | |
| class BallImplConstructor implements Ball { | |
| @override | |
| int x; |
| /// ANSI escape sequence constants. | |
| /// | |
| /// See also: | |
| /// - <https://vt100.net/docs/vt100-ug/chapter3.html>. | |
| /// - <https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html> | |
| library ansi; | |
| /// Provides constants for 16-bit colors and styles using ANSI-escape sequences. | |
| enum AnsiEscapes16Bit { | |
| /// Resets all styled output after this escape sequence. |
I searched for "Dependency Injection" and looked at the [top ~10 or so on pub.dev][top-10].
class AppModule extends Module {| void main() { | |
| // {Animals.cat: 0, Animals.dog: 1, Animals.pig: 2} | |
| print(Animals.values.toMap()); | |
| } | |
| extension EnumHelper<E extends Enum> on Iterable<E> { | |
| Map<E, int> toMap() { | |
| return {for (final v in this) v: v.index}; | |
| } | |
| } |
| /// Parses a shell-style string [input] into a list of arguments. | |
| /// | |
| /// ```dart | |
| /// // [-x, 3, -y, 4, -abc, -beep=boop, foo, bar, baz] | |
| /// print(argv('-x 3 -y 4 -abc -beep=boop foo "bar" \'baz\'')); | |
| /// ``` | |
| List<String> argv(String input) { | |
| const $space = 0x20; | |
| const $tab = 0x09; | |
| const $newLine = 0x0a; |
| void main() { | |
| late final a = Animal(); | |
| print('Meow'); | |
| print(a.sound); | |
| } | |
| class Animal { | |
| Animal() { | |
| print('CREATED: Animal'); | |
| } |