David PHAM-VAN

Fix Theme creation

... ... @@ -3,6 +3,7 @@
## 1.3.22
- Fix Text alignment
- Fix Theme creation
## 1.3.21
... ...
... ... @@ -111,7 +111,10 @@ class TextStyle {
this.decorationStyle,
this.decorationThickness,
}) : assert(inherit || color != null),
assert(inherit || font != null),
assert(inherit || fontNormal != null),
assert(inherit || fontBold != null),
assert(inherit || fontItalic != null),
assert(inherit || fontBoldItalic != null),
assert(inherit || fontSize != null),
assert(inherit || fontWeight != null),
assert(inherit || fontStyle != null),
... ... @@ -120,7 +123,6 @@ class TextStyle {
assert(inherit || lineSpacing != null),
assert(inherit || height != null),
assert(inherit || decoration != null),
assert(inherit || decorationColor != null),
assert(inherit || decorationStyle != null),
assert(inherit || decorationThickness != null),
fontNormal = fontNormal ??
... ... @@ -142,6 +144,7 @@ class TextStyle {
factory TextStyle.defaultStyle() {
return TextStyle(
inherit: false,
color: PdfColors.black,
fontNormal: Font.helvetica(),
fontBold: Font.helveticaBold(),
... ...
... ... @@ -18,7 +18,36 @@ part of widget;
@immutable
class Theme extends Inherited {
const Theme({
factory Theme({
TextStyle defaultTextStyle,
TextStyle paragraphStyle,
TextStyle header0,
TextStyle header1,
TextStyle header2,
TextStyle header3,
TextStyle header4,
TextStyle header5,
TextStyle bulletStyle,
TextStyle tableHeader,
TextStyle tableCell,
}) {
final Theme base = Theme.base();
return base.copyWith(
defaultTextStyle: defaultTextStyle,
paragraphStyle: paragraphStyle,
bulletStyle: bulletStyle,
header0: header0,
header1: header1,
header2: header2,
header3: header3,
header4: header4,
header5: header5,
tableHeader: tableHeader,
tableCell: tableCell,
);
}
Theme._({
@required this.defaultTextStyle,
@required this.paragraphStyle,
@required this.header0,
... ... @@ -30,7 +59,17 @@ class Theme extends Inherited {
@required this.bulletStyle,
@required this.tableHeader,
@required this.tableCell,
});
}) : assert(defaultTextStyle.inherit == false),
assert(paragraphStyle.inherit == false),
assert(header0.inherit == false),
assert(header1.inherit == false),
assert(header2.inherit == false),
assert(header3.inherit == false),
assert(header4.inherit == false),
assert(header5.inherit == false),
assert(bulletStyle.inherit == false),
assert(tableHeader.inherit == false),
assert(tableCell.inherit == false);
factory Theme.withFont({Font base, Font bold, Font italic, Font boldItalic}) {
final TextStyle defaultStyle = TextStyle.defaultStyle().copyWith(
... ... @@ -41,19 +80,20 @@ class Theme extends Inherited {
fontBoldItalic: boldItalic);
final double fontSize = defaultStyle.fontSize;
return Theme(
defaultTextStyle: defaultStyle,
paragraphStyle: defaultStyle.copyWith(lineSpacing: 5),
bulletStyle: defaultStyle.copyWith(lineSpacing: 5),
header0: defaultStyle.copyWith(fontSize: fontSize * 2.0),
header1: defaultStyle.copyWith(fontSize: fontSize * 1.5),
header2: defaultStyle.copyWith(fontSize: fontSize * 1.4),
header3: defaultStyle.copyWith(fontSize: fontSize * 1.3),
header4: defaultStyle.copyWith(fontSize: fontSize * 1.2),
header5: defaultStyle.copyWith(fontSize: fontSize * 1.1),
tableHeader: defaultStyle.copyWith(
fontSize: fontSize * 0.8, fontWeight: FontWeight.bold),
tableCell: defaultStyle.copyWith(fontSize: fontSize * 0.8));
return Theme._(
defaultTextStyle: defaultStyle,
paragraphStyle: defaultStyle.copyWith(lineSpacing: 5),
bulletStyle: defaultStyle.copyWith(lineSpacing: 5),
header0: defaultStyle.copyWith(fontSize: fontSize * 2.0),
header1: defaultStyle.copyWith(fontSize: fontSize * 1.5),
header2: defaultStyle.copyWith(fontSize: fontSize * 1.4),
header3: defaultStyle.copyWith(fontSize: fontSize * 1.3),
header4: defaultStyle.copyWith(fontSize: fontSize * 1.2),
header5: defaultStyle.copyWith(fontSize: fontSize * 1.1),
tableHeader: defaultStyle.copyWith(
fontSize: fontSize * 0.8, fontWeight: FontWeight.bold),
tableCell: defaultStyle.copyWith(fontSize: fontSize * 0.8),
);
}
factory Theme.base() => Theme.withFont();
... ... @@ -71,18 +111,19 @@ class Theme extends Inherited {
TextStyle tableHeader,
TextStyle tableCell,
}) =>
Theme(
defaultTextStyle: defaultTextStyle ?? this.defaultTextStyle,
paragraphStyle: paragraphStyle ?? this.paragraphStyle,
bulletStyle: bulletStyle ?? this.bulletStyle,
header0: header0 ?? this.header0,
header1: header1 ?? this.header1,
header2: header2 ?? this.header2,
header3: header3 ?? this.header3,
header4: header4 ?? this.header4,
header5: header5 ?? this.header5,
tableHeader: tableHeader ?? this.tableHeader,
tableCell: tableCell ?? this.tableCell);
Theme._(
defaultTextStyle: this.defaultTextStyle.merge(defaultTextStyle),
paragraphStyle: this.paragraphStyle.merge(paragraphStyle),
bulletStyle: this.bulletStyle.merge(bulletStyle),
header0: this.header0.merge(header0),
header1: this.header1.merge(header1),
header2: this.header2.merge(header2),
header3: this.header3.merge(header3),
header4: this.header4.merge(header4),
header5: this.header5.merge(header5),
tableHeader: this.tableHeader.merge(tableHeader),
tableCell: this.tableCell.merge(tableCell),
);
static Theme of(Context context) {
return context.inherited[Theme];
... ...
... ... @@ -117,6 +117,19 @@ void main() {
));
});
test('Theme Page 4', () {
pdf.addPage(Page(
pageFormat: PdfPageFormat.a4,
orientation: PageOrientation.portrait,
margin: EdgeInsets.all(8.0),
theme: Theme(
defaultTextStyle: TextStyle(font: Font.courier(), fontSize: 10.0),
),
build: (Context context) {
return Center(child: Text('Text'));
}));
});
tearDownAll(() {
final File file = File('widgets-theme.pdf');
file.writeAsBytesSync(pdf.save());
... ...