Showing
8 changed files
with
94 additions
and
69 deletions
| @@ -59,13 +59,9 @@ Future<Uint8List> generateReport(PdfPageFormat pageFormat) async { | @@ -59,13 +59,9 @@ Future<Uint8List> generateReport(PdfPageFormat pageFormat) async { | ||
| 59 | ), | 59 | ), |
| 60 | overlay: pw.ChartLegend( | 60 | overlay: pw.ChartLegend( |
| 61 | position: const pw.Alignment(-.7, 1), | 61 | position: const pw.Alignment(-.7, 1), |
| 62 | - decoration: const pw.BoxDecoration( | 62 | + decoration: pw.BoxDecoration( |
| 63 | color: PdfColors.white, | 63 | color: PdfColors.white, |
| 64 | - border: pw.BoxBorder( | ||
| 65 | - bottom: true, | ||
| 66 | - top: true, | ||
| 67 | - left: true, | ||
| 68 | - right: true, | 64 | + border: pw.Border.all( |
| 69 | color: PdfColors.black, | 65 | color: PdfColors.black, |
| 70 | width: .5, | 66 | width: .5, |
| 71 | ), | 67 | ), |
| @@ -19,6 +19,7 @@ | @@ -19,6 +19,7 @@ | ||
| 19 | - Remove dependency to the deprecated utf library | 19 | - Remove dependency to the deprecated utf library |
| 20 | - Fix RichText.maxLines with multiple TextSpan | 20 | - Fix RichText.maxLines with multiple TextSpan |
| 21 | - Fix Exif parsing | 21 | - Fix Exif parsing |
| 22 | +- Add Border and BorderSide objects | ||
| 22 | 23 | ||
| 23 | ## 1.12.0 | 24 | ## 1.12.0 |
| 24 | 25 |
| @@ -162,11 +162,7 @@ abstract class Dataset extends Widget { | @@ -162,11 +162,7 @@ abstract class Dataset extends Widget { | ||
| 162 | return Container( | 162 | return Container( |
| 163 | decoration: BoxDecoration( | 163 | decoration: BoxDecoration( |
| 164 | color: color, | 164 | color: color, |
| 165 | - border: const BoxBorder( | ||
| 166 | - left: true, | ||
| 167 | - top: true, | ||
| 168 | - bottom: true, | ||
| 169 | - right: true, | 165 | + border: Border.all( |
| 170 | color: PdfColors.black, | 166 | color: PdfColors.black, |
| 171 | width: .5, | 167 | width: .5, |
| 172 | ), | 168 | ), |
| @@ -152,6 +152,74 @@ class BoxBorder { | @@ -152,6 +152,74 @@ class BoxBorder { | ||
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | +/// A side of a border of a box. | ||
| 156 | +class BorderSide { | ||
| 157 | + /// Creates the side of a border. | ||
| 158 | + const BorderSide({ | ||
| 159 | + this.color = PdfColors.black, | ||
| 160 | + this.width = 1.0, | ||
| 161 | + this.style = BorderStyle.solid, | ||
| 162 | + }); | ||
| 163 | + | ||
| 164 | + /// The color of this side of the border. | ||
| 165 | + final PdfColor color; | ||
| 166 | + | ||
| 167 | + /// The width of this side of the border. | ||
| 168 | + final double width; | ||
| 169 | + | ||
| 170 | + /// The style of this side of the border. | ||
| 171 | + final BorderStyle style; | ||
| 172 | + | ||
| 173 | + BorderSide copyWith({ | ||
| 174 | + PdfColor color, | ||
| 175 | + double width, | ||
| 176 | + BorderStyle style, | ||
| 177 | + }) => | ||
| 178 | + BorderSide( | ||
| 179 | + color: color, | ||
| 180 | + width: width, | ||
| 181 | + style: style, | ||
| 182 | + ); | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +/// A border of a box, comprised of four sides: top, right, bottom, left. | ||
| 186 | +class Border extends BoxBorder { | ||
| 187 | + const Border._(bool left, bool top, bool right, bool bottom, PdfColor color, | ||
| 188 | + double width, BorderStyle style) | ||
| 189 | + : super( | ||
| 190 | + left: left, | ||
| 191 | + top: top, | ||
| 192 | + right: right, | ||
| 193 | + bottom: bottom, | ||
| 194 | + color: color, | ||
| 195 | + width: width, | ||
| 196 | + style: style, | ||
| 197 | + ); | ||
| 198 | + | ||
| 199 | + /// A uniform border with all sides the same color and width. | ||
| 200 | + factory Border.all({ | ||
| 201 | + PdfColor color = PdfColors.black, | ||
| 202 | + double width = 1.0, | ||
| 203 | + BorderStyle style = BorderStyle.solid, | ||
| 204 | + }) => | ||
| 205 | + Border._( | ||
| 206 | + true, | ||
| 207 | + true, | ||
| 208 | + true, | ||
| 209 | + true, | ||
| 210 | + color, | ||
| 211 | + width, | ||
| 212 | + style, | ||
| 213 | + ); | ||
| 214 | + | ||
| 215 | + /// Creates a border whose sides are all the same. | ||
| 216 | + factory Border.fromBorderSide(BorderSide side) => Border.all( | ||
| 217 | + color: side.color, | ||
| 218 | + width: side.width, | ||
| 219 | + style: side.style, | ||
| 220 | + ); | ||
| 221 | +} | ||
| 222 | + | ||
| 155 | @immutable | 223 | @immutable |
| 156 | class DecorationImage { | 224 | class DecorationImage { |
| 157 | @Deprecated('Use DecorationImage.provider()') | 225 | @Deprecated('Use DecorationImage.provider()') |
| @@ -42,12 +42,8 @@ class Checkbox extends SingleChildWidget { | @@ -42,12 +42,8 @@ class Checkbox extends SingleChildWidget { | ||
| 42 | height: height, | 42 | height: height, |
| 43 | margin: const EdgeInsets.all(1), | 43 | margin: const EdgeInsets.all(1), |
| 44 | decoration: decoration ?? | 44 | decoration: decoration ?? |
| 45 | - const BoxDecoration( | ||
| 46 | - border: BoxBorder( | ||
| 47 | - left: true, | ||
| 48 | - top: true, | ||
| 49 | - bottom: true, | ||
| 50 | - right: true, | 45 | + BoxDecoration( |
| 46 | + border: Border.all( | ||
| 51 | color: PdfColors.grey600, | 47 | color: PdfColors.grey600, |
| 52 | width: 2, | 48 | width: 2, |
| 53 | )))); | 49 | )))); |
| @@ -36,15 +36,11 @@ void main() { | @@ -36,15 +36,11 @@ void main() { | ||
| 36 | alignment: Alignment.center, | 36 | alignment: Alignment.center, |
| 37 | margin: const EdgeInsets.all(30), | 37 | margin: const EdgeInsets.all(30), |
| 38 | padding: const EdgeInsets.all(20), | 38 | padding: const EdgeInsets.all(20), |
| 39 | - decoration: const BoxDecoration( | 39 | + decoration: BoxDecoration( |
| 40 | color: PdfColors.blue, | 40 | color: PdfColors.blue, |
| 41 | - borderRadiusEx: BorderRadius.all(Radius.circular(20)), | ||
| 42 | - border: BoxBorder( | 41 | + borderRadiusEx: const BorderRadius.all(Radius.circular(20)), |
| 42 | + border: Border.all( | ||
| 43 | color: PdfColors.blue800, | 43 | color: PdfColors.blue800, |
| 44 | - top: true, | ||
| 45 | - left: true, | ||
| 46 | - right: true, | ||
| 47 | - bottom: true, | ||
| 48 | width: 2, | 44 | width: 2, |
| 49 | )), | 45 | )), |
| 50 | width: 200, | 46 | width: 200, |
| @@ -103,30 +99,18 @@ void main() { | @@ -103,30 +99,18 @@ void main() { | ||
| 103 | Container( | 99 | Container( |
| 104 | height: 200.0, | 100 | height: 200.0, |
| 105 | width: 200.0, | 101 | width: 200.0, |
| 106 | - decoration: const BoxDecoration( | 102 | + decoration: BoxDecoration( |
| 107 | shape: BoxShape.circle, | 103 | shape: BoxShape.circle, |
| 108 | - border: BoxBorder( | ||
| 109 | - bottom: true, | ||
| 110 | - top: true, | ||
| 111 | - left: true, | ||
| 112 | - right: true, | ||
| 113 | - color: PdfColors.blue, | ||
| 114 | - width: 3), | 104 | + border: Border.all(color: PdfColors.blue, width: 3), |
| 115 | ), | 105 | ), |
| 116 | ), | 106 | ), |
| 117 | Container( | 107 | Container( |
| 118 | height: 200.0, | 108 | height: 200.0, |
| 119 | width: 200.0, | 109 | width: 200.0, |
| 120 | - decoration: const BoxDecoration( | 110 | + decoration: BoxDecoration( |
| 121 | shape: BoxShape.rectangle, | 111 | shape: BoxShape.rectangle, |
| 122 | - borderRadiusEx: BorderRadius.all(Radius.circular(40)), | ||
| 123 | - border: BoxBorder( | ||
| 124 | - bottom: true, | ||
| 125 | - top: true, | ||
| 126 | - left: true, | ||
| 127 | - right: true, | ||
| 128 | - color: PdfColors.blue, | ||
| 129 | - width: 3), | 112 | + borderRadiusEx: const BorderRadius.all(Radius.circular(40)), |
| 113 | + border: Border.all(color: PdfColors.blue, width: 3), | ||
| 130 | ), | 114 | ), |
| 131 | ), | 115 | ), |
| 132 | ], | 116 | ], |
| @@ -141,9 +125,9 @@ void main() { | @@ -141,9 +125,9 @@ void main() { | ||
| 141 | alignment: Alignment.center, | 125 | alignment: Alignment.center, |
| 142 | margin: const EdgeInsets.all(30), | 126 | margin: const EdgeInsets.all(30), |
| 143 | padding: const EdgeInsets.all(20), | 127 | padding: const EdgeInsets.all(20), |
| 144 | - decoration: const BoxDecoration( | ||
| 145 | - borderRadiusEx: BorderRadius.all(Radius.circular(20)), | ||
| 146 | - gradient: LinearGradient( | 128 | + decoration: BoxDecoration( |
| 129 | + borderRadiusEx: const BorderRadius.all(Radius.circular(20)), | ||
| 130 | + gradient: const LinearGradient( | ||
| 147 | colors: <PdfColor>[ | 131 | colors: <PdfColor>[ |
| 148 | PdfColors.blue, | 132 | PdfColors.blue, |
| 149 | PdfColors.red, | 133 | PdfColors.red, |
| @@ -154,12 +138,8 @@ void main() { | @@ -154,12 +138,8 @@ void main() { | ||
| 154 | stops: <double>[0, .8, 1.0], | 138 | stops: <double>[0, .8, 1.0], |
| 155 | tileMode: TileMode.clamp, | 139 | tileMode: TileMode.clamp, |
| 156 | ), | 140 | ), |
| 157 | - border: BoxBorder( | 141 | + border: Border.all( |
| 158 | color: PdfColors.blue800, | 142 | color: PdfColors.blue800, |
| 159 | - top: true, | ||
| 160 | - left: true, | ||
| 161 | - right: true, | ||
| 162 | - bottom: true, | ||
| 163 | width: 2, | 143 | width: 2, |
| 164 | )), | 144 | )), |
| 165 | width: 200, | 145 | width: 200, |
| @@ -174,9 +154,9 @@ void main() { | @@ -174,9 +154,9 @@ void main() { | ||
| 174 | alignment: Alignment.center, | 154 | alignment: Alignment.center, |
| 175 | margin: const EdgeInsets.all(30), | 155 | margin: const EdgeInsets.all(30), |
| 176 | padding: const EdgeInsets.all(20), | 156 | padding: const EdgeInsets.all(20), |
| 177 | - decoration: const BoxDecoration( | ||
| 178 | - borderRadiusEx: BorderRadius.all(Radius.circular(20)), | ||
| 179 | - gradient: RadialGradient( | 157 | + decoration: BoxDecoration( |
| 158 | + borderRadiusEx: const BorderRadius.all(Radius.circular(20)), | ||
| 159 | + gradient: const RadialGradient( | ||
| 180 | colors: <PdfColor>[ | 160 | colors: <PdfColor>[ |
| 181 | PdfColors.blue, | 161 | PdfColors.blue, |
| 182 | PdfColors.red, | 162 | PdfColors.red, |
| @@ -187,12 +167,8 @@ void main() { | @@ -187,12 +167,8 @@ void main() { | ||
| 187 | focal: FractionalOffset(.7, .45), | 167 | focal: FractionalOffset(.7, .45), |
| 188 | focalRadius: 1, | 168 | focalRadius: 1, |
| 189 | ), | 169 | ), |
| 190 | - border: BoxBorder( | 170 | + border: Border.all( |
| 191 | color: PdfColors.blue800, | 171 | color: PdfColors.blue800, |
| 192 | - top: true, | ||
| 193 | - left: true, | ||
| 194 | - right: true, | ||
| 195 | - bottom: true, | ||
| 196 | width: 2, | 172 | width: 2, |
| 197 | )), | 173 | )), |
| 198 | width: 200, | 174 | width: 200, |
| @@ -54,11 +54,7 @@ class Decorated extends StatelessWidget { | @@ -54,11 +54,7 @@ class Decorated extends StatelessWidget { | ||
| 54 | padding: const EdgeInsets.all(2), | 54 | padding: const EdgeInsets.all(2), |
| 55 | decoration: BoxDecoration( | 55 | decoration: BoxDecoration( |
| 56 | color: color ?? PdfColors.yellow100, | 56 | color: color ?? PdfColors.yellow100, |
| 57 | - border: const BoxBorder( | ||
| 58 | - left: true, | ||
| 59 | - top: true, | ||
| 60 | - right: true, | ||
| 61 | - bottom: true, | 57 | + border: Border.all( |
| 62 | color: PdfColors.grey, | 58 | color: PdfColors.grey, |
| 63 | width: .5, | 59 | width: .5, |
| 64 | ), | 60 | ), |
| @@ -54,14 +54,10 @@ void main() { | @@ -54,14 +54,10 @@ void main() { | ||
| 54 | Container( | 54 | Container( |
| 55 | padding: const EdgeInsets.all(5), | 55 | padding: const EdgeInsets.all(5), |
| 56 | margin: const EdgeInsets.only(bottom: 10), | 56 | margin: const EdgeInsets.only(bottom: 10), |
| 57 | - decoration: const BoxDecoration( | 57 | + decoration: BoxDecoration( |
| 58 | color: PdfColors.amber, | 58 | color: PdfColors.amber, |
| 59 | - border: BoxBorder( | ||
| 60 | - top: true, | ||
| 61 | - bottom: true, | ||
| 62 | - left: true, | ||
| 63 | - right: true, | ||
| 64 | - width: 2)), | 59 | + border: Border.all(width: 2), |
| 60 | + ), | ||
| 65 | child: Text( | 61 | child: Text( |
| 66 | 'Hello World', | 62 | 'Hello World', |
| 67 | textScaleFactor: 2, | 63 | textScaleFactor: 2, |
-
Please register or login to post a comment