David PHAM-VAN

Remove deprecated methods

... ... @@ -40,7 +40,7 @@ class MyApp extends StatelessWidget {
}
/// This method takes a page format and generates the Pdf file data
List<int> buildPdf(PdfPageFormat format) {
Future<Uint8List> buildPdf(PdfPageFormat format) async {
// Create the Pdf document
final pw.Document doc = pw.Document();
... ... @@ -60,7 +60,7 @@ class MyApp extends StatelessWidget {
);
// Build and return the final Pdf file data
return doc.save();
return await doc.save();
}
}
```
... ...
... ... @@ -165,5 +165,5 @@ Future<Uint8List> generateDocument(PdfPageFormat format) async {
'Text is available under the Creative Commons Attribution Share Alike License.')
]));
return doc.save();
return await doc.save();
}
... ...
... ... @@ -156,7 +156,7 @@ class Invoice {
),
pw.Container(
decoration: pw.BoxDecoration(
borderRadiusEx:
borderRadius:
const pw.BorderRadius.all(pw.Radius.circular(2)),
color: accentColor,
),
... ... @@ -456,7 +456,7 @@ class Invoice {
border: null,
cellAlignment: pw.Alignment.centerLeft,
headerDecoration: pw.BoxDecoration(
borderRadiusEx: const pw.BorderRadius.all(pw.Radius.circular(2)),
borderRadius: const pw.BorderRadius.all(pw.Radius.circular(2)),
color: baseColor,
),
headerHeight: 25,
... ...
... ... @@ -129,7 +129,7 @@ Future<Uint8List> generateResume(PdfPageFormat format) async {
width: 100,
height: 100,
color: lightGreen,
child: pw.Image.provider(profileImage),
child: pw.Image(profileImage),
),
),
pw.Column(children: <pw.Widget>[
... ... @@ -249,7 +249,7 @@ class _Category extends pw.StatelessWidget {
return pw.Container(
decoration: const pw.BoxDecoration(
color: lightGreen,
borderRadiusEx: pw.BorderRadius.all(pw.Radius.circular(6)),
borderRadius: pw.BorderRadius.all(pw.Radius.circular(6)),
),
margin: const pw.EdgeInsets.only(bottom: 10, top: 20),
padding: const pw.EdgeInsets.fromLTRB(10, 7, 10, 4),
... ...
... ... @@ -23,7 +23,6 @@ import 'document.dart';
import 'font_metrics.dart';
import 'object.dart';
import 'point.dart';
import 'rect.dart';
import 'stream.dart';
import 'type1_font.dart';
import 'type1_fonts.dart';
... ... @@ -162,17 +161,9 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
params['/Encoding'] = const PdfName('/WinAnsiEncoding');
}
/// How many units to move for the next glyph
@Deprecated('Use `glyphMetrics` instead')
double glyphAdvance(int charCode) => glyphMetrics(charCode).advanceWidth;
/// Calculate the [PdfFontMetrics] for this glyph
PdfFontMetrics glyphMetrics(int charCode);
/// Calculate the dimensions of this glyph
@Deprecated('Use `glyphMetrics` instead')
PdfRect glyphBounds(int charCode) => glyphMetrics(charCode).toPdfRect();
/// Calculate the [PdfFontMetrics] for this string
PdfFontMetrics stringMetrics(String s, {double letterSpacing = 0}) {
if (s.isEmpty) {
... ... @@ -193,10 +184,6 @@ See https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management
}
}
/// Calculage the bounding box for this string
@Deprecated('Use `stringMetrics` instead')
PdfRect stringBounds(String s) => stringMetrics(s).toPdfRect();
/// Calculage the unit size of this string
PdfPoint stringSize(String s) {
final metrics = stringMetrics(s);
... ...
... ... @@ -27,10 +27,6 @@ class PdfPageList extends PdfObject {
/// This holds the pages
final List<PdfPage> pages = <PdfPage>[];
/// This returns a specific page. Used by the Pdf class.
@Deprecated('Use pages[index] instead')
PdfPage getPage(int page) => pages[page];
@override
void prepare() {
super.prepare();
... ...
... ... @@ -22,12 +22,6 @@ class PdfPoint {
final double x, y;
@Deprecated('Use `x` instead')
double get w => x;
@Deprecated('Use `y` instead')
double get h => y;
static const PdfPoint zero = PdfPoint(0.0, 0.0);
@override
... ...
... ... @@ -43,24 +43,6 @@ class PdfRect {
double get horizondalCenter => x + width / 2;
double get verticalCenter => y + height / 2;
@Deprecated('Use `left` instead')
double get l => left;
@Deprecated('Use `bottom` instead')
double get b => bottom;
@Deprecated('Use `right` instead')
double get r => right;
@Deprecated('Use `top` instead')
double get t => top;
@Deprecated('Use `width` instead')
double get w => width;
@Deprecated('Use `height` instead')
double get h => height;
@override
String toString() => 'PdfRect($x, $y, $width, $height)';
... ...
... ... @@ -25,37 +25,7 @@ enum BorderStyle { none, solid, dashed, dotted }
@immutable
abstract class BoxBorder {
@Deprecated('Use Border instead')
factory BoxBorder({
bool left = false,
bool top = false,
bool right = false,
bool bottom = false,
PdfColor color = PdfColors.black,
double width = 1.0,
BorderStyle style = BorderStyle.solid,
}) {
assert(color != null);
assert(width != null);
assert(width >= 0.0);
assert(style != null);
return Border(
top: BorderSide(
color: color, width: width, style: top ? style : BorderStyle.none),
bottom: BorderSide(
color: color,
width: width,
style: bottom ? style : BorderStyle.none),
left: BorderSide(
color: color, width: width, style: left ? style : BorderStyle.none),
right: BorderSide(
color: color,
width: width,
style: right ? style : BorderStyle.none));
}
const BoxBorder.P();
const BoxBorder();
BorderSide get top;
BorderSide get bottom;
... ... @@ -198,7 +168,7 @@ class Border extends BoxBorder {
assert(right != null),
assert(bottom != null),
assert(left != null),
super.P();
super();
/// A uniform border with all sides the same color and width.
factory Border.all({
... ... @@ -217,7 +187,7 @@ class Border extends BoxBorder {
right = side,
bottom = side,
left = side,
super.P();
super();
/// Creates a border with symmetrical vertical and horizontal sides.
const Border.symmetric({
... ... @@ -229,7 +199,7 @@ class Border extends BoxBorder {
top = horizontal,
right = vertical,
bottom = horizontal,
super.P();
super();
@override
final BorderSide top;
... ...
... ... @@ -32,18 +32,7 @@ enum DecorationPosition { background, foreground }
@immutable
class DecorationImage {
@Deprecated('Use DecorationImage.provider()')
DecorationImage({
@required PdfImage image,
this.fit = BoxFit.cover,
this.alignment = Alignment.center,
}) : assert(image != null),
assert(fit != null),
assert(alignment != null),
image = ImageProxy(image),
dpi = null;
const DecorationImage.provider({
const DecorationImage({
@required this.image,
this.fit = BoxFit.cover,
this.alignment = Alignment.center,
... ... @@ -313,33 +302,22 @@ class BoxDecoration {
const BoxDecoration({
this.color,
this.border,
@Deprecated('Use borderRadiusEx with `BorderRadius.all(Radius.circular(20))`')
double borderRadius,
BorderRadius borderRadiusEx,
this.borderRadius,
this.boxShadow,
this.gradient,
this.image,
this.shape = BoxShape.rectangle,
}) : assert(shape != null),
assert(!(borderRadius != null && borderRadiusEx != null),
'Don\'t set both borderRadius and borderRadiusEx'),
_borderRadius = borderRadiusEx,
_radius = borderRadius;
}) : assert(shape != null);
/// The color to fill in the background of the box.
final PdfColor color;
final BoxBorder border;
final BorderRadius _borderRadius;
final double _radius;
final BorderRadius borderRadius;
final BoxShape shape;
final DecorationImage image;
final Gradient gradient;
final List<BoxShadow> boxShadow;
BorderRadius get borderRadius =>
_borderRadius ??
(_radius == null ? null : BorderRadius.all(Radius.circular(_radius)));
void paint(
Context context,
PdfRect box, [
... ...
... ... @@ -111,7 +111,7 @@ class FlatButton extends SingleChildWidget {
decoration: decoration ??
BoxDecoration(
color: colorDown,
borderRadiusEx: const BorderRadius.all(Radius.circular(2)),
borderRadius: const BorderRadius.all(Radius.circular(2)),
),
padding: padding ??
const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
... ... @@ -124,7 +124,7 @@ class FlatButton extends SingleChildWidget {
decoration: decoration ??
BoxDecoration(
color: colorRollover,
borderRadiusEx: const BorderRadius.all(Radius.circular(2)),
borderRadius: const BorderRadius.all(Radius.circular(2)),
),
padding: padding ??
const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
... ... @@ -138,7 +138,7 @@ class FlatButton extends SingleChildWidget {
decoration: decoration ??
BoxDecoration(
color: color,
borderRadiusEx: const BorderRadius.all(Radius.circular(2)),
borderRadius: const BorderRadius.all(Radius.circular(2)),
),
padding: padding ??
const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
... ...
... ... @@ -77,18 +77,7 @@ void _drawImageRect(PdfGraphics canvas, PdfImage image, PdfRect sourceRect,
}
class Image extends Widget {
@Deprecated('Use Image.provider instead')
Image(
PdfImage image, {
this.fit = BoxFit.contain,
this.alignment = Alignment.center,
this.width,
this.height,
}) : assert(image != null),
image = ImageProxy(image),
dpi = null;
Image.provider(
this.image, {
this.fit = BoxFit.contain,
this.alignment = Alignment.center,
... ...
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:barcode/barcode.dart';
import 'package:meta/meta.dart';
import 'package:pdf/pdf.dart';
import 'barcode.dart';
import 'decoration.dart';
import 'geometry.dart';
import 'widget.dart';
typedef QrError = void Function(dynamic error);
@Deprecated('Use BarcodeWidget instead')
class QrCodeWidget extends StatelessWidget {
QrCodeWidget({
@required this.data,
this.version,
this.errorCorrectionLevel = BarcodeQRCorrectionLevel.low,
this.color = PdfColors.black,
this.backgroundColor,
this.decoration,
this.margin,
this.onError,
this.gapless = false,
this.size,
this.padding,
});
/// the qr code data
final String data;
/// the qr code version
final int version;
/// the qr code error correction level
final BarcodeQRCorrectionLevel errorCorrectionLevel;
/// the color of the dark squares
final PdfColor color;
final PdfColor backgroundColor;
final EdgeInsets margin;
final QrError onError;
final bool gapless;
final double size;
final EdgeInsets padding;
final BoxDecoration decoration;
@override
Widget build(Context context) {
return BarcodeWidget(
barcode: Barcode.qrCode(
typeNumber: version,
errorCorrectLevel: errorCorrectionLevel,
),
data: data,
backgroundColor: backgroundColor,
color: color,
decoration: decoration,
width: size,
height: size,
margin: margin,
padding: padding,
);
}
}
... ... @@ -58,44 +58,7 @@ enum TableWidth { min, max }
class TableBorder extends Border {
/// Creates a border for a table.
@Deprecated('Use TableBorder.ex instead')
TableBorder(
{bool left = true,
bool top = true,
bool right = true,
bool bottom = true,
bool horizontalInside = true,
bool verticalInside = true,
PdfColor color = PdfColors.black,
double width = 1.0})
: horizontalInside = BorderSide(
color: color,
width: width,
style: horizontalInside ? BorderStyle.solid : BorderStyle.none),
verticalInside = BorderSide(
color: color,
width: width,
style: verticalInside ? BorderStyle.solid : BorderStyle.none),
super(
top: BorderSide(
color: color,
width: width,
style: top ? BorderStyle.solid : BorderStyle.none),
bottom: BorderSide(
color: color,
width: width,
style: bottom ? BorderStyle.solid : BorderStyle.none),
left: BorderSide(
color: color,
width: width,
style: left ? BorderStyle.solid : BorderStyle.none),
right: BorderSide(
color: color,
width: width,
style: right ? BorderStyle.solid : BorderStyle.none));
/// Creates a border for a table.
const TableBorder.ex({
const TableBorder({
BorderSide left = BorderSide.none,
BorderSide top = BorderSide.none,
BorderSide right = BorderSide.none,
... ... @@ -111,7 +74,7 @@ class TableBorder extends Border {
BorderStyle style = BorderStyle.solid,
}) {
final side = BorderSide(color: color, width: width, style: style);
return TableBorder.ex(
return TableBorder(
top: side,
right: side,
bottom: side,
... ... @@ -125,7 +88,7 @@ class TableBorder extends Border {
BorderSide inside = BorderSide.none,
BorderSide outside = BorderSide.none,
}) {
return TableBorder.ex(
return TableBorder(
top: outside,
right: outside,
bottom: outside,
... ... @@ -280,7 +243,6 @@ class Table extends Widget implements SpanningWidget {
factory Table.fromTextArray({
Context context,
@required List<List<dynamic>> data,
@deprecated EdgeInsets margin,
EdgeInsets cellPadding = const EdgeInsets.all(5),
double cellHeight = 0,
Alignment cellAlignment = Alignment.topLeft,
... ... @@ -296,7 +258,7 @@ class Table extends Widget implements SpanningWidget {
Map<int, Alignment> headerAlignments,
TextStyle headerStyle,
OnCellFormat headerFormat,
TableBorder border = const TableBorder.ex(
TableBorder border = const TableBorder(
left: BorderSide(),
right: BorderSide(),
top: BorderSide(),
... ... @@ -315,10 +277,6 @@ class Table extends Widget implements SpanningWidget {
assert(headerCount != null && headerCount >= 0);
assert(cellHeight != null);
if (margin != null) {
cellPadding = margin;
}
if (context != null) {
final theme = Theme.of(context);
headerStyle ??= theme.tableHeader;
... ...
... ... @@ -357,9 +357,6 @@ class TextStyle {
);
}
@Deprecated('use `font` instead')
Font get paintFont => font;
Font get font {
if (fontWeight != FontWeight.bold) {
if (fontStyle != FontStyle.italic) {
... ...
... ... @@ -204,15 +204,6 @@ class Theme extends StatelessWidget {
return context.inherited[ThemeData];
}
@Deprecated('Use ThemeData.base()')
static ThemeData base() => ThemeData.base();
@Deprecated('Use ThemeData.withFont()')
static ThemeData withFont(
{Font base, Font bold, Font italic, Font boldItalic}) =>
ThemeData.withFont(
base: base, bold: bold, italic: italic, boldItalic: boldItalic);
@override
Widget build(Context context) {
return InheritedWidget(
... ...
... ... @@ -47,7 +47,6 @@ export 'src/widgets/page_theme.dart';
export 'src/widgets/partitions.dart';
export 'src/widgets/placeholders.dart';
export 'src/widgets/progress.dart';
export 'src/widgets/qrcode.dart';
export 'src/widgets/stack.dart';
export 'src/widgets/svg.dart';
export 'src/widgets/table.dart';
... ...
... ... @@ -38,8 +38,7 @@ void compute(Message message) {
message.image,
);
pdf.addPage(
Page(build: (Context context) => Center(child: Image.provider(image))));
pdf.addPage(Page(build: (Context context) => Center(child: Image(image))));
message.sendPort.send(pdf.save());
}
... ...
... ... @@ -37,7 +37,7 @@ void main() {
test('Pdf Jpeg Download', () async {
pdf.addPage(Page(
build: (Context context) => Center(child: Image.provider(image)),
build: (Context context) => Center(child: Image(image)),
));
});
... ... @@ -49,7 +49,7 @@ void main() {
crossAxisSpacing: 10,
children: List<Widget>.generate(
images.length,
(int index) => Image.provider(
(int index) => Image(
MemoryImage(
base64.decode(images[index]),
),
... ... @@ -69,7 +69,7 @@ void main() {
return SizedBox(
width: 200,
height: 100,
child: Image.provider(
child: Image(
image,
fit: fit,
),
... ... @@ -82,7 +82,7 @@ void main() {
test('Pdf Image decode', () {
final imageWidgets = imageFiles.map<Widget>(
(String image) => SizedBox(
child: Image.provider(
child: Image(
MemoryImage(
gzip.decode(base64.decode(image)),
),
... ...
... ... @@ -38,7 +38,7 @@ void main() {
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: PdfColors.blue,
borderRadiusEx: const BorderRadius.all(Radius.circular(20)),
borderRadius: const BorderRadius.all(Radius.circular(20)),
border: Border.all(
color: PdfColors.blue800,
width: 2,
... ... @@ -61,8 +61,8 @@ void main() {
alignment: Alignment.center,
decoration: BoxDecoration(
shape: shape,
borderRadiusEx: const BorderRadius.all(Radius.circular(10)),
image: DecorationImage.provider(image: image, fit: fit),
borderRadius: const BorderRadius.all(Radius.circular(10)),
image: DecorationImage(image: image, fit: fit),
),
width: 100,
height: 100,
... ... @@ -109,7 +109,7 @@ void main() {
width: 200.0,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadiusEx: const BorderRadius.all(Radius.circular(40)),
borderRadius: const BorderRadius.all(Radius.circular(40)),
border: Border.all(color: PdfColors.blue, width: 3),
),
),
... ... @@ -126,7 +126,7 @@ void main() {
margin: const EdgeInsets.all(30),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadiusEx: const BorderRadius.all(Radius.circular(20)),
borderRadius: const BorderRadius.all(Radius.circular(20)),
gradient: const LinearGradient(
colors: <PdfColor>[
PdfColors.blue,
... ... @@ -155,7 +155,7 @@ void main() {
margin: const EdgeInsets.all(30),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadiusEx: const BorderRadius.all(Radius.circular(20)),
borderRadius: const BorderRadius.all(Radius.circular(20)),
gradient: const RadialGradient(
colors: <PdfColor>[
PdfColors.blue,
... ...
... ... @@ -51,7 +51,7 @@ List<TableRow> buildTable(
margin: const EdgeInsets.all(5),
decoration: BoxDecoration(
color: color,
borderRadiusEx: const BorderRadius.all(Radius.circular(5)),
borderRadius: const BorderRadius.all(Radius.circular(5)),
),
height: Theme.of(context).tableCell.fontSize),
Container(
... ... @@ -208,7 +208,7 @@ void main() {
border: null,
cellAlignment: Alignment.center,
headerDecoration: const BoxDecoration(
borderRadiusEx: BorderRadius.all(Radius.circular(2)),
borderRadius: BorderRadius.all(Radius.circular(2)),
color: PdfColors.indigo,
),
headerHeight: 25,
... ...
... ... @@ -81,7 +81,7 @@ void main() {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Image.provider(im),
Image(im),
PdfLogo(),
Column(
children: <Widget>[
... ...
... ... @@ -19,57 +19,8 @@ import 'dart:ui' as ui;
import 'package:flutter/rendering.dart' as rdr;
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
/// Loads an image from a Flutter [ui.Image]
/// into a [PdfImage] instance
@Deprecated('Use flutterImageProvider')
Future<PdfImage> pdfImageFromImage(
{@required PdfDocument pdf, @required ui.Image image}) async {
final bytes = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
return PdfImage(pdf,
image: bytes.buffer.asUint8List(),
width: image.width,
height: image.height);
}
/// Loads an image from a Flutter [ImageProvider]
/// into a [PdfImage] instance
@Deprecated('Use flutterImageProvider')
Future<PdfImage> pdfImageFromImageProvider(
{@required PdfDocument pdf,
@required rdr.ImageProvider image,
rdr.ImageConfiguration configuration,
rdr.ImageErrorListener onError}) async {
final completer = Completer<PdfImage>();
final stream = image.resolve(configuration ?? rdr.ImageConfiguration.empty);
rdr.ImageStreamListener listener;
listener = rdr.ImageStreamListener((rdr.ImageInfo image, bool sync) async {
final result = await pdfImageFromImage(pdf: pdf, image: image.image);
if (!completer.isCompleted) {
completer.complete(result);
}
stream.removeListener(listener);
}, onError: (dynamic exception, StackTrace stackTrace) {
if (!completer.isCompleted) {
completer.complete(null);
}
if (onError != null) {
onError(exception, stackTrace);
} else {
// https://groups.google.com/forum/#!topic/flutter-announce/hp1RNIgej38
assert(false, 'image failed to load');
}
});
stream.addListener(listener);
return completer.future;
}
/// Loads an image from a Flutter [ImageProvider]
/// into an [ImageProvider] instance
Future<ImageProvider> flutterImageProvider(
... ...
... ... @@ -167,13 +167,6 @@ mixin Printing {
return PrintingPlatform.instance.info();
}
/// Returns a [PrintingInfo] object representing the capabilities
/// supported for the current platform as a map
@Deprecated('Use Printing.info()')
static Future<Map<dynamic, dynamic>> printingInfo() async {
return (await info()).asMap();
}
/// Convert a PDF to a list of images.
/// ```dart
/// await for (final page in Printing.raster(content)) {
... ... @@ -194,19 +187,4 @@ mixin Printing {
return PrintingPlatform.instance.raster(document, pages, dpi);
}
/// Prints a [PdfDocument] or a pdf stream to a local printer
/// using the platform UI
@Deprecated('use Printing.layoutPdf(onLayout: (_) => document.save());')
static Future<void> printPdf({
@Deprecated('use bytes with document.save()') PdfDocument document,
Uint8List bytes,
}) async {
assert(document != null || bytes != null);
assert(!(document == null && bytes == null));
await layoutPdf(
onLayout: (PdfPageFormat format) =>
document != null ? document.save() : bytes);
}
}
... ...
... ... @@ -53,7 +53,7 @@ void main() {
pw.Page(
build: (pw.Context context) => pw.Center(
child: pw.Container(
child: pw.Image.provider(image),
child: pw.Image(image),
),
),
),
... ...