Skip to content

Commit

Permalink
fix(flame_console): MemoryRepository can't be const (#3362)
Browse files Browse the repository at this point in the history
Since the `MemoryConsoleCommandsRepository` maintains the commands in
memory and modifies the its internal list, it can't be const.
  • Loading branch information
erickzanardo authored Nov 8, 2024
1 parent 47ba0d8 commit e977bd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ 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<String> commands = const [],
}) : _commands = commands;
MemoryConsoleRepository({
List<String>? commands,
}) : _commands = commands ?? <String>[];

final List<String> _commands;

Expand Down
10 changes: 6 additions & 4 deletions packages/flame_console/lib/src/view/console_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ class ConsoleView<G extends FlameGame> extends StatefulWidget {
required this.game,
required this.onClose,
this.customCommands,
ConsoleRepository? repository,
this.repository,
this.containerBuilder,
this.cursorBuilder,
this.cursorColor,
this.historyBuilder,
this.textStyle,
@visibleForTesting this.controller,
super.key,
}) : repository = repository ?? const MemoryConsoleRepository();
});
final G game;
final List<ConsoleCommand<G>>? customCommands;
final VoidCallback onClose;
final ConsoleRepository repository;
final ConsoleRepository? repository;
final ConsoleController? controller;
final ContainerBuilder? containerBuilder;
Expand Down Expand Up @@ -88,13 +88,15 @@ class _ConsoleViewState extends State<ConsoleView> {
if (widget.customCommands != null) ...widget.customCommands!,
];
late final repository = widget.repository ?? MemoryConsoleRepository();
late final Map<String, ConsoleCommand> _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,
Expand Down

0 comments on commit e977bd4

Please sign in to comment.