binSaed / flutter_cached_pdfview

Enhanced PDF view for Flutter.
https://pub.dev/packages/flutter_cached_pdfview
MIT License
118 stars 69 forks source link

无法截屏???Can't take a screen shot?? #27

Closed shaoting0730 closed 1 year ago

shaoting0730 commented 4 years ago

image image 无法使用 RepaintBoundary 截屏??? to: 971603961143_ pic 981603961144_ pic

binSaed commented 4 years ago

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

shaoting0730 commented 4 years ago

好的,这是我的完整代码。 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,
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
myselfuser1 commented 1 year ago

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

shaoting0730 commented 1 year ago

@okbye123 thank you~