0

I am showing pdf in a pop up alert, here is the code

pdfPreviewOk(String pdfSrc) {
    showDialog(
        context: context,
        builder: (BuildContext context) {return AlertDialog(
            scrollable: true,
            content: Padding(
                padding: const EdgeInsets.all(10.0), child: PdfPreview(pdfSrc)),
          );
        });
  }

and here is PdfPreview code that I get from https://stackoverflow.com/a/64748486/13133893

import 'package:flutter/material.dart';
import 'dart:html' as html;
import 'dart:ui' as ui;

class PdfPreview extends StatelessWidget {
  final String pdfLink;
  PdfPreview(this.pdfLink) {
    // ignore: undefined_prefixed_name
    ui.platformViewRegistry.registerViewFactory('iframe', (int viewId) {
      var iframe = html.IFrameElement();
      iframe.src = pdfLink;
      return iframe;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height * 0.7,
        child: HtmlElementView(viewType: 'iframe'));
  }
}

but the problem is, the string of pdfLink seems didnt't update, I always need to hot reload to get the newest pdfLink. Is there a way to update the value of pdfLink ?

wahyu
  • 1,679
  • 5
  • 35
  • 73

0 Answers0