* Print the error message multiple times to avoid overlap with status bar and add paragraph to mock_canvas
This commit is contained in:
@@ -9,6 +9,8 @@ import 'object.dart';
|
||||
|
||||
const double _kMaxWidth = 100000.0;
|
||||
const double _kMaxHeight = 100000.0;
|
||||
// Line length to fit small phones without dynamically checking size.
|
||||
const String line = '\n────────────────────\n\n';
|
||||
|
||||
/// A render object used as a placeholder when an error occurs.
|
||||
///
|
||||
@@ -42,7 +44,10 @@ class RenderErrorBox extends RenderBox {
|
||||
// see the paragraph.dart file and the RenderParagraph class.
|
||||
ui.ParagraphBuilder builder = new ui.ParagraphBuilder(paragraphStyle);
|
||||
builder.pushStyle(textStyle);
|
||||
builder.addText(message);
|
||||
builder.addText(
|
||||
'$message$line$message$line$message$line$message$line$message$line$message$line'
|
||||
'$message$line$message$line$message$line$message$line$message$line$message'
|
||||
);
|
||||
_paragraph = builder.build();
|
||||
}
|
||||
} catch (e) { }
|
||||
@@ -79,14 +84,15 @@ class RenderErrorBox extends RenderBox {
|
||||
|
||||
/// The text style to use when painting [RenderErrorBox] objects.
|
||||
static ui.TextStyle textStyle = new ui.TextStyle(
|
||||
color: const Color(0xFFFFFF00),
|
||||
color: const Color(0xFFFFFF66),
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 7.0
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.bold
|
||||
);
|
||||
|
||||
/// The paragraph style to use when painting [RenderErrorBox] objects.
|
||||
static ui.ParagraphStyle paragraphStyle = new ui.ParagraphStyle(
|
||||
lineHeight: 0.25 // TODO(ianh): https://github.com/flutter/flutter/issues/2460 will affect this
|
||||
lineHeight: 0.85
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -104,6 +110,7 @@ class RenderErrorBox extends RenderBox {
|
||||
width = size.width;
|
||||
}
|
||||
_paragraph.layout(new ui.ParagraphConstraints(width: width));
|
||||
|
||||
context.canvas.drawParagraph(_paragraph, offset);
|
||||
}
|
||||
} catch (e) { }
|
||||
|
||||
22
packages/flutter/test/rendering/error_test.dart
Normal file
22
packages/flutter/test/rendering/error_test.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../rendering/mock_canvas.dart';
|
||||
|
||||
/// Unit tests error.dart's usage via ErrorWidget.
|
||||
void main() {
|
||||
final String errorMessage = 'Some error message';
|
||||
|
||||
testWidgets('test draw error paragraph', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new ErrorWidget(new Exception(errorMessage)));
|
||||
|
||||
expect(find.byType(ErrorWidget), paints
|
||||
..rect(rect: new Rect.fromLTWH(0.0, 0.0, 800.0, 600.0))
|
||||
..paragraph(offset: Offset.zero));
|
||||
});
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui show Paragraph;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -182,6 +184,15 @@ abstract class PaintPattern {
|
||||
/// [Canvas.drawLine] call are ignored.
|
||||
void line({ Color color, bool hasMaskFilter, PaintingStyle style });
|
||||
|
||||
/// Indicates that a paragraph is expected next.
|
||||
///
|
||||
/// Calls are skipped until a call to [Canvas.drawParagraph] is found. Any
|
||||
/// arguments that are passed to this method are compared to the actual
|
||||
/// [Canvas.drawParagraph] call's argument, and any mismatches result in failure.
|
||||
///
|
||||
/// If no call to [Canvas.drawParagraph] was made, then this results in failure.
|
||||
void paragraph({ ui.Paragraph paragraph, Offset offset });
|
||||
|
||||
/// Provides a custom matcher.
|
||||
///
|
||||
/// Each method call after the last matched call (if any) will be passed to
|
||||
@@ -269,6 +280,11 @@ class _TestRecordingCanvasPatternMatcher extends Matcher implements PaintPattern
|
||||
_predicates.add(new _LinePaintPredicate(color: color, hasMaskFilter: hasMaskFilter, style: style));
|
||||
}
|
||||
|
||||
@override
|
||||
void paragraph({ ui.Paragraph paragraph, Offset offset }) {
|
||||
_predicates.add(new _FunctionPaintPredicate(#drawParagraph, <dynamic>[paragraph, offset]));
|
||||
}
|
||||
|
||||
@override
|
||||
void something(PaintPatternPredicate predicate) {
|
||||
_predicates.add(new _SomethingPaintPredicate(predicate));
|
||||
|
||||
Reference in New Issue
Block a user