Giter Site home page Giter Site logo

Comments (3)

SergeShkurko avatar SergeShkurko commented on June 14, 2024
Show code example
import 'package:flutter/material.dart';
import 'package:native_pdf_view/native_pdf_view.dart';
import 'package:native_pdf_view_example/has_support.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  // Create page controller
  final _pageController = PageController();
  int _actualPageNumber = 1;

  @override
  void initState() {
    // listen page number change
    _pageController.addListener(() {
      final pageIndex = _pageController.page.round();
      final pageNumber = pageIndex + 1;
      // Set actual page
      if (pageNumber != _actualPageNumber) {
        setState(() {
          _actualPageNumber = pageNumber;
        });
      }
    });
    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, // set page controller
                      document: snapshot.data,
                    ),
                    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 (await hasSupport()) {
      return PDFDocument.openAsset('assets/sample.pdf');
    } else {
      throw Exception(
        'PDF Rendering does not '
        'support on the system of this version',
      );
    }
  }
}

Снимок экрана 2019-12-13 в 16 54 14 Снимок экрана 2019-12-13 в 16 54 36

@IchordeDionysos will this solve your problem?

from packages.flutter.

SergeShkurko avatar SergeShkurko commented on June 14, 2024

Got your idea, I agree
Added in 2.1.0

from packages.flutter.

IchordeDionysos avatar IchordeDionysos commented on June 14, 2024

Yes, the example you provided worked, but is so think far less beautiful and less intuitive/obvious to us :)

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.