David PHAM-VAN

Add textDirection parameter to PageTheme

# Changelog
## 1.12.0
- Add textDirection parameter to PageTheme
## 1.11.2
- Fix Table.fromTextArray vertical alignment
... ...
... ... @@ -88,6 +88,7 @@ class MultiPage extends Page {
this.maxPages = 20,
PageOrientation orientation,
EdgeInsets margin,
TextDirection textDirection,
}) : _buildList = build,
assert(mainAxisAlignment != null),
assert(crossAxisAlignment != null),
... ... @@ -97,7 +98,9 @@ class MultiPage extends Page {
pageFormat: pageFormat,
margin: margin,
theme: theme,
orientation: orientation);
orientation: orientation,
textDirection: textDirection,
);
final BuildListCallback _buildList;
... ... @@ -168,7 +171,11 @@ class MultiPage extends Page {
int index = 0;
int sameCount = 0;
final Context baseContext =
Context(document: document.document).inheritFrom(calculatedTheme);
Context(document: document.document).inheritFromAll(<Inherited>[
calculatedTheme,
if (pageTheme.textDirection != null)
InheritedDirectionality(pageTheme.textDirection),
]);
final List<Widget> children = _buildList(baseContext);
WidgetContext widgetContext;
... ...
... ... @@ -24,21 +24,23 @@ typedef BuildListCallback = List<Widget> Function(Context context);
enum PageOrientation { natural, landscape, portrait }
class Page {
Page(
{PageTheme pageTheme,
Page({
PageTheme pageTheme,
PdfPageFormat pageFormat,
BuildCallback build,
ThemeData theme,
PageOrientation orientation,
EdgeInsets margin,
bool clip = false})
: assert(
bool clip = false,
TextDirection textDirection,
}) : assert(
pageTheme == null ||
(pageFormat == null &&
theme == null &&
orientation == null &&
margin == null &&
clip == false),
clip == false &&
textDirection == null),
'Don\'t set both pageTheme and other settings'),
pageTheme = pageTheme ??
PageTheme(
... ... @@ -47,6 +49,7 @@ class Page {
margin: margin,
theme: theme,
clip: clip,
textDirection: textDirection,
),
_build = build;
... ... @@ -106,7 +109,11 @@ class Page {
document: document.document,
page: _pdfPage,
canvas: canvas,
).inheritFrom(calculatedTheme);
).inheritFromAll(<Inherited>[
calculatedTheme,
if (pageTheme.textDirection != null)
InheritedDirectionality(pageTheme.textDirection),
]);
Widget background;
Widget content;
... ...
... ... @@ -26,6 +26,7 @@ class PageTheme {
PageOrientation orientation,
EdgeInsets margin,
this.clip = false,
this.textDirection,
}) : pageFormat = pageFormat ?? PdfPageFormat.standard,
orientation = orientation ?? PageOrientation.natural,
_margin = margin;
... ... @@ -44,6 +45,8 @@ class PageTheme {
final bool clip;
final TextDirection textDirection;
bool get mustRotate =>
(orientation == PageOrientation.landscape &&
pageFormat.height > pageFormat.width) ||
... ... @@ -77,6 +80,7 @@ class PageTheme {
PageOrientation orientation,
EdgeInsets margin,
bool clip,
TextDirection textDirection,
}) =>
PageTheme(
pageFormat: pageFormat ?? this.pageFormat,
... ... @@ -86,5 +90,6 @@ class PageTheme {
orientation: orientation ?? this.orientation,
margin: margin ?? this.margin,
clip: clip ?? this.clip,
textDirection: textDirection ?? this.textDirection,
);
}
... ...
... ... @@ -381,7 +381,14 @@ class TextStyle {
'TextStyle(color:$color font:$font size:$fontSize weight:$fontWeight style:$fontStyle letterSpacing:$letterSpacing wordSpacing:$wordSpacing lineSpacing:$lineSpacing height:$height background:$background decoration:$decoration decorationColor:$decorationColor decorationStyle:$decorationStyle decorationThickness:$decorationThickness, renderingMode:$renderingMode)';
}
class Directionality extends StatelessWidget implements Inherited {
class InheritedDirectionality extends Inherited {
const InheritedDirectionality(this.textDirection);
/// The text direction for this subtree.
final TextDirection textDirection;
}
class Directionality extends StatelessWidget {
/// Creates a widget that determines the directionality of text and
/// text-direction-sensitive render objects.
///
... ... @@ -410,15 +417,16 @@ class Directionality extends StatelessWidget implements Inherited {
/// TextDirection textDirection = Directionality.of(context);
/// ```
static TextDirection of(Context context) {
final Directionality widget = context.inherited[Directionality];
return widget?.textDirection ?? TextDirection.ltr;
final InheritedDirectionality inherited =
context.inherited[InheritedDirectionality];
return inherited?.textDirection ?? TextDirection.ltr;
}
@override
Widget build(Context context) {
return InheritedWidget(
build: (Context context) => child,
inherited: this,
inherited: InheritedDirectionality(textDirection),
);
}
}
... ...
... ... @@ -68,9 +68,15 @@ class Context {
}
Context inheritFrom(Inherited object) {
return inheritFromAll(<Inherited>[object]);
}
Context inheritFromAll(Iterable<Inherited> objects) {
final HashMap<Type, Inherited> inherited =
HashMap<Type, Inherited>.of(this.inherited);
for (final Inherited object in objects) {
inherited[object.runtimeType] = object;
}
return copyWith(inherited: inherited);
}
}
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 1.11.2
version: 1.12.0
environment:
sdk: ">=2.3.0 <3.0.0"
... ...