Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2022-01-31 19:04:58 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b237938b52c774e98658362ab4d2c1debd760d80
b237938b
1 parent
ba90a811
Fix dispose state issue
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
58 deletions
printing/CHANGELOG.md
printing/lib/src/preview/actions.dart
printing/lib/src/preview/controller.dart
printing/lib/src/preview/pdf_preview.dart
printing/pubspec.yaml
printing/CHANGELOG.md
View file @
b237938
# Changelog
## 5.7.2
-
Fix dispose state issue
## 5.7.1
-
Update Google Fonts, fixes documentation issues
...
...
printing/lib/src/preview/actions.dart
View file @
b237938
...
...
@@ -237,7 +237,26 @@ class PdfPageFormatAction extends StatelessWidget {
final
theme
=
Theme
.
of
(
context
);
final
iconColor
=
theme
.
primaryIconTheme
.
color
??
Colors
.
white
;
final
data
=
PdfPreviewController
.
listen
(
context
);
final
keys
=
pageFormats
.
keys
.
toList
();
final
_pageFormats
=
<
String
,
PdfPageFormat
>{...
pageFormats
};
var
format
=
data
.
pageFormat
;
final
orientation
=
data
.
horizontal
;
if
(!
_pageFormats
.
values
.
contains
(
data
.
pageFormat
))
{
var
found
=
false
;
for
(
final
f
in
_pageFormats
.
values
)
{
if
(
format
.
portrait
==
f
.
portrait
)
{
format
=
f
;
found
=
true
;
break
;
}
}
if
(!
found
)
{
_pageFormats
[
'---'
]
=
format
;
}
}
final
keys
=
_pageFormats
.
keys
.
toList
()..
sort
();
return
DropdownButton
<
PdfPageFormat
>(
dropdownColor:
theme
.
primaryColor
,
...
...
@@ -245,12 +264,12 @@ class PdfPageFormatAction extends StatelessWidget {
Icons
.
arrow_drop_down
,
color:
iconColor
,
),
value:
data
.
pageF
ormat
,
value:
f
ormat
,
items:
List
<
DropdownMenuItem
<
PdfPageFormat
>>.
generate
(
pageFormats
.
length
,
_
pageFormats
.
length
,
(
int
index
)
{
final
key
=
keys
[
index
];
final
val
=
pageFormats
[
key
]
;
final
val
=
_pageFormats
[
key
]!
;
return
DropdownMenuItem
<
PdfPageFormat
>(
value:
val
,
child:
Text
(
key
,
style:
TextStyle
(
color:
iconColor
)),
...
...
@@ -259,7 +278,8 @@ class PdfPageFormatAction extends StatelessWidget {
),
onChanged:
(
PdfPageFormat
?
pageFormat
)
{
if
(
pageFormat
!=
null
)
{
data
.
pageFormat
=
pageFormat
;
data
.
pageFormat
=
orientation
?
pageFormat
.
landscape
:
pageFormat
.
portrait
;
}
},
);
...
...
printing/lib/src/preview/controller.dart
View file @
b237938
...
...
@@ -19,41 +19,52 @@ import 'package:pdf/pdf.dart';
import
'../callback.dart'
;
mixin
PdfPreviewData
implements
ChangeNotifier
{
// PdfPreviewData(this.build);
typedef
ComputePageFormat
=
PdfPageFormat
Function
();
class
PdfPreviewData
extends
ChangeNotifier
{
PdfPreviewData
({
PdfPageFormat
?
initialPageFormat
,
required
this
.
buildDocument
,
required
Map
<
String
,
PdfPageFormat
>
pageFormats
,
required
ComputePageFormat
onComputeActualPageFormat
,
})
:
assert
(
pageFormats
.
isNotEmpty
),
_onComputeActualPageFormat
=
onComputeActualPageFormat
{
_pageFormat
=
initialPageFormat
??
(
pageFormats
[
localPageFormat
]
??
pageFormats
.
values
.
first
);
}
LayoutCallback
get
buildDocumen
t
;
late
PdfPageFormat
_pageForma
t
;
PdfPageFormat
?
_pageForma
t
;
final
LayoutCallback
buildDocumen
t
;
PdfPageFormat
get
initi
alPageFormat
;
final
ComputePageFormat
_onComputeActu
alPageFormat
;
PdfPageFormat
get
pageFormat
=>
_pageFormat
??
initialPageFormat
;
PdfPageFormat
get
pageFormat
=>
_pageFormat
;
set
pageFormat
(
PdfPageFormat
value
)
{
if
(
_pageFormat
==
value
)
{
return
;
}
if
(
_pageFormat
!=
value
)
{
_pageFormat
=
value
;
notifyListeners
();
}
bool
?
_horizontal
;
}
/// Is the print horizontal
bool
get
horizontal
=>
_
horizontal
??
pageFormat
.
width
>
pageFormat
.
height
;
bool
get
horizontal
=>
_
pageFormat
.
width
>
_
pageFormat
.
height
;
set
horizontal
(
bool
value
)
{
if
(
_horizontal
==
value
)
{
return
;
}
_horizontal
=
value
;
final
format
=
value
?
_pageFormat
.
landscape
:
_pageFormat
.
portrait
;
if
(
format
!=
_pageFormat
)
{
_pageFormat
=
format
;
notifyListeners
();
}
}
/// Computed page format
PdfPageFormat
get
computedPageFormat
=>
horizontal
?
pageFormat
.
landscape
:
pageFormat
.
portrait
;
@Deprecated
(
'Use pageFormat instead'
)
PdfPageFormat
get
computedPageFormat
=>
_pageFormat
;
/// The page format of the document
PdfPageFormat
get
actualPageFormat
=>
_onComputeActualPageFormat
();
String
get
localPageFormat
{
final
locale
=
WidgetsBinding
.
instance
!.
window
.
locale
;
...
...
@@ -65,8 +76,6 @@ mixin PdfPreviewData implements ChangeNotifier {
}
return
'A4'
;
}
PdfPageFormat
get
actualPageFormat
=>
pageFormat
;
}
class
PdfPreviewController
extends
InheritedNotifier
{
...
...
printing/lib/src/preview/pdf_preview.dart
View file @
b237938
...
...
@@ -158,41 +158,17 @@ class PdfPreview extends StatefulWidget {
_PdfPreviewState
createState
()
=>
_PdfPreviewState
();
}
class
_PdfPreviewState
extends
State
<
PdfPreview
>
with
PdfPreviewData
,
ChangeNotifier
{
class
_PdfPreviewState
extends
State
<
PdfPreview
>
{
final
previewWidget
=
GlobalKey
<
PdfPreviewCustomState
>();
late
PdfPreviewData
previewData
;
/// Printing subsystem information
PrintingInfo
?
info
;
var
infoLoaded
=
false
;
@override
LayoutCallback
get
buildDocument
=>
widget
.
build
;
@override
PdfPageFormat
get
initialPageFormat
=>
widget
.
initialPageFormat
??
(
widget
.
pageFormats
.
isNotEmpty
?
(
widget
.
pageFormats
[
localPageFormat
]
??
widget
.
pageFormats
.
values
.
first
)
:
(
PdfPreview
.
_defaultPageFormats
[
localPageFormat
])
??
PdfPreview
.
_defaultPageFormats
.
values
.
first
);
@override
PdfPageFormat
get
pageFormat
{
var
_pageFormat
=
super
.
pageFormat
;
if
(!
widget
.
pageFormats
.
containsValue
(
_pageFormat
))
{
_pageFormat
=
initialPageFormat
;
pageFormat
=
_pageFormat
;
}
return
_pageFormat
;
}
var
infoLoaded
=
false
;
@override
PdfPageFormat
get
actualPageFormat
{
var
format
=
pageFormat
;
PdfPageFormat
computeActualPageFormat
()
{
var
format
=
previewData
.
pageFormat
;
final
pages
=
previewWidget
.
currentState
?.
pages
??
const
[];
final
dpi
=
previewWidget
.
currentState
?.
dpi
??
72
;
...
...
@@ -209,7 +185,16 @@ class _PdfPreviewState extends State<PdfPreview>
@override
void
initState
()
{
addListener
(()
{
previewData
=
PdfPreviewData
(
buildDocument:
widget
.
build
,
pageFormats:
widget
.
pageFormats
.
isNotEmpty
?
widget
.
pageFormats
:
PdfPreview
.
_defaultPageFormats
,
initialPageFormat:
widget
.
initialPageFormat
,
onComputeActualPageFormat:
computeActualPageFormat
,
);
previewData
.
addListener
(()
{
if
(
mounted
)
{
setState
(()
{});
}
...
...
@@ -219,10 +204,24 @@ class _PdfPreviewState extends State<PdfPreview>
}
@override
void
dispose
()
{
previewData
.
dispose
();
super
.
dispose
();
}
@override
void
didUpdateWidget
(
covariant
PdfPreview
oldWidget
)
{
if
(
oldWidget
.
build
!=
widget
.
build
||
widget
.
shouldRepaint
||
widget
.
pageFormats
!=
oldWidget
.
pageFormats
)
{
previewData
=
PdfPreviewData
(
buildDocument:
widget
.
build
,
pageFormats:
widget
.
pageFormats
.
isNotEmpty
?
widget
.
pageFormats
:
PdfPreview
.
_defaultPageFormats
,
initialPageFormat:
previewData
.
pageFormat
,
onComputeActualPageFormat:
computeActualPageFormat
,
);
setState
(()
{});
}
super
.
didUpdateWidget
(
oldWidget
);
...
...
@@ -301,7 +300,7 @@ class _PdfPreviewState extends State<PdfPreview>
}());
return
PdfPreviewController
(
data:
this
,
data:
previewData
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
...
...
@@ -313,7 +312,7 @@ class _PdfPreviewState extends State<PdfPreview>
maxPageWidth:
widget
.
maxPageWidth
,
onError:
widget
.
onError
,
padding:
widget
.
padding
,
pageFormat:
computedP
ageFormat
,
pageFormat:
previewData
.
p
ageFormat
,
pages:
widget
.
pages
,
pdfPreviewPageDecoration:
widget
.
pdfPreviewPageDecoration
,
previewPageMargin:
widget
.
previewPageMargin
,
...
...
printing/pubspec.yaml
View file @
b237938
...
...
@@ -6,7 +6,7 @@ description: >
homepage
:
https://github.com/DavBfr/dart_pdf/tree/master/printing
repository
:
https://github.com/DavBfr/dart_pdf
issue_tracker
:
https://github.com/DavBfr/dart_pdf/issues
version
:
5.7.
1
version
:
5.7.
2
environment
:
sdk
:
"
>=2.12.0
<3.0.0"
...
...
Please
register
or
login
to post a comment