diff --git a/lib/widget/viewer.dart b/lib/widget/viewer.dart index ac09b03d..dc1079cb 100644 --- a/lib/widget/viewer.dart +++ b/lib/widget/viewer.dart @@ -73,13 +73,34 @@ class _ViewerState extends State with TickerProviderStateMixin { build(BuildContext context) { return AppTheme( child: Scaffold( - body: Builder(builder: (context) => _buildContent(context)), + body: Builder( + builder: (context) => + kIsWeb ? _buildWebContent(context) : _buildContent(context)), ), ); } + Widget _buildWebContent(BuildContext context) { + assert(kIsWeb); + // support switching pages with keyboard on web + return RawKeyboardListener( + onKey: (ev) { + if (!_canSwitchPage()) { + return; + } + if (ev.isKeyPressed(LogicalKeyboardKey.arrowLeft)) { + _switchToLeftImage(); + } else if (ev.isKeyPressed(LogicalKeyboardKey.arrowRight)) { + _switchToRightImage(); + } + }, + focusNode: _pageFocus, + child: _buildContent(context), + ); + } + Widget _buildContent(BuildContext context) { - Widget content = Listener( + return Listener( onPointerDown: (event) { ++_finger; if (_finger >= 2 && _canZoom()) { @@ -133,26 +154,6 @@ class _ViewerState extends State with TickerProviderStateMixin { ), ), ); - - // support switching pages with keyboard on web - if (kIsWeb) { - content = RawKeyboardListener( - onKey: (ev) { - if (!_canSwitchPage()) { - return; - } - if (ev.isKeyPressed(LogicalKeyboardKey.arrowLeft)) { - _switchToLeftImage(); - } else if (ev.isKeyPressed(LogicalKeyboardKey.arrowRight)) { - _switchToRightImage(); - } - }, - focusNode: _pageFocus, - child: content, - ); - } - - return content; } List _buildNavigationButtons(BuildContext context) {