From 7068e2ec1c0667a1bdf8b1ddabd0da53496b2b43 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Thu, 31 Oct 2024 17:37:03 -0300 Subject: [PATCH 1/3] fix(flame_console): MemoryRepository can't be const --- .../lib/src/repository/memory_console_repository.dart | 10 ++++++---- packages/flame_console/lib/src/view/console_view.dart | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/flame_console/lib/src/repository/memory_console_repository.dart b/packages/flame_console/lib/src/repository/memory_console_repository.dart index 6915b66c3f3..9f9a679c4ac 100644 --- a/packages/flame_console/lib/src/repository/memory_console_repository.dart +++ b/packages/flame_console/lib/src/repository/memory_console_repository.dart @@ -3,11 +3,13 @@ import 'package:flame_console/flame_console.dart'; /// An implementation of a [ConsoleRepository] that stores the command history /// in memory. class MemoryConsoleRepository extends ConsoleRepository { - const MemoryConsoleRepository({ - List commands = const [], - }) : _commands = commands; + MemoryConsoleRepository({ + List? commands, + }) { + _commands = commands ?? []; + } - final List _commands; + late final List _commands; @override Future addToCommandHistory(String command) async { diff --git a/packages/flame_console/lib/src/view/console_view.dart b/packages/flame_console/lib/src/view/console_view.dart index 5de91bd52a6..8a7f830918e 100644 --- a/packages/flame_console/lib/src/view/console_view.dart +++ b/packages/flame_console/lib/src/view/console_view.dart @@ -43,7 +43,7 @@ class ConsoleView extends StatefulWidget { required this.game, required this.onClose, this.customCommands, - ConsoleRepository? repository, + this.repository, this.containerBuilder, this.cursorBuilder, this.cursorColor, @@ -51,12 +51,12 @@ class ConsoleView extends StatefulWidget { this.textStyle, @visibleForTesting this.controller, super.key, - }) : repository = repository ?? const MemoryConsoleRepository(); + }); final G game; final List>? customCommands; final VoidCallback onClose; - final ConsoleRepository repository; + final ConsoleRepository? repository; final ConsoleController? controller; final ContainerBuilder? containerBuilder; @@ -88,13 +88,15 @@ class _ConsoleViewState extends State { if (widget.customCommands != null) ...widget.customCommands!, ]; + late final repository = widget.repository ?? MemoryConsoleRepository(); + late final Map _commandsMap = { for (final command in _commandList) command.name: command, }; late final _controller = widget.controller ?? ConsoleController( - repository: widget.repository, + repository: repository, game: widget.game, scrollController: _scrollController, onClose: widget.onClose, From 0484a4987ae4f8fc549af1c3ece22a576999d05b Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Fri, 8 Nov 2024 10:19:12 -0300 Subject: [PATCH 2/3] PR suggestion --- .../lib/src/repository/memory_console_repository.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/flame_console/lib/src/repository/memory_console_repository.dart b/packages/flame_console/lib/src/repository/memory_console_repository.dart index 9f9a679c4ac..1f7edfccd13 100644 --- a/packages/flame_console/lib/src/repository/memory_console_repository.dart +++ b/packages/flame_console/lib/src/repository/memory_console_repository.dart @@ -5,9 +5,7 @@ import 'package:flame_console/flame_console.dart'; class MemoryConsoleRepository extends ConsoleRepository { MemoryConsoleRepository({ List? commands, - }) { - _commands = commands ?? []; - } + }) : _commands = commands ?? []; late final List _commands; From 242a99b5db0e2ef746e836b5b05f73164ed36473 Mon Sep 17 00:00:00 2001 From: Erick Date: Fri, 8 Nov 2024 10:26:23 -0300 Subject: [PATCH 3/3] Update packages/flame_console/lib/src/repository/memory_console_repository.dart --- .../lib/src/repository/memory_console_repository.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flame_console/lib/src/repository/memory_console_repository.dart b/packages/flame_console/lib/src/repository/memory_console_repository.dart index 1f7edfccd13..c2e59e5e9cc 100644 --- a/packages/flame_console/lib/src/repository/memory_console_repository.dart +++ b/packages/flame_console/lib/src/repository/memory_console_repository.dart @@ -7,7 +7,7 @@ class MemoryConsoleRepository extends ConsoleRepository { List? commands, }) : _commands = commands ?? []; - late final List _commands; + final List _commands; @override Future addToCommandHistory(String command) async {