Aleksei
Committed by David PHAM-VAN

Implement and apply `PdfActionBarTheme`

  1 +import 'package:flutter/foundation.dart';
  2 +import 'package:flutter/material.dart';
  3 +
  4 +class PdfActionBarTheme with Diagnosticable {
  5 + /// Creates a theme for action bar of [PdfPreviewController].
  6 + const PdfActionBarTheme({
  7 + this.backgroundColor,
  8 + this.iconColor,
  9 + this.height,
  10 + this.textStyle,
  11 + this.elevation = 4,
  12 + this.alignment = WrapAlignment.spaceAround,
  13 + });
  14 +
  15 + final Color? backgroundColor;
  16 + final Color? iconColor;
  17 + final double? height;
  18 + final TextStyle? textStyle;
  19 + final double elevation;
  20 + final WrapAlignment alignment;
  21 +
  22 + /// Creates a copy of this object but with the given fields replaced with the
  23 + /// new values.
  24 + PdfActionBarTheme copyWith({
  25 + Color? backgroundColor,
  26 + Color? iconColor,
  27 + double? height,
  28 + TextStyle? textStyle,
  29 + double? elevation,
  30 + WrapAlignment? alignment,
  31 + }) {
  32 + return PdfActionBarTheme(
  33 + backgroundColor: backgroundColor ?? this.backgroundColor,
  34 + iconColor: iconColor ?? this.iconColor,
  35 + height: height ?? this.height,
  36 + textStyle: textStyle ?? this.textStyle,
  37 + elevation: elevation ?? this.elevation,
  38 + alignment: alignment ?? this.alignment,
  39 + );
  40 + }
  41 +
  42 + @override
  43 + int get hashCode => Object.hashAll(
  44 + [backgroundColor, iconColor, height, textStyle, elevation, alignment]);
  45 +
  46 + @override
  47 + bool operator ==(Object other) {
  48 + if (identical(this, other)) {
  49 + return true;
  50 + }
  51 + if (other.runtimeType != runtimeType) {
  52 + return false;
  53 + }
  54 + return other is PdfActionBarTheme &&
  55 + other.backgroundColor == backgroundColor &&
  56 + other.iconColor == iconColor &&
  57 + other.height == height &&
  58 + other.textStyle == textStyle &&
  59 + other.elevation == elevation &&
  60 + other.alignment == alignment;
  61 + }
  62 +
  63 + @override
  64 + void debugFillProperties(DiagnosticPropertiesBuilder properties) {
  65 + super.debugFillProperties(properties);
  66 + properties.add(ColorProperty('backgroundColor', backgroundColor));
  67 + properties.add(ColorProperty('iconColor', iconColor));
  68 + properties.add(DoubleProperty('height', height));
  69 + properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle));
  70 + properties.add(DoubleProperty('elevation', elevation));
  71 + properties.add(DiagnosticsProperty<WrapAlignment>('alignment', alignment,
  72 + defaultValue: WrapAlignment.spaceAround));
  73 + }
  74 +}
@@ -21,6 +21,7 @@ import 'package:pdf/widgets.dart' as pw; @@ -21,6 +21,7 @@ import 'package:pdf/widgets.dart' as pw;
21 import '../callback.dart'; 21 import '../callback.dart';
22 import '../printing.dart'; 22 import '../printing.dart';
23 import '../printing_info.dart'; 23 import '../printing_info.dart';
  24 +import 'action_bar_theme.dart';
24 import 'actions.dart'; 25 import 'actions.dart';
25 import 'controller.dart'; 26 import 'controller.dart';
26 import 'custom.dart'; 27 import 'custom.dart';
@@ -62,6 +63,7 @@ class PdfPreview extends StatefulWidget { @@ -62,6 +63,7 @@ class PdfPreview extends StatefulWidget {
62 this.loadingWidget, 63 this.loadingWidget,
63 this.onPageFormatChanged, 64 this.onPageFormatChanged,
64 this.dpi, 65 this.dpi,
  66 + this.actionBarTheme = const PdfActionBarTheme(),
65 }) : _pagesBuilder = null, 67 }) : _pagesBuilder = null,
66 super(key: key); 68 super(key: key);
67 69
@@ -119,6 +121,7 @@ class PdfPreview extends StatefulWidget { @@ -119,6 +121,7 @@ class PdfPreview extends StatefulWidget {
119 this.loadingWidget, 121 this.loadingWidget,
120 this.onPageFormatChanged, 122 this.onPageFormatChanged,
121 this.dpi, 123 this.dpi,
  124 + this.actionBarTheme = const PdfActionBarTheme(),
122 required CustomPdfPagesBuilder pagesBuilder, 125 required CustomPdfPagesBuilder pagesBuilder,
123 }) : _pagesBuilder = pagesBuilder, 126 }) : _pagesBuilder = pagesBuilder,
124 super(key: key); 127 super(key: key);
@@ -223,6 +226,9 @@ class PdfPreview extends StatefulWidget { @@ -223,6 +226,9 @@ class PdfPreview extends StatefulWidget {
223 /// If not provided, this value is calculated. 226 /// If not provided, this value is calculated.
224 final double? dpi; 227 final double? dpi;
225 228
  229 + /// The style of actions bar.
  230 + final PdfActionBarTheme actionBarTheme;
  231 +
226 /// clients can pass this builder to render 232 /// clients can pass this builder to render
227 /// their own pages. 233 /// their own pages.
228 final CustomPdfPagesBuilder? _pagesBuilder; 234 final CustomPdfPagesBuilder? _pagesBuilder;
@@ -406,16 +412,19 @@ class PdfPreviewState extends State<PdfPreview> { @@ -406,16 +412,19 @@ class PdfPreviewState extends State<PdfPreview> {
406 if (actions.isNotEmpty) 412 if (actions.isNotEmpty)
407 IconTheme.merge( 413 IconTheme.merge(
408 data: IconThemeData( 414 data: IconThemeData(
409 - color: iconColor, 415 + color: widget.actionBarTheme.iconColor ?? iconColor,
410 ), 416 ),
411 child: Material( 417 child: Material(
412 - elevation: 4,  
413 - color: theme.primaryColor, 418 + elevation: widget.actionBarTheme.elevation,
  419 + color:
  420 + widget.actionBarTheme.backgroundColor ?? theme.primaryColor,
  421 + textStyle: widget.actionBarTheme.textStyle,
414 child: SizedBox( 422 child: SizedBox(
415 width: double.infinity, 423 width: double.infinity,
  424 + height: widget.actionBarTheme.height,
416 child: SafeArea( 425 child: SafeArea(
417 child: Wrap( 426 child: Wrap(
418 - alignment: WrapAlignment.spaceAround, 427 + alignment: widget.actionBarTheme.alignment,
419 children: actions, 428 children: actions,
420 ), 429 ),
421 ), 430 ),