Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

'package:pdf/src/pdf/format/num.dart': Failed assertion: line 32 pos 12: '!value.isNaN': is not true. #1783

Open
jazzbpn opened this issue Nov 26, 2024 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@jazzbpn
Copy link

jazzbpn commented Nov 26, 2024

'package:pdf/src/pdf/format/num.dart': Failed assertion: line 32 pos 12: '!value.isNaN': is not true.

Screenshot 2024-11-26 at 20 04 53
@jazzbpn jazzbpn added bug Something isn't working needs triage labels Nov 26, 2024
@jacksonb-cs
Copy link

Encountering this while using PdfColorCmyk.fromRgb. The above error is thrown when passing a value of 1 to the green component and 0 to the red and blue components. The same is not true, however, when passing a 1 exclusively to either red or blue. Can reproduce in a Windows Flutter app with the following:

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

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: PdfPreview(
          build: (format) {
            final doc = pw.Document()
              ..addPage(pw.Page(
                pageFormat: format,
                build: (context) {
                  return pw.Container(
                    color: PdfColorCmyk.fromRgb(0, 1, 0), // ASSERTION ERROR
                    // color: PdfColorCmyk.fromRgb(0, 0.99, 0), // OK
                    // color: PdfColorCmyk.fromRgb(0, 0, 1), // OK
                    // color: PdfColorCmyk.fromRgb(1, 0, 0), // OK
                  );
                },
              ));
            return doc.save();
          },
        ),
      ),
    );
  }
}
dependencies:
  flutter:
    sdk: flutter
  pdf: ^3.11.1
  printing: ^5.13.4
[√] Flutter (Channel stable, 3.24.5, on Microsoft Windows [Version 10.0.22631.4460], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.3)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.95.3)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

@jacksonb-cs
Copy link

Interestingly, a slightly different error is thrown using the following:

PdfColorCmyk.fromRgb(1, 0, 1)
'package:pdf/src/pdf/format/num.dart': Failed assertion: line 24 pos 16: 'value != double.negativeInfinity': is not true.

But I don't know if that's intended behavior because the documentation is practically non-existent.

@DavBfr
Copy link
Owner

DavBfr commented Nov 27, 2024

Good catch!
Here's the fix: fc1f97d

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants