### start method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/LobbyNotifier/start.html Initiates the game by setting the game status to 'Started'. This method is part of the LobbyNotifier and is called to transition the game state. ```APIDOC ## start ### Description Initiates the game by setting the game status to 'Started'. This method is part of the LobbyNotifier and is called to transition the game state. ### Signature `void start()` ### Implementation ```dart void start() { state = state.copyWith(gameStatus: GameStatus.Started); } ``` ``` -------------------------------- ### startGame method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOGameClient/startGame.html Initiates a game by sending a start event to the game server. It requires a PlayerID and a GameCode to identify the player and the game to be started. ```APIDOC ## startGame ### Description Sends a start event to the game server to initiate a game session. ### Method N/A (SDK method) ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **playerID** (PlayerID) - Required - The unique identifier for the player. - **code** (GameCode) - Required - The code representing the game to be started. ### Request Example ```dart // Example usage within the IOGameClient await gameClient.startGame(playerID, gameCode); ``` ### Response #### Success Response - **bool** - Returns true if the game was successfully started, false otherwise. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Start Game Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/LobbyNotifier/start.html Call this method to transition the game state to 'Started'. It updates the LobbyNotifier's state accordingly. ```dart void start() { state = state.copyWith(gameStatus: GameStatus.Started); } ``` -------------------------------- ### startGame Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameClient-class.html Sends a start event to the game server. ```APIDOC ## startGame ### Description Sends a start event to the game server. ### Method `startGame(PlayerID playerID, GameCode code)` ### Parameters #### Path Parameters - **playerID** (PlayerID) - Required - The ID of the player. - **code** (GameCode) - Required - The code of the game. ### Returns `Future` - Returns true if the start event was sent successfully, false otherwise. ``` -------------------------------- ### startGame Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/NoServerGameClient-class.html Sends a start event to the game. This method overrides the base class method. ```APIDOC ## startGame(PlayerID playerID, GameCode code) ### Description Sends a start event to the game. ### Method `Future startGame(PlayerID playerID, GameCode code)` ### Parameters #### Path Parameters - **playerID** (PlayerID) - Required - The ID of the player. - **code** (GameCode) - Required - The code of the game. ### Overrides `startGame` in `GameClient` ``` -------------------------------- ### Example Usage of StateProvider and StateNotifierProvider Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeStateProvider/AutoDisposeStateProvider.html This example demonstrates how to use StateProvider for managing a selected item ID and StateNotifierProvider for a list of products. It shows how to watch and read providers to update the UI based on user interaction. ```dart final selectedProductIdProvider = StateProvider((ref) => null); final productsProvider = StateNotifierProvider>((ref) => ProductsNotifier()); Widget build(BuildContext context, WidgetRef ref) { final List products = ref.watch(productsProvider); final selectedProductId = ref.watch(selectedProductIdProvider); return ListView( children: [ for (final product in products) GestureDetector( onTap: () => ref.read(selectedProductIdProvider.notifier).state = product.id, child: ProductItem( product: product, isSelected: selectedProductId.state == product.id, ), ), ], ); } ``` -------------------------------- ### sumBy Examples Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/FicIterableExtension/sumBy.html Demonstrates the usage of the sumBy method with integers, doubles, and string lengths. ```dart expect([1, 2, 3, 4, 5].sumBy((e) => e), 15); expect([1.5, 2.5, 3.3, 4, 5].sumBy((e) => e), 16.3); expect(['a', 'ab', 'abc', 'abcd', 'abcde'].sumBy((e) => e.length), 15); ``` -------------------------------- ### addReadyPlayer Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GenericGame/addReadyPlayer.html Adds a ready player to the list of players who are ready to start the game. ```APIDOC ## addReadyPlayer Method ### Description Adds a ready player to the list of players who are ready to start the game. ### Method Signature The method signature is as follows: ```dart GenericGame addReadyPlayer(PlayerID player) ``` ### Parameters #### Path Parameters This method does not have path parameters. #### Query Parameters This method does not have query parameters. #### Request Body This method does not have a request body. ### Parameters - **player** (PlayerID) - Required - The ID of the player to add to the ready list. ### Response #### Success Response The method returns an updated `GenericGame` object with the player added to the `readyPlayers` list. ### Implementation Notes The implementation uses `copyWith` to create a new instance of `GenericGame` with the updated `readyPlayers` list. ``` -------------------------------- ### List fillRange Example Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/fillRange.html Demonstrates how to use fillRange on a standard Dart List. ```dart final List list = List(3); list.fillRange(0, 2, 1); print(list); // [1, 1, null] ``` -------------------------------- ### indexOf Method Signature and Usage Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSetView/indexOf.html Demonstrates the signature, behavior, and examples of the indexOf method. ```APIDOC ## indexOf Method ### Description Returns the first index of `element` in this list. Searches the list from index `start` to the end of the list. The first time an object `o` is encountered so that `o == element`, the index of `o` is returned. ### Method Signature ```dart int indexOf(T element, [int start = 0]) ``` ### Parameters - **element** (T) - The element to search for. - **start** (int, optional) - The index to start the search from. Defaults to 0. ### Returns - (int) - The first index of `element` if found, otherwise -1. ### Examples #### Basic Usage ```dart final notes = ['do', 're', 'mi', 're']; print(notes.indexOf('re')); // Output: 1 ``` #### Usage with Start Index ```dart final notes = ['do', 're', 'mi', 're']; final indexWithStart = notes.indexOf('re', 2); print(indexWithStart); // Output: 3 ``` #### Element Not Found ```dart final notes = ['do', 're', 'mi', 're']; final index = notes.indexOf('fa'); print(index); // Output: -1 ``` ### Implementation Details ```dart @override int indexOf(T element, [int start = 0]) => _set.toList(growable: false).indexOf(element, start); ``` ``` -------------------------------- ### IList fillRange Example Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/fillRange.html Demonstrates how to use fillRange on an IList. ```dart final IList ilist = IList(); ilist.fillRange(0, 2, 1); print(ilist); // [1, 1, null] ``` -------------------------------- ### Get sublist with start and end indices Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/sublist.html Returns a new list containing elements from the start index up to (but not including) the end index. Ensure that 0 <= start <= end <= list.length. ```dart final IList colors = ["red", "green", "blue", "orange", "pink"].lock; print(colors.sublist(1, 3)); // [green, blue] ``` -------------------------------- ### startGame abstract method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameClient/startGame.html Initiates a game session by sending a start event to the game server. This method requires a PlayerID and a GameCode. ```APIDOC ## startGame abstract method ### Description Sends a start event to the game server to initiate a game session. ### Method Signature Future startGame(PlayerID playerID, GameCode code) ### Parameters #### Path Parameters - **playerID** (PlayerID) - Required - The unique identifier for the player. - **code** (GameCode) - Required - The code representing the game to be started. ### Response #### Success Response - **bool** - Returns true if the game start event was successfully sent, false otherwise. ``` -------------------------------- ### Get sublist with only start index Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/sublist.html Returns a new list containing elements from the start index to the end of the original list when the end index is omitted. Ensure that 0 <= start <= list.length. ```dart print(colors.sublist(1)); // [green, blue, orange, pink] ``` -------------------------------- ### Using IList.getRange to get a sub-range Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/getRange.html Demonstrates how to use the getRange method to extract a portion of an IList. The range is inclusive of the start index and exclusive of the end index. Ensure the provided range is valid (0 <= start <= end <= length). ```dart final IList colors = ['red', 'green', 'blue', 'orange', 'pink'].lock; final Iterable range = colors.getRange(1, 4); range.join(', '); // 'green, blue, orange' ``` -------------------------------- ### connect() Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOServerClient-class.html Establishes a connection to the backend server. ```APIDOC ## connect() ### Description Connects to the backend server. ### Method Future ### Endpoint N/A (Method call) ### Returns A Future that completes when the connection is established. ``` -------------------------------- ### create Method Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeStateProviderFamily/create.html This is the implementation of the `create` method, showing how it constructs and returns a new `AutoDisposeStateProvider`. ```APIDOC ## Implementation ```dart @override AutoDisposeStateProvider create(Arg argument) { return AutoDisposeStateProvider( (ref) => _create(ref, argument), name: name, from: this, argument: argument, ); } ``` ``` -------------------------------- ### Dart Iterable.take() Example Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/take.html Demonstrates how to use the take() method to get the first few elements from a list. The method handles cases where the requested count exceeds the list size. ```dart final numbers = [1, 2, 3, 5, 6, 7]; final result = numbers.take(4); // (1, 2, 3, 5) final takeAll = numbers.take(100); // (1, 2, 3, 5, 6, 7) ``` -------------------------------- ### Removing Entries from a Map with removeWhere Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListMap/removeWhere.html Demonstrates how to use the removeWhere method to filter and remove entries from a standard Dart map based on a predicate function. This example shows removing entries where the value starts with 'E'. ```dart final terrestrial = {1: 'Mercury', 2: 'Venus', 3: 'Earth'}; terrestrial.removeWhere((key, value) => value.startsWith('E')); print(terrestrial); // {1: Mercury, 2: Venus} ``` -------------------------------- ### Implementing setupOverride Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeFutureProviderFamily/setupOverride.html This snippet shows how to implement the setupOverride method. It calls the family's provider with the given argument and then uses the setup function to override the origin and override providers with the created futureProvider. ```dart @override void setupOverride(Arg argument, SetupOverride setup) { final futureProvider = call(argument); setup(origin: futureProvider, override: futureProvider); } ``` -------------------------------- ### removeRange Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/removeRange.html Removes the objects in the range `start` inclusive to `end` exclusive. The provided range, given by `start` and `end`, must be valid. A range from `start` to `end` is valid if `0 <= start <= end <= len`, where `len` is this list's `length`. The range starts at `start` and has length `end - start`. An empty range (with `end == start`) is valid. ```APIDOC ## removeRange ### Description Removes the objects in the range `start` inclusive to `end` exclusive. The provided range, given by `start` and `end`, must be valid. A range from `start` to `end` is valid if `0 <= start <= end <= len`, where `len` is this list's `length`. The range starts at `start` and has length `end - start`. An empty range (with `end == start`) is valid. ### Method Signature ```dart IList removeRange(int start, int end) ``` ### Parameters #### Path Parameters - **start** (int) - Required - The starting index of the range to remove (inclusive). - **end** (int) - Required - The ending index of the range to remove (exclusive). ### Returns - **IList** - A new IList with the specified range of elements removed. ``` -------------------------------- ### indexOf Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList-class.html Returns the index of the first occurrence of the specified `element` in the list, starting the search from the given `start` index. Defaults to starting from index 0. ```APIDOC ## indexOf ### Description Returns the index of the first `element` in the list. ### Method `indexOf(T element, [int start = 0])` ### Parameters - **element** (T) - The element to search for. - **start** (int) - The index to start the search from. Defaults to 0. ### Returns `int` - The index of the first occurrence of the element, or -1 if not found. ``` -------------------------------- ### Implementing setupOverride Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeStateNotifierProviderFamily/setupOverride.html This snippet shows the implementation of the setupOverride method. It overrides the provider and its notifier for a given argument. ```dart @override void setupOverride(Arg argument, SetupOverride setup) { final provider = call(argument); setup(origin: provider, override: provider); setup(origin: provider.notifier, override: provider.notifier); } ``` -------------------------------- ### indexWhere Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList-class.html Returns the index of the first element in the list that satisfies the provided `test` predicate, starting the search from the given `start` index. Defaults to starting from index 0. ```APIDOC ## indexWhere ### Description Returns the first index in the list that satisfies the provided `test`. ### Method `indexWhere(Predicate test, [int start = 0])` ### Parameters - **test** (Predicate) - The condition to test each element against. - **start** (int) - The index to start the search from. Defaults to 0. ### Returns `int` - The index of the first element that satisfies the test, or -1 if no such element is found. ``` -------------------------------- ### IOServer Constructors Source: https://pub.dev/documentation/game_scaffold_dart/latest/server/IOServer-class.html Initializes a new instance of the IOServer class. ```APIDOC ## IOServer Constructor ### Description Initializes a new instance of the IOServer class with optional debug and https settings, and paths to certificate and RSA files. ### Parameters - **debug** (bool) - Optional - Enables or disables debug mode. Defaults to false. - **https** (bool) - Optional - Enables or disables HTTPS. Defaults to false. - **pathToPem** (String?) - Optional - Path to the PEM certificate file. - **pathToRsa** (String?) - Optional - Path to the RSA key file. - **port** (int) - Optional - The port number to listen on. Defaults to defaultGamePort. ``` -------------------------------- ### Finding the last index of elements starting with 'r' Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSetView/lastIndexWhere.html Demonstrates how to use lastIndexWhere to find the last occurrence of elements that start with a specific string. The search can be limited to a starting index. ```dart final notes = ['do', 're', 'mi', 're']; final first = notes.lastIndexWhere((note) => note.startsWith('r')); // 3 final second = notes.lastIndexWhere((note) => note.startsWith('r'), 2); // 1 ``` -------------------------------- ### Implementing setupOverride Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/Family/setupOverride.html This snippet shows the basic implementation of the setupOverride method. It's used to override providers associated with an argument by calling the setup function with origin and override configurations. ```dart @override void setupOverride(Arg argument, SetupOverride setup) { setup(origin: call(argument), override: call(argument)); } ``` -------------------------------- ### Find last element starting with 'r' from end Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/lastIndexWhere.html Demonstrates finding the last index of an element that starts with 'r' from the end of the list. The search starts from the beginning of the list by default. ```dart final notes = ['do', 're', 'mi', 're']; final first = notes.lastIndexWhere((note) => note.startsWith('r')); // 3 ``` -------------------------------- ### IList.sublist Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/sublist.html Returns a new list containing the elements between `start` and `end`. The `start` and `end` positions must satisfy the relations 0 ≤ `start` ≤ `end` ≤ `this.length`. If `end` is omitted, it defaults to the length of the list. If `end` is equal to `start`, the returned list is empty. ```APIDOC ## IList.sublist ### Description Returns a new list containing the elements between `start` and `end`. ### Method Signature `IList sublist(int start, [int? end])` ### Parameters #### Path Parameters - **start** (int) - Required - The starting index (inclusive). - **end** (int?) - Optional - The ending index (exclusive). Defaults to the length of the list if omitted. ### Example Usage ```dart final IList colors = ["red", "green", "blue", "orange", "pink"].lock; print(colors.sublist(1, 3)); // Output: [green, blue] print(colors.sublist(1)); // Output: [green, blue, orange, pink] ``` ### Constraints - `0 <= start <= end <= this.length` - If `end == start`, the returned list is empty. ``` -------------------------------- ### create method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeStateNotifierProvider/create.html Initializes the state of a provider by watching the notifier, setting up a listener for state changes, and returning the initial state. ```APIDOC ## create method ### Description Initializes the state of a provider by watching the notifier, setting up a listener for state changes, and returning the initial state. ### Method Signature ```dart State create(AutoDisposeProviderElementBase ref) ``` ### Parameters #### Path Parameters - **ref** (AutoDisposeProviderElementBase) - Required - The element base for the provider, used to interact with the provider lifecycle and state. ### Implementation Details This method overrides the base `create` method. It watches the provider's notifier, sets up a listener that calls `ref.setState` whenever the notifier's state changes, and registers this listener to be removed upon provider disposal using `ref.onDispose`. Finally, it returns the current state of the provider using `ref.requireState`. ``` -------------------------------- ### lastIndexOf Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/lastIndexOf.html Returns the last index of the specified element in the list. The search starts from the `start` index and proceeds backward to the beginning of the list. If `start` is omitted, the entire list is searched from the end. ```APIDOC ## lastIndexOf ### Description Finds the last index of `element` in the list, searching backwards from the `start` index. Returns the index of the first occurrence of `element` found when searching from right to left. Returns -1 if the element is not found. ### Method Signature `int lastIndexOf(T element, [int? start])` ### Parameters #### Path Parameters - **element** (T) - The element to search for. - **start** (int?) - Optional. The index to start searching backwards from. If omitted, the search starts from the end of the list. ### Examples #### Example 1: With start index ```dart final notes = ['do', 're', 'mi', 're']; const startIndex = 2; final index = notes.lastIndexOf('re', startIndex); // Returns 1 ``` #### Example 2: Without start index ```dart final notes = ['do', 're', 'mi', 're']; final index = notes.lastIndexOf('re'); // Returns 3 ``` #### Example 3: Element not found ```dart final notes = ['do', 're', 'mi', 're']; final index = notes.lastIndexOf('fa'); // Returns -1 ``` ### Return Value An `int` representing the last index of the element, or -1 if the element is not found. ``` -------------------------------- ### startGame Method Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/NoServerGameClient/startGame.html This snippet shows the implementation of the startGame method. It retrieves a backend reader, accesses the lobby notifier, simulates a delay, and then calls the start method on the notifier to begin the game. It returns a boolean indicating success. ```dart @override Future startGame(PlayerID playerID, GameCode code) async { final backendReader = NoServerClient.games[code]!.container.read; final notifier = backendReader(BackendProviders.lobby.notifier); await Future.delayed(const Duration(microseconds: 1)); notifier.start(); return true; } ``` -------------------------------- ### fillRange Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/fillRange.html Overwrites a range of elements with `fillValue`. Sets the positions greater than or equal to `start` and less than `end`, to `fillValue`. The provided range, given by `start` and `end`, must be valid. A range from `start` to `end` is valid if 0 ≤ `start` ≤ `end` ≤ length. An empty range (with `end == start`) is valid. If the element type is not nullable, the `fillValue` must be provided and must be non-`null`. ```APIDOC ## fillRange ### Description Overwrites a range of elements with `fillValue`. Sets the positions greater than or equal to `start` and less than `end`, to `fillValue`. The provided range, given by `start` and `end`, must be valid. A range from `start` to `end` is valid if 0 ≤ `start` ≤ `end` ≤ length. An empty range (with `end == start`) is valid. If the element type is not nullable, the `fillValue` must be provided and must be non-`null`. ### Parameters #### Path Parameters - **start** (int) - Required - The starting index of the range (inclusive). - **end** (int) - Required - The ending index of the range (exclusive). - **fillValue** (T?) - Optional - The value to fill the range with. If the element type is not nullable, this must be provided and non-null. ### Example ```dart final words = List.filled(5, 'old'); print(words); // [old, old, old, old, old] words.fillRange(1, 3, 'new'); print(words); // [old, new, new, old, old] ``` ``` -------------------------------- ### removeRange(int start, int end) Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IListConst-class.html Removes the objects in the range `start` inclusive to `end` exclusive. ```APIDOC ## removeRange(int start, int end) ### Description Removes the objects in the range `start` inclusive to `end` exclusive. ### Method N/A (Instance method) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (N/A) Returns the IList with the specified range removed. #### Response Example N/A ``` -------------------------------- ### autoStart Property Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameConfig/autoStart.html Shows the abstract implementation of the autoStart getter. This is typically overridden by subclasses. ```dart bool get autoStart => throw _privateConstructorUsedError; ``` -------------------------------- ### NoServerGameClient Constructors Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/NoServerGameClient-class.html Initializes a new instance of the NoServerGameClient class. ```APIDOC ## NoServerGameClient() ### Description Initializes a new instance of the NoServerGameClient class. ### Constructors - NoServerGameClient() ``` -------------------------------- ### Event Get Event Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameEventGame/event.html This snippet shows the basic implementation of the 'Event get event' property. ```dart Event get event; ``` -------------------------------- ### indexWhere Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ReversedListView/indexWhere.html Finds the first index in the reversed list that satisfies the provided test predicate. The search starts from the specified `start` index and proceeds towards the beginning of the list (effectively searching from the end of the original list towards the start). ```APIDOC ## indexWhere Method ### Description Finds the first index in the reversed list that satisfies the provided `test` predicate. The search starts from the specified `start` index and proceeds towards the beginning of the list. The first time an object `o` is encountered such that `test(o)` is true, the index of `o` (relative to the reversed list) is returned. Returns -1 if no element satisfies the predicate. ### Method Signature ```dart int indexWhere(Predicate test, [int start = 0]) ``` ### Parameters * **test** (Predicate) - Required - A function that returns true for the element being sought. * **start** (int) - Optional - The index to start the search from. Defaults to 0. ### Examples ```dart final notes = ['do', 're', 'mi', 're']; // Assuming ReversedListView is initialized with notes // Find the first note starting with 'r' from the beginning of the reversed list final first = reversedListView.indexWhere((note) => note.startsWith('r')); // Expected: 1 (index of 're' from the end) // Find the first note starting with 'r' starting the search from index 2 of the reversed list final second = reversedListView.indexWhere((note) => note.startsWith('r'), 2); // Expected: 3 (index of the second 're' from the end) // Find a note that does not exist final index = reversedListView.indexWhere((note) => note.startsWith('k')); // Expected: -1 ``` ### Return Value An integer representing the index of the first element that satisfies the `test` predicate, or -1 if no such element is found. ``` -------------------------------- ### IOServerClient Constructors Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOServerClient-class.html Initializes a new instance of the IOServerClient class. ```APIDOC ## IOServerClient ### Description Initializes a new instance of the IOServerClient class. ### Parameters * **address** (GameAddress) - Required - The network address of the game server. * **ref** (ProviderRef) - Required - A reference to the ServerClient provider. ``` -------------------------------- ### Get Map Length Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListMapView/length.html Returns the number of key/value pairs in the map. This is an implementation of the `int get length` getter. ```dart @override int get length => _map.length; ``` -------------------------------- ### Using AutoDisposeStateProvider for State Management Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeStateProvider-class.html This example demonstrates how to use AutoDisposeStateProvider to manage a selected product ID and a list of products. It shows how to watch and read providers, and how to update the state when a product is tapped. ```dart final selectedProductIdProvider = StateProvider((ref) => null); final productsProvider = StateNotifierProvider>((ref) => ProductsNotifier()); Widget build(BuildContext context, WidgetRef ref) { final List products = ref.watch(productsProvider); final selectedProductId = ref.watch(selectedProductIdProvider); return ListView( children: [ for (final product in products) GestureDetector( onTap: () => ref.read(selectedProductIdProvider.notifier).state = product.id, child: ProductItem( product: product, isSelected: selectedProductId.state == product.id, ), ), ], ); } ``` -------------------------------- ### GenericGame.start Factory Constructor Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GenericGame/GenericGame.start.html Initializes a new game instance with the provided players and game settings. This is a factory constructor that sets up a default game state. ```APIDOC ## GenericGame.start(IList players, {required bool multiPly, required bool simultaneousAction}) ### Description Creates a default initialized game with the provided list of players. This factory constructor is used to set up a new game instance with essential parameters like multiplayer and simultaneous action settings. ### Method factory ### Parameters #### Positional Parameters - **players** (IList) - Required - The list of players participating in the game. #### Named Parameters - **multiPly** (bool) - Required - Indicates if the game is a multiplayer game. - **simultaneousAction** (bool) - Required - Indicates if players can perform actions simultaneously. ``` -------------------------------- ### lastIndexWhere Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/FromIListMixin/lastIndexWhere.html Finds the index of the last element in the list that satisfies the predicate `test`. The search can optionally start from the `start` index. ```APIDOC ## lastIndexWhere ### Description Finds the index of the last element in the list that satisfies the predicate `test`. The search can optionally start from the `start` index. ### Signature `int lastIndexWhere(Predicate test, [int? start])` ### Parameters #### Path Parameters - **test** (Predicate) - Required - The condition to test each element against. - **start** (int?) - Optional - The index to start searching from (inclusive, searching backwards). ### Returns An integer representing the index of the last element that satisfies the predicate, or -1 if no such element is found. ``` -------------------------------- ### Get gameType Property Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameConfig/gameType.html This snippet shows the implementation of the get gameType getter. It is used to retrieve the game type as a String. ```dart String get gameType => throw _privateConstructorUsedError; ``` -------------------------------- ### NoServerGameClient Constructor Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/NoServerGameClient/NoServerGameClient.html Initializes a new instance of the NoServerGameClient class. This constructor does not require any arguments and sets up the client for offline gameplay. ```APIDOC ## NoServerGameClient() ### Description Initializes a new instance of the NoServerGameClient class. This constructor does not require any arguments and sets up the client for offline gameplay. ### Method constructor ### Endpoint N/A (Constructor) ### Parameters None ### Request Example ```dart var client = NoServerGameClient(); ``` ### Response #### Success Response Initializes the NoServerGameClient object. #### Response Example ```dart // No direct response object, initializes the client instance. ``` ``` -------------------------------- ### Entry Class Constructors and Methods Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/Entry-class.html This snippet details the constructors, properties, methods, operators, and static methods available for the Entry class. ```APIDOC ## Entry class Similar to a MapEntry, but correctly implements equals (== comparing key and value), `hashcode` and Comparable.compareTo. Implemented types: * Comparable> ## Constructors ### Entry(K key, V value) Creates a new Entry with the given key and value. ## Properties * **hashCode** → int The hash code for this object. * **key** → K The key of the entry. * **runtimeType** → Type A representation of the runtime type of the object. * **value** → V The value of the entry. ## Methods ### compareTo(Entry other) → int Compares this object to another Entry object. ### noSuchMethod(Invocation invocation) → dynamic Invoked when a nonexistent method or property is accessed. ### toString() → String Returns a string representation of this Entry object. ## Operators ### operator ==(Object other) → bool Checks if this Entry is equal to another object. ## Static Methods ### from(MapEntry entry) → Entry Creates an Entry object from a MapEntry. ``` -------------------------------- ### gameStream Implementation Example Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/GameClient/gameStream.html An example of how the gameStream method can be implemented. This implementation returns a Stream of GameOrError, accepting PlayerID and GameCode. ```dart Stream gameStream(PlayerID playerID, GameCode code); ``` -------------------------------- ### create Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/AutoDisposeProviderBase/create.html Initializes the state of a provider. This is an abstract method that must be implemented by subclasses. ```APIDOC ## create ### Description Initializes the state of a provider. This is an abstract method that must be implemented by subclasses. ### Method Signature `State create(AutoDisposeRef ref)` ### Parameters #### Path Parameters - **ref** (AutoDisposeRef) - Required - The reference to the provider container. ``` -------------------------------- ### lastIndexOf Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/FromIListMixin/lastIndexOf.html Finds the last index of the specified element in this list. Returns the index of the last occurrence of `element` in this list; returns -1 if there is no element in the list. If `start` is provided, the search starts from that index backwards. If `start` is omitted, it defaults to the last element of the list. ```APIDOC ## lastIndexOf ### Description Finds the last index of the specified element in this list. Returns the index of the last occurrence of `element` in this list; returns -1 if there is no element in the list. If `start` is provided, the search starts from that index backwards. If `start` is omitted, it defaults to the last element of the list. ### Method Signature `int lastIndexOf(T element, [int? start])` ### Parameters #### Optional Parameters - **start** (int?) - The index to start the search from (inclusive, searching backwards). Defaults to the last index of the list if not provided. ### Returns - **int** - The index of the last occurrence of the element, or -1 if not found. ``` -------------------------------- ### IMap.withConfig Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IMap/IMap.withConfig.html Creates an IMap instance from a provided Map and a ConfigMap. If the input map is null or empty, an empty IMap is returned. Otherwise, it initializes the IMap with the given map and configuration. ```APIDOC ## IMap.withConfig ### Description Creates an IMap from a Map and a ConfigMap. ### Method factory ### Signature IMap.withConfig(Map? map, ConfigMap config) ### Parameters #### Path Parameters - **map** (Map?) - Optional - The initial map to populate the IMap with. - **config** (ConfigMap) - Required - The configuration object for the IMap. ### Response #### Success Response - **IMap** - An instance of IMap initialized with the provided map and configuration. ``` -------------------------------- ### NoServerClient Constructors Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/NoServerClient-class.html Initializes a new instance of the NoServerClient class. ```APIDOC ## NoServerClient() ### Description Initializes a new instance of the NoServerClient class. ### Method Constructor ``` -------------------------------- ### Find first element starting with 'r' Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/indexWhere.html Demonstrates finding the first element in a list that starts with 'r'. Searches from the beginning of the list. ```dart final IList notes = ['do', 're', 'mi', 're'].lock; notes.indexWhere((note) => note.startsWith('r')); // 1 ``` -------------------------------- ### withConfigFrom Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IListConst-class.html Creates a new list with the same contents but the configuration from another list. ```APIDOC ## withConfigFrom ### Description Returns a new list with the contents of the present IList, but the config of `other`. ### Method `withConfigFrom(IList other)` ### Parameters - **other** (IList) - Required - The list from which to copy the configuration. ### Response Returns an `IList` with the contents of the current list and the configuration of the `other` list. ``` -------------------------------- ### replaceRange Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/replaceRange.html Replaces elements in a list within a specified range (from start to end) with elements from a replacement iterable. The original elements in the range are removed, and the new elements are inserted at the start index. This operation requires the list to be growable and the range to be valid (0 <= start <= end <= length). ```APIDOC ## replaceRange ### Description Replaces a range of elements in the list with the elements from the `replacement` iterable. It first removes elements from `start` to `end` and then inserts the elements from `replacement` at the `start` index. This method is roughly equivalent to calling `removeRange` followed by `insertAll`, but may be more efficient. ### Method Signature `void replaceRange(int start, int end, Iterable replacement)` ### Parameters - **start** (int) - The starting index of the range to replace. Must be non-negative and less than or equal to `end` and the list's length. - **end** (int) - The ending index (exclusive) of the range to replace. Must be greater than or equal to `start` and less than or equal to the list's length. - **replacement** (Iterable) - An iterable containing the elements to insert into the list. ### Notes - The list must be growable. This method does not work on fixed-length lists. - The range `[start, end)` must be valid, meaning `0 <= start <= end <= length`. ### Example ```dart final numbers = [1, 2, 3, 4, 5]; final replacements = [6, 7]; numbers.replaceRange(1, 4, replacements); print(numbers); // Output: [1, 6, 7, 5] ``` ``` -------------------------------- ### withConfig Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IListConst-class.html Creates a new list with a specified configuration. ```APIDOC ## withConfig ### Description Creates a new list with the given `config`. ### Method `withConfig(ConfigList config)` ### Parameters - **config** (ConfigList) - Required - The configuration to apply to the new list. ### Response Returns an `IList` with the specified configuration. ``` -------------------------------- ### Find last index satisfying a condition Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/lastIndexWhere.html Demonstrates finding the last index of elements starting with 'r' in a list, with and without a specified start index. ```dart final IList notes = ['do', 're', 'mi', 're'].lock; notes.lastIndexWhere((note) => note.startsWith('r')); // 3 notes.lastIndexWhere((note) => note.startsWith('r'), 2); // 1 ``` -------------------------------- ### Find first element starting with 'r' from a specific index Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/indexWhere.html Demonstrates finding the first element that starts with 'r', beginning the search from index 2. ```dart notes.indexWhere((note) => note.startsWith('r'), 2); // 3 ``` -------------------------------- ### Socket.IO Game Client Provider Setup Source: https://pub.dev/documentation/game_scaffold_dart/latest/server/socketIOGameClient.html This snippet shows how to create a Riverpod provider for the GameClient. It initializes the IOGameClient with necessary dependencies and includes logic to gracefully exit and dispose of the client when the provider is no longer needed. ```dart final socketIOGameClient = Provider( (ref) { final client = IOGameClient( code: ref.read(GameProviders.code), address: ref.watch(GameProviders.remoteUri), ref: ref, ); ref.onDispose(() { client.exitGame( ref.read(GameProviders.playerID), ref.read(GameProviders.code), ); client.dispose(); }); return client; }, name: 'socketIOGameClient', dependencies: [ GameProviders.remoteUri, GameProviders.code, GameProviders.playerID, ], ); ``` -------------------------------- ### Dart Map get() Method Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListMap/get.html This snippet shows the direct implementation of the get() method for a Dart Map, which uses the internal map lookup. ```dart V? get(covariant K key) => _map[key]; ``` -------------------------------- ### replaceRange(int start, int end, Iterable replacement) Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IListConst-class.html Removes the objects in the range `start` inclusive to `end` exclusive and inserts the contents of `replacement` in its place. ```APIDOC ## replaceRange(int start, int end, Iterable replacement) ### Description Removes the objects in the range `start` inclusive to `end` exclusive and inserts the contents of `replacement` in its place. ### Method N/A (Instance method) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (N/A) Returns the IList with the specified range replaced. #### Response Example N/A ``` -------------------------------- ### IOServerClient Constructor Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOServerClient/IOServerClient.html Initializes the IOServerClient with a game address and a provider reference. A connection is asynchronously initiated shortly after construction. ```dart IOServerClient({ required this.address, required this.ref, }) { Future.delayed(const Duration(milliseconds: 10), connect); } ``` -------------------------------- ### Find last index of element from a specific start index Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/lastIndexOf.html Searches the list backwards from the provided `start` index. Returns the index of the last occurrence of the `element`. ```dart final IList notes = ['do', 're', 'mi', 're'].lock; notes.lastIndexOf('re', 2); // 1 ``` -------------------------------- ### startGame Method Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOGameClient/startGame.html This snippet shows the implementation of the startGame method. It sends a start game request to the server via a socket call and returns the boolean result. ```dart @override Future startGame(PlayerID playerID, GameCode code) async { final result = await _socket! .call(IOChannel.startgame, {'playerID': playerID, 'code': code}); return result as bool; } ``` -------------------------------- ### IOServerClient Constructor Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOServerClient/IOServerClient.html Initializes the IOServerClient with a game address and a provider reference to a ServerClient. It also schedules an asynchronous connection attempt. ```APIDOC ## IOServerClient Constructor ### Description Initializes the IOServerClient with a game address and a provider reference to a ServerClient. It also schedules an asynchronous connection attempt. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor Signature ```dart IOServerClient({ required GameAddress address, required ProviderRef ref, }) ``` ### Implementation Notes The constructor immediately schedules a connection attempt to be made shortly after initialization using `Future.delayed`. ``` -------------------------------- ### IList.fillRange Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IList/fillRange.html Sets the objects in the range `start` inclusive to `end` exclusive to the given `fillValue`. The provided range must be valid (0 <= start <= end <= length). ```APIDOC ## IList.fillRange ### Description Sets the objects in the range `start` inclusive to `end` exclusive to the given `fillValue`. The provided range, given by `start` and `end`, must be valid. A range from `start` to `end` is valid if `0 <= start <= end <= len`, where `len` is this list's `length`. The range starts at `start` and has length `end - start`. An empty range (with `end == start`) is valid. If the element type is not nullable, omitting `fillValue` or passing `null` as `fillValue` will make the `fillRange` fail. ### Method Signature `IList fillRange(int start, int end, [T? fillValue])` ### Parameters #### Path Parameters - `start` (int) - The starting index of the range (inclusive). - `end` (int) - The ending index of the range (exclusive). - `fillValue` (T?) - Optional. The value to fill the range with. If omitted or null, and the element type is not nullable, the operation may fail. ### Example ```dart // Example with IList: final IList ilist = IList(); ilist.fillRange(0, 2, 1); print(ilist); // Output: [1, 1, null] ``` ### Returns An `IList` with the specified range filled with `fillValue`. ``` -------------------------------- ### Create Game Implementation Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/IOServerClient/createGame.html This snippet shows the implementation of the createGame method. It logs the game configuration and then calls a private method _createGame to handle the actual game creation. ```dart @override Future createGame(PlayerID playerID, GameConfig config) async { logger.fine('Creating game $config'); final gameCode = await _createGame(config); return gameCode; } ``` -------------------------------- ### Find last element starting with 'r' from index 2 Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/lastIndexWhere.html Demonstrates finding the last index of an element that starts with 'r', searching backwards from a specified index (2 in this case). ```dart final notes = ['do', 're', 'mi', 're']; final second = notes.lastIndexWhere((note) => note.startsWith('r'), 2); // 1 ``` -------------------------------- ### setupOverride Method Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/FamilyOverride-class.html Allows a family to override all the different providers associated with an argument. ```APIDOC ## setupOverride Method ### Description Allows a family to override all the different providers associated with an argument. ### Signature void setupOverride(Arg argument, SetupOverride setup) ### Parameters * `argument` (Arg) - The argument for which providers will be overridden. * `setup` (SetupOverride) - The setup configuration for the override. ``` -------------------------------- ### Finding an element's index starting from a specific position Source: https://pub.dev/documentation/game_scaffold_dart/latest/game_scaffold_dart/ListSet/indexOf.html Shows how to find the index of 're' starting the search from index 2. This is useful when you need to find subsequent occurrences of an element. ```dart final notes = ['do', 're', 'mi', 're']; final indexWithStart = notes.indexOf('re', 2); // 3 ```