Git Product home page Git Product logo

Comments (4)

binSaed avatar binSaed commented on June 18, 2024

hi @pheromone
today I don't have I time to debugging to detect the issue
but send to me an example of your code and I will help you as fast

from flutter_cached_pdfview.

shaoting0730 avatar shaoting0730 commented on June 18, 2024

好的,这是我的完整代码。
Okay, here's my complete code.

import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_drag_scale/core/drag_scale_widget.dart';
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
import 'package:nav_router/nav_router.dart';
import 'package:oktoast/oktoast.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';

class LookPdfFile extends StatefulWidget {
  @override
  _LookPdfFileState createState() => _LookPdfFileState();
}

class _LookPdfFileState extends State<LookPdfFile> {
  GlobalKey _rootWidgetKey = GlobalKey();
  List<Uint8List> _images = List();

  /*
  * 截图 + 保存
  * */
  _capturePng() async {
    try {
      RenderRepaintBoundary boundary =
          _rootWidgetKey.currentContext.findRenderObject();
      var image = await boundary.toImage(pixelRatio: 3.0);
      ByteData byteData = await image.toByteData(format: ImageByteFormat.png);

      final result =
          await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());

      showToast('图片已经保存至相册');
    } catch (e) {
      print(e);
    }
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Stack(
          children: [
            //       pdf + 截屏
            SizedBox(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              child: RepaintBoundary(
                key: _rootWidgetKey,
                child: Stack(
                  children: [
                    DragScaleContainer(
                      doubleTapStillScale: true,
                      child: PDF().cachedFromUrl(
                        'http://africau.edu/images/default/sample.pdf',
                        placeholder: (progress) =>
                            Center(child: Text('$progress %')),
                        errorWidget: (error) =>
                            Center(child: Text(error.toString())),
                      ),
                    ),
                    Positioned(
                      top: MediaQuery.of(context).size.height / 2,
                      left: MediaQuery.of(context).size.width / 2,
                      child: Icon(
                        Icons.arrow_downward,
                        color: Colors.blue,
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Positioned(
              top: 0,
              left: 0,
              width: MediaQuery.of(context).size.width,
              child: Row(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: InkWell(
                      onTap: () {
                        pop(_images);
                      },
                      child: Text(
                        '< 返回',
                        style: TextStyle(
                          fontSize: 18,
                          color: Colors.blue,
                        ),
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(right: 10),
                    child: InkWell(
                      onTap: _capturePng,
                      child: Icon(
                        Icons.camera_alt,
                        color: Colors.blue,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

from flutter_cached_pdfview.

pritish-thub avatar pritish-thub commented on June 18, 2024

This will help https://www.youtube.com/watch?v=gAUVz0U7eyA

from flutter_cached_pdfview.

shaoting0730 avatar shaoting0730 commented on June 18, 2024

@okbye123 thank you~

from flutter_cached_pdfview.

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.