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 6915b66c3f..9f9a679c4a 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 5de91bd52a..8a7f830918 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,