alhappler / alh_pdf_view

13 stars 9 forks source link

use Direction key control the PDF view #29

Closed YuhooZhu closed 1 year ago

YuhooZhu commented 2 years ago

I would like to let the user use Direction key control the PDF view. I understand that it may not be supported at the moment but may I have some indications on how to start if I had to implement this? Thanks a lot! Here is my code:

body: RawKeyboardListener(
        focusNode: FocusNode(),
        autofocus: true,
        onKey: (event) {
          if (event.runtimeType == RawKeyDownEvent) {
            switch (event.logicalKey.keyLabel) {
              case "Arrow Up":
                break;
              case "Arrow Down":
                log("Arrow Down");
                break;
              case "Arrow Left":
                log("Arrow Left");
                break;
              case "Arrow Right":
                log("Arrow Right");
                break;
              case "Enter":
                log("Enter");
                break;
              case "Backspace":
                zoomReset();
                log("Backspace");
                break;
            }
            setState(() {});
          }
        },
        child: Stack(
          children: <Widget>[
            AlhPdfView(
              filePath: widget.path,
              enableSwipe: false,
              swipeHorizontal: false,
              autoSpacing: false,
              pageFling: true,
              pageSnap: true,
              defaultPage: currentPage!,
              fitPolicy: FitPolicy.both,
              enableDefaultScrollHandle: true,
              // gestureRecognizers: Set()
              //   ..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer()
              //     ..onTapDown = (tap) {
              //       print("This one prints");
              //     })),
              // minZoom: 5.0,
              // maxZoom: 6.0,
              onRender: (_pages) {
                setState(() {
                  pages = _pages;
                  isReady = true;
                });
              },
              onError: (error) {
                setState(() {
                  errorMessage = error.toString();
                });
                log(error.toString());
              },
              onPageError: (page, error) {
                setState(() {
                  errorMessage = '$page: ${error.toString()}';
                });
                log('$page: ${error.toString()}');
              },
              onViewCreated: (controller) {
                alhPdfViewController = controller;
              },
              onPageChanged: (int? page, int? total) {
                log('page change: $page/$total');
                setState(() {
                  currentPage = page;
                });
              },
            ),
            errorMessage.isEmpty
                ? !isReady
                    ? Center(
                        child: CircularProgressIndicator(),
                      )
                    : Container()
                : Center(
                    child: Text(errorMessage),
                  )
          ],
        ),
      ),
andreBalh commented 2 years ago

So what you want to have is that the PdfView has a function that says moveToBottom or moveToTop that could be triggered with your keyboard of your mobile phone or with some buttons? So basically you don't want to scroll with your fingers? @YuhooZhu

andreBalh commented 1 year ago

Closing this because of no response