Giter Site home page Giter Site logo

gotopage about packages.flutter HOT 7 CLOSED

scerio avatar scerio commented on June 6, 2024 1
gotopage

from packages.flutter.

Comments (7)

emreesen27 avatar emreesen27 commented on June 6, 2024 1

First of all, I'm sorry for my bad English. I am looking for a method that allows the user to go directly to a specific page.

from packages.flutter.

emreesen27 avatar emreesen27 commented on June 6, 2024 1

native_pdf_view
https://pub.dev/packages/native_pdf_view

from packages.flutter.

SergeShkurko avatar SergeShkurko commented on June 6, 2024 1

you can attach PageController

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _actualPageNumber = 1;
  PDFDocument _document;
  
  PageController _pageController; // <---------

  @override
  void initState() {
    _pageController = PageController(
      initialPage: 0
    );
    super.initState();
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
        theme: ThemeData(primaryColor: Colors.white),
        home: Scaffold(
          appBar: AppBar(title: Text('PDFView example')),
          body: FutureBuilder<PDFDocument>(
            future: _getDocument(),
            builder: (_, snapshot) {
              if (snapshot.hasData) {
                return Stack(
                  children: <Widget>[
                    PDFView(
                      controller: _pageController, // <---- attach controller
                      document: snapshot.data,
                      onPageChanged: (page) {
                        setState(() {
                          _actualPageNumber = page;
                        });
                      },
                    ),
                    Align(
                      alignment: Alignment.center,
                      child: Text(
                        '$_actualPageNumber/${snapshot.data.pagesCount}',
                        style: TextStyle(fontSize: 34),
                      ),
                    )
                  ],
                );
              }

              if (snapshot.hasError) {
                return Center(
                  child: Text(
                    'PDF Rendering does not '
                    'support on the system of this version',
                  ),
                );
              }

              return Center(child: CircularProgressIndicator());
            },
          ),
        ),
      );

  Future<PDFDocument> _getDocument() async {
    if (_document != null) {
      return _document;
    }
    if (await hasSupport()) {
      return _document = await PDFDocument.openAsset('assets/sample.pdf');
    } else {
      throw Exception(
        'PDF Rendering does not '
        'support on the system of this version',
      );
    }
  }
}

after call for choose:

_pageController.jumpToPage(pageIndex);

or call for animated choose:

_pageController.animateToPage(
  pageIndex,
  curve: Curves.decelerate,
  duration: Duration(milliseconds: 250),
);

from packages.flutter.

SergeShkurko avatar SergeShkurko commented on June 6, 2024

@emreesen27 What kind of plugin are you talking about?

from packages.flutter.

SergeShkurko avatar SergeShkurko commented on June 6, 2024

plugin native_pdf_view ?

from packages.flutter.

deakjahn avatar deakjahn commented on June 6, 2024

With the caveat, Serge, that you should never load anything into a FutureBuilder like this. Calling the loader function from inside the builder means that it will be called repeatedly for each frame rendered, reloading the PDF each and every time.

Instead, declare a Future variable, not a function:

Future<PDFDocument> document;

Populate it inside initState():

_document = PDFDocument.openAsset('assets/sample.pdf');

then refer to this variable in the builder:

FutureBuilder<PDFDocument>(
        future: _document,

See the official docs for details.

from packages.flutter.

SergeShkurko avatar SergeShkurko commented on June 6, 2024

@deakjahn I know. This code is used a simple example only.

from packages.flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.