Fix Reader Keyboad listener
This commit is contained in:
parent
8af11754d5
commit
cf17603b03
5 changed files with 74 additions and 35 deletions
|
|
@ -1,4 +1,4 @@
|
|||
arb-dir: lib/l10n
|
||||
template-arb-file: app_en.arb
|
||||
untranslated-messages-file: untranslated_messages.txt
|
||||
# untranslated-messages-file: untranslated_messages.txt
|
||||
output-localization-file: app_localizations.dart
|
||||
|
|
@ -792,6 +792,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
if (hasPrevEpisode)
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (isFullScreen) {
|
||||
_key.currentState?.exitFullscreen();
|
||||
}
|
||||
pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _streamController.getPrevEpisode());
|
||||
|
|
@ -805,6 +808,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
if (hasNextEpisode)
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (isFullScreen) {
|
||||
_key.currentState?.exitFullscreen();
|
||||
}
|
||||
pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _streamController.getNextEpisode(),
|
||||
|
|
@ -1022,7 +1028,7 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
},
|
||||
seekBarPositionColor: primaryColor(context),
|
||||
seekBarThumbColor: primaryColor(context),
|
||||
primaryButtonBar: _mobilePrimaryButtonBar(),
|
||||
primaryButtonBar: _mobilePrimaryButtonBar(isFullScreen),
|
||||
topButtonBarMargin: const EdgeInsets.all(0),
|
||||
topButtonBar: _topButtonBar(context, isFullScreen),
|
||||
bottomButtonBarMargin: const EdgeInsets.only(left: 8, right: 8),
|
||||
|
|
@ -1033,7 +1039,7 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
child: _videoPlayer(context));
|
||||
}
|
||||
|
||||
List<Widget> _mobilePrimaryButtonBar() {
|
||||
List<Widget> _mobilePrimaryButtonBar(bool isFullScreen) {
|
||||
bool hasPrevEpisode = _streamController.getEpisodeIndex().$1 + 1 !=
|
||||
_streamController
|
||||
.getEpisodesLength(_streamController.getEpisodeIndex().$2);
|
||||
|
|
@ -1043,6 +1049,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
IconButton(
|
||||
onPressed: hasPrevEpisode
|
||||
? () {
|
||||
if (isFullScreen) {
|
||||
_key.currentState?.exitFullscreen();
|
||||
}
|
||||
pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _streamController.getPrevEpisode());
|
||||
|
|
@ -1060,6 +1069,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
|
|||
IconButton(
|
||||
onPressed: hasNextEpisode
|
||||
? () {
|
||||
if (isFullScreen) {
|
||||
_key.currentState?.exitFullscreen();
|
||||
}
|
||||
pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _streamController.getNextEpisode(),
|
||||
|
|
|
|||
|
|
@ -268,45 +268,72 @@ class _MangaChapterPageGalleryState
|
|||
_goBack(context);
|
||||
return false;
|
||||
},
|
||||
child: KeyboardListener(
|
||||
child: RawKeyboardListener(
|
||||
autofocus: true,
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent) {
|
||||
return;
|
||||
}
|
||||
onKey: (event) {
|
||||
bool hasNextChapter = _readerController.getChapterIndex().$1 != 0;
|
||||
bool hasPrevChapter = _readerController.getChapterIndex().$1 + 1 !=
|
||||
_readerController
|
||||
.getChaptersLength(_readerController.getChapterIndex().$2);
|
||||
final action = switch (event.logicalKey) {
|
||||
LogicalKeyboardKey.escape => _goBack(context),
|
||||
LogicalKeyboardKey.backspace => _goBack(context),
|
||||
LogicalKeyboardKey.escape =>
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.escape) || event.repeat)
|
||||
? _goBack(context)
|
||||
: null,
|
||||
LogicalKeyboardKey.backspace =>
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.backspace) ||
|
||||
event.repeat)
|
||||
? _goBack(context)
|
||||
: null,
|
||||
LogicalKeyboardKey.arrowUp =>
|
||||
_onBtnTapped(_currentIndex! - 1, true),
|
||||
LogicalKeyboardKey.arrowLeft => _isReverseHorizontal
|
||||
? _onBtnTapped(_currentIndex! + 1, false)
|
||||
: _onBtnTapped(_currentIndex! - 1, true),
|
||||
LogicalKeyboardKey.arrowRight => _isReverseHorizontal
|
||||
? _onBtnTapped(_currentIndex! - 1, true)
|
||||
: _onBtnTapped(_currentIndex! + 1, false),
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.arrowUp) || event.repeat)
|
||||
? _onBtnTapped(_currentIndex! - 1, true)
|
||||
: null,
|
||||
LogicalKeyboardKey.arrowLeft =>
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.arrowLeft) ||
|
||||
event.repeat)
|
||||
? _isReverseHorizontal
|
||||
? _onBtnTapped(_currentIndex! + 1, false)
|
||||
: _onBtnTapped(_currentIndex! - 1, true)
|
||||
: null,
|
||||
LogicalKeyboardKey.arrowRight =>
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.arrowRight) ||
|
||||
event.repeat)
|
||||
? _isReverseHorizontal
|
||||
? _onBtnTapped(_currentIndex! - 1, true)
|
||||
: _onBtnTapped(_currentIndex! + 1, false)
|
||||
: null,
|
||||
LogicalKeyboardKey.arrowDown =>
|
||||
_onBtnTapped(_currentIndex! + 1, true),
|
||||
LogicalKeyboardKey.keyN || LogicalKeyboardKey.pageDown => switch (
|
||||
hasNextChapter) {
|
||||
true => pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _readerController.getNextChapter(),
|
||||
),
|
||||
_ => null
|
||||
},
|
||||
LogicalKeyboardKey.keyP || LogicalKeyboardKey.pageUp => switch (
|
||||
hasPrevChapter) {
|
||||
true => pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _readerController.getPrevChapter()),
|
||||
_ => null
|
||||
},
|
||||
(!event.isKeyPressed(LogicalKeyboardKey.arrowDown) ||
|
||||
event.repeat)
|
||||
? _onBtnTapped(_currentIndex! + 1, true)
|
||||
: null,
|
||||
LogicalKeyboardKey.keyN ||
|
||||
LogicalKeyboardKey.pageDown =>
|
||||
((!event.isKeyPressed(LogicalKeyboardKey.keyN) ||
|
||||
!event.isKeyPressed(LogicalKeyboardKey.pageDown)) ||
|
||||
event.repeat)
|
||||
? switch (hasNextChapter) {
|
||||
true => pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _readerController.getNextChapter(),
|
||||
),
|
||||
_ => null
|
||||
}
|
||||
: null,
|
||||
LogicalKeyboardKey.keyP ||
|
||||
LogicalKeyboardKey.pageUp =>
|
||||
((!event.isKeyPressed(LogicalKeyboardKey.keyP) ||
|
||||
!event.isKeyPressed(LogicalKeyboardKey.pageUp)) ||
|
||||
event.repeat)
|
||||
? switch (hasPrevChapter) {
|
||||
true => pushReplacementMangaReaderView(
|
||||
context: context,
|
||||
chapter: _readerController.getPrevChapter()),
|
||||
_ => null
|
||||
}
|
||||
: null,
|
||||
_ => null
|
||||
};
|
||||
action;
|
||||
|
|
|
|||
|
|
@ -1597,5 +1597,5 @@ packages:
|
|||
source: hosted
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.2.0 <4.0.0"
|
||||
dart: ">=3.2.3 <4.0.0"
|
||||
flutter: ">=3.16.0"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ publish_to: 'none'
|
|||
version: 0.1.45+38
|
||||
|
||||
environment:
|
||||
sdk: '>=3.2.0 <4.0.0'
|
||||
sdk: '>=3.2.3 <4.0.0'
|
||||
|
||||
|
||||
dependencies:
|
||||
|
|
|
|||
Loading…
Reference in a new issue