view document in browser flutter web

import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:universal_html/html.dart' as html;

class PdfDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final pdf = pw.Document();
    pdf.addPage(pw.Page(
        pageFormat: PdfPageFormat.a4,
        build: (pw.Context context) {
          return pw.Center(
            child: pw.Text("Hello World"),
          );
        }));
    final bytes = pdf.save();
    final blob = html.Blob([bytes], 'application/pdf');

    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text("Open"),
              onPressed: () {
                final url = html.Url.createObjectUrlFromBlob(blob);
                html.window.open(url, "_blank");
                html.Url.revokeObjectUrl(url);
              },
            ),
            RaisedButton(
              child: Text("Download"),
              onPressed: () {
                final url = html.Url.createObjectUrlFromBlob(blob);
                final anchor =
                    html.document.createElement('a') as html.AnchorElement
                      ..href = url
                      ..style.display = 'none'
                      ..download = 'some_name.pdf';
                html.document.body.children.add(anchor);
                anchor.click();
                html.document.body.children.remove(anchor);
                html.Url.revokeObjectUrl(url);
              },
            ),
          ],
          mainAxisAlignment: MainAxisAlignment.center,
        ),
      ),
    );
  }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
flutter web app data flutterweb .env how to add elfsight to flutter web app flutter web channel flutter browser try flutter in browser flutter for web development convert flutter app to web flutter pdf web flutter webpage example Flutter para WEB flutter web app and native app check web compatibility of your flutter plugins websites with flutter and relase load pdf flutter as html flutter andriod studio webview webdev flutterpdf web flutter enable mobile app flutter activate web download webpage flutter flutter in app browser flutter-web uint8listto File channel web flutter convert flutter to web flutter web + mobile + save pdf file how to download pdf flutter web flutter based websites flutter browser app dart flutter web services application download code flutter for web dev flutter web dex flutter chanel stable web save data from flutter website in pdf flutter for web open pdf flutter for web opening pdf flutter web create and download pdf flutter export pdf web and moile can flutter web api be used for mobile app best channel for flutter web flutter web stable channel websites using flutter flutter project online what is flutter web server flutter websites how to update flutter app content from a website flutter webdev how to give websupport in flutter flutter web example download app examples for fllutter web applications does flutter for web compile to javascript What web server does flutter use flutter for web and android and ios flutter build for mobile and web flutter for web android ios flutter download an app generated pdf flutter downloasd in app generated pdf how to download in app genreated pdf in flutter webdev flutter flutter webpage test specify to select only pdf file flutter web flutter projects websites can we develop a website using flutter cannot send http after active flutter web flutter for web example flutter web in stable channel flutter web app example
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source