I was trying to use PDF library for Flutter using the package here
the idea is to create something like this: which is the example in the package's page.
the problem is that if I run the Demo example there, it works exactly as the example, which is fine.
But if I create a new project and COPY/PASTE all *.dart files and pubspec.yaml : it doesn't work. The script creates the file, I can downloading it or print it as well, but doesn't show the file.
I'm not using project with more information, I'm just copying the same code to a clean project and I'm also getting packages in pubspec.yaml
did someone has the same problem? I will post an image below.
in addition: I'M RUNNING BOTH PROJECTS AS FLUTTER WEB, IN CHROME
thank you for your help!! :)
below a 'hello world' code that showed me the same error..
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:flutter/material.dart';
import 'package:printing/printing.dart';
import 'dart:typed_data';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
final pw.Document doc = pw.Document();
@override
Widget build(BuildContext context) {
Future<Uint8List> generateDocument(PdfPageFormat format) async {
doc.addPage(pw.Page(
pageFormat: PdfPageFormat.standard,
build: (pw.Context context) {
return pw.Center(
child: pw.Text("Hello World"),
); // Center
})); // Page
return doc.save();
}
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: PdfPreview(
maxPageWidth: 700,
build: generateDocument,
),
),
);
}
}