David PHAM-VAN

Fix GridView when empty

... ... @@ -3,11 +3,12 @@
## 1.5.0
- Fix Align debug painting
- Fix GridView when empty
## 1.4.1
- Update dependency to barcode ^1.5.0
- Update type1 font warning url
- Update type1 font warning URL
- Fix Image fit
## 1.4.0
... ...
... ... @@ -56,10 +56,15 @@ class GridView extends MultiChildWidget implements SpanningWidget {
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
if (children.isEmpty) {
box = PdfRect.zero;
return;
}
assert(() {
if (constraints.maxHeight.isInfinite && childAspectRatio.isInfinite) {
print(
'Unable to calculate the GridView dimensions. Please set one the height constraints or childAspectRatio.');
'Unable to calculate the GridView dimensions. Please set the height constraints or childAspectRatio.');
return false;
}
return true;
... ... @@ -208,6 +213,10 @@ class GridView extends MultiChildWidget implements SpanningWidget {
void debugPaint(Context context) {
super.debugPaint(context);
if (children.isEmpty) {
return;
}
context.canvas
..setFillColor(PdfColors.lime)
..moveTo(box.left, box.bottom)
... ...
... ... @@ -33,6 +33,7 @@ import 'widget_basic_test.dart' as widget_basic;
import 'widget_clip_test.dart' as widget_clip;
import 'widget_container_test.dart' as widget_container;
import 'widget_flex_test.dart' as widget_flex;
import 'widget_grid_view_test.dart' as widget_grid_view;
import 'widget_multipage_test.dart' as widget_multipage;
import 'widget_table_test.dart' as widget_table;
import 'widget_test.dart' as widget;
... ... @@ -59,6 +60,7 @@ void main() {
widget_clip.main();
widget_container.main();
widget_flex.main();
widget_grid_view.main();
widget_multipage.main();
widget_table.main();
widget_text.main();
... ...
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// ignore_for_file: omit_local_variable_types
import 'dart:io';
import 'package:pdf/widgets.dart';
import 'package:test/test.dart';
Document pdf;
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
test('Pdf Widgets GridView empty', () {
pdf.addPage(MultiPage(
build: (Context context) => <Widget>[
GridView(
crossAxisCount: 1,
childAspectRatio: 1,
),
]));
});
test('Pdf Widgets GridView Vertical', () {
pdf.addPage(MultiPage(
build: (Context context) => <Widget>[
GridView(
crossAxisCount: 3,
childAspectRatio: 1,
direction: Axis.vertical,
children: List<Widget>.generate(
20, (int index) => Center(child: Text('$index')))),
]));
});
test('Pdf Widgets GridView Horizontal', () {
pdf.addPage(Page(
build: (Context context) => GridView(
crossAxisCount: 5,
direction: Axis.horizontal,
childAspectRatio: 1,
children: List<Widget>.generate(
20, (int index) => Center(child: Text('$index')))),
));
});
tearDownAll(() {
final File file = File('widgets-gridview.pdf');
file.writeAsBytesSync(pdf.save());
});
}
... ...
No preview for this file type