Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flame_console): MemoryRepository can't be const #3362

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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