David PHAM-VAN

Fix GridView when empty

@@ -3,11 +3,12 @@ @@ -3,11 +3,12 @@
3 ## 1.5.0 3 ## 1.5.0
4 4
5 - Fix Align debug painting 5 - Fix Align debug painting
  6 +- Fix GridView when empty
6 7
7 ## 1.4.1 8 ## 1.4.1
8 9
9 - Update dependency to barcode ^1.5.0 10 - Update dependency to barcode ^1.5.0
10 -- Update type1 font warning url 11 +- Update type1 font warning URL
11 - Fix Image fit 12 - Fix Image fit
12 13
13 ## 1.4.0 14 ## 1.4.0
@@ -56,10 +56,15 @@ class GridView extends MultiChildWidget implements SpanningWidget { @@ -56,10 +56,15 @@ class GridView extends MultiChildWidget implements SpanningWidget {
56 @override 56 @override
57 void layout(Context context, BoxConstraints constraints, 57 void layout(Context context, BoxConstraints constraints,
58 {bool parentUsesSize = false}) { 58 {bool parentUsesSize = false}) {
  59 + if (children.isEmpty) {
  60 + box = PdfRect.zero;
  61 + return;
  62 + }
  63 +
59 assert(() { 64 assert(() {
60 if (constraints.maxHeight.isInfinite && childAspectRatio.isInfinite) { 65 if (constraints.maxHeight.isInfinite && childAspectRatio.isInfinite) {
61 print( 66 print(
62 - 'Unable to calculate the GridView dimensions. Please set one the height constraints or childAspectRatio.'); 67 + 'Unable to calculate the GridView dimensions. Please set the height constraints or childAspectRatio.');
63 return false; 68 return false;
64 } 69 }
65 return true; 70 return true;
@@ -208,6 +213,10 @@ class GridView extends MultiChildWidget implements SpanningWidget { @@ -208,6 +213,10 @@ class GridView extends MultiChildWidget implements SpanningWidget {
208 void debugPaint(Context context) { 213 void debugPaint(Context context) {
209 super.debugPaint(context); 214 super.debugPaint(context);
210 215
  216 + if (children.isEmpty) {
  217 + return;
  218 + }
  219 +
211 context.canvas 220 context.canvas
212 ..setFillColor(PdfColors.lime) 221 ..setFillColor(PdfColors.lime)
213 ..moveTo(box.left, box.bottom) 222 ..moveTo(box.left, box.bottom)
@@ -33,6 +33,7 @@ import 'widget_basic_test.dart' as widget_basic; @@ -33,6 +33,7 @@ import 'widget_basic_test.dart' as widget_basic;
33 import 'widget_clip_test.dart' as widget_clip; 33 import 'widget_clip_test.dart' as widget_clip;
34 import 'widget_container_test.dart' as widget_container; 34 import 'widget_container_test.dart' as widget_container;
35 import 'widget_flex_test.dart' as widget_flex; 35 import 'widget_flex_test.dart' as widget_flex;
  36 +import 'widget_grid_view_test.dart' as widget_grid_view;
36 import 'widget_multipage_test.dart' as widget_multipage; 37 import 'widget_multipage_test.dart' as widget_multipage;
37 import 'widget_table_test.dart' as widget_table; 38 import 'widget_table_test.dart' as widget_table;
38 import 'widget_test.dart' as widget; 39 import 'widget_test.dart' as widget;
@@ -59,6 +60,7 @@ void main() { @@ -59,6 +60,7 @@ void main() {
59 widget_clip.main(); 60 widget_clip.main();
60 widget_container.main(); 61 widget_container.main();
61 widget_flex.main(); 62 widget_flex.main();
  63 + widget_grid_view.main();
62 widget_multipage.main(); 64 widget_multipage.main();
63 widget_table.main(); 65 widget_table.main();
64 widget_text.main(); 66 widget_text.main();
  1 +/*
  2 + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +
  17 +// ignore_for_file: omit_local_variable_types
  18 +
  19 +import 'dart:io';
  20 +
  21 +import 'package:pdf/widgets.dart';
  22 +import 'package:test/test.dart';
  23 +
  24 +Document pdf;
  25 +
  26 +void main() {
  27 + setUpAll(() {
  28 + Document.debug = true;
  29 + pdf = Document();
  30 + });
  31 +
  32 + test('Pdf Widgets GridView empty', () {
  33 + pdf.addPage(MultiPage(
  34 + build: (Context context) => <Widget>[
  35 + GridView(
  36 + crossAxisCount: 1,
  37 + childAspectRatio: 1,
  38 + ),
  39 + ]));
  40 + });
  41 +
  42 + test('Pdf Widgets GridView Vertical', () {
  43 + pdf.addPage(MultiPage(
  44 + build: (Context context) => <Widget>[
  45 + GridView(
  46 + crossAxisCount: 3,
  47 + childAspectRatio: 1,
  48 + direction: Axis.vertical,
  49 + children: List<Widget>.generate(
  50 + 20, (int index) => Center(child: Text('$index')))),
  51 + ]));
  52 + });
  53 +
  54 + test('Pdf Widgets GridView Horizontal', () {
  55 + pdf.addPage(Page(
  56 + build: (Context context) => GridView(
  57 + crossAxisCount: 5,
  58 + direction: Axis.horizontal,
  59 + childAspectRatio: 1,
  60 + children: List<Widget>.generate(
  61 + 20, (int index) => Center(child: Text('$index')))),
  62 + ));
  63 + });
  64 +
  65 + tearDownAll(() {
  66 + final File file = File('widgets-gridview.pdf');
  67 + file.writeAsBytesSync(pdf.save());
  68 + });
  69 +}
No preview for this file type