Skip to content

Commit

Permalink
Start listen key events
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Nov 20, 2023
1 parent 4587f08 commit bac1e7b
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 56 deletions.
7 changes: 0 additions & 7 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@ PODS:
- Flutter (1.0.0)
- flutter_native_splash (0.0.1):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_native_splash:
:path: ".symlinks/plugins/flutter_native_splash/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"

SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126

PODFILE CHECKSUM: ec8b70a489dd1f81e53ef185cf7ad30fce8f8d00
Expand Down
1 change: 1 addition & 0 deletions lib/src/feature/app/widget/material_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class _MaterialContextState extends State<MaterialContext> {
localizationsDelegates: Localization.localizationDelegates,
supportedLocales: Localization.supportedLocales,
locale: LocaleScope.of(context).locale,
onGenerateTitle: (context) => context.r.appTitle,
home: const GamePage(),
),
);
Expand Down
29 changes: 25 additions & 4 deletions lib/src/feature/game/logic/game_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:ui' show Locale;

import 'package:collection/collection.dart';
import 'package:flutter/services.dart' show KeyEvent, LogicalKeyboardKey;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:wordly/src/feature/game/data/game_repository.dart';
Expand Down Expand Up @@ -29,6 +30,8 @@ sealed class GameEvent with _$GameEvent {
const factory GameEvent.deleteLongPressed() = _GameEventDeleteLongPressed;

const factory GameEvent.enterPressed() = _GameEventEnterPressed;

const factory GameEvent.listenKeyEvent(KeyEvent keyEvent) = _GameEventListenKeyEvent;
}

@Freezed()
Expand Down Expand Up @@ -108,6 +111,7 @@ class GameBloc extends Bloc<GameEvent, GameState> {
enterPressed: (e) => _enterPressed(e, emit),
deletePressed: (e) => _deletePressed(e, emit),
deleteLongPressed: (e) => _deleteLongPressed(e, emit),
listenKeyEvent: (e) => _listenKeyEvent(e, emit),
),
);
}
Expand All @@ -116,10 +120,27 @@ class GameBloc extends Bloc<GameEvent, GameState> {
final IStatisticsRepository _statisticsRepository;
final ILevelRepository _levelRepository;

void _changeDictionary(
_GameEventChangeDictionary event,
Emitter<GameState> emit,
) {
void _listenKeyEvent(_GameEventListenKeyEvent event, Emitter<GameState> emit) {
final key = event.keyEvent;
if (key.logicalKey == LogicalKeyboardKey.enter) {
add(const GameEvent.enterPressed());
return;
}

if (key.logicalKey == LogicalKeyboardKey.delete || key.logicalKey == LogicalKeyboardKey.backspace) {
add(const GameEvent.deletePressed());
return;
}

// TODO(Carapacik): letter
// final letter = KeyboardKeys.fromLogicalKey(event.keyDown.logicalKey);
// if (letter != null) {
// add(GameEvent.letterPressed(letter));
// return;
// }
}

void _changeDictionary(_GameEventChangeDictionary event, Emitter<GameState> emit) {
if (state.dictionary == event.dictionary) {
return;
}
Expand Down
Loading

0 comments on commit bac1e7b

Please sign in to comment.