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/bash | |
| # Post-build script for Flutter Web | |
| # Generates production patch loader with content-based hashes | |
| set -e | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| APP_ROOT="/path/to/your_app" |
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 { | |
| /// assume a simplified game message using a record type: (int gameId, String eventData) | |
| var streamController = StreamController<(int, String)>(); | |
| var stream = streamController.stream; | |
| var messageSwitch = Switch(stream); | |
| // game 1, event 1a | |
| streamController.sink.add((1, '1a')); |
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 { | |
| /// assume a simplified game message using a record type: (int gameId, String eventData) | |
| var streamController = StreamController<(int, String)>(); | |
| var stream = streamController.stream; | |
| var messageSwitch = Switch(stream); | |
| // game 1, event 1a | |
| streamController.sink.add((1, '1a')); |
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
| class Switch { | |
| ... | |
| void eventListener((int, String) event) { | |
| print('Switch: received event $event'); | |
| var gameId = event.$1; | |
| var gameStateController = _gameStateControllers.putIfAbsent(gameId, () { | |
| var streamController = StreamController<(int, String)>(); | |
| var gameEventStream = streamController.stream; | |
| streamController.sink.add(event); |
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
| class Switch { | |
| ... | |
| Switch(Stream<(int, String)> stream) : stream = stream.asBroadcastStream() { | |
| _subscription = this.stream.listen(eventListener); | |
| } | |
| ... | |
| } |
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() { | |
| /// assume a simplified game message using a record type: (int gameId, String eventData) | |
| var streamController = StreamController<(int, String)>(); | |
| var stream = streamController.stream; | |
| var messageSwitch = Switch(stream); | |
| // game 1, event 1a | |
| streamController.sink.add((1, '1a')); |
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
| class GameStateController { | |
| final int gameId; | |
| final Stream<(int, String)> _stream; | |
| GameStateController(this.gameId, Stream<(int, String)> eventStream) : _stream = eventStream { | |
| _stream.listen(processEvent); | |
| } | |
| void processEvent(event) { | |
| print('received event $event'); |
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() { | |
| /// assume a simplified game message using a record type: (int gameId, String eventData) | |
| var streamController = StreamController<(int, String)>(); | |
| // game 1, event 1a | |
| streamController.sink.add((1, '1a')); | |
| // game 2, event 2a | |
| streamController.sink.add((2, '2a')); |