Skip to content

Commit

Permalink
Add KeyboardListener to viewer page
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Dec 23, 2023
1 parent 09d827d commit ba260c1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HorizontalViewerPage extends StatefulWidget {

class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
late final ViewerController c;
Duration? lastKeyPressedTimeStamp;

@override
void initState() {
Expand Down Expand Up @@ -76,6 +77,24 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
),
),
),
KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if(lastKeyPressedTimeStamp != null){
// print('${event.timeStamp.inSeconds}');
// print('${lastKeyPressedTimeStamp!.inSeconds}');
if((event.timeStamp.inMilliseconds - lastKeyPressedTimeStamp!.inMilliseconds) < 250) return;
}
lastKeyPressedTimeStamp = event.timeStamp;
if(event.physicalKey.debugName == 'Arrow Left'){
c.leftButton();
}
if(event.physicalKey.debugName == 'Arrow Right'){
c.rightButton();
}
},
child: Container(),
),
Align(
alignment: Alignment.center,
child: Container(
Expand Down
29 changes: 26 additions & 3 deletions lib/pages/viewer/vertical_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class VerticalViewerPage extends StatefulWidget {
class _VerticalViewerPageState extends State<VerticalViewerPage>
with SingleTickerProviderStateMixin {
late final ViewerController c;
Duration? lastKeyPressedTimeStamp;

/// this is used for interactive viewer widget
/// double-tap a specific location to zoom in on that location.
Expand Down Expand Up @@ -185,9 +186,31 @@ class _VerticalViewerPageState extends State<VerticalViewerPage>
color: null,
width: width,
height: height,
child: CustomDoubleTapGestureDectector(
onTap: _touchEvent,
onDoubleTap: _doubleTapEvent,
child: Column(
children:[
CustomDoubleTapGestureDectector(
onTap: _touchEvent,
onDoubleTap: _doubleTapEvent,
),
KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if(lastKeyPressedTimeStamp != null){
// print('${event.timeStamp.inSeconds}');
// print('${lastKeyPressedTimeStamp!.inSeconds}');
if((event.timeStamp.inMilliseconds - lastKeyPressedTimeStamp!.inMilliseconds) < 250) return;
}
lastKeyPressedTimeStamp = event.timeStamp;
if(event.physicalKey.debugName == 'Arrow Left'){
c.leftButton();
}
if(event.physicalKey.debugName == 'Arrow Right'){
c.rightButton();
}
},
child: Container(),
),
],
),
);
}
Expand Down

0 comments on commit ba260c1

Please sign in to comment.