|
16 | 16 | library; |
17 | 17 |
|
18 | 18 | import 'dart:io'; |
19 | | -import 'dart:ui' show Image, Picture, Size; |
| 19 | +import 'dart:ui' show Image, Picture, Size, TextDirection; |
20 | 20 |
|
21 | 21 | import 'package:flutter/foundation.dart'; |
22 | 22 |
|
@@ -232,3 +232,40 @@ bool _defaultPictureCapture(Picture picture) => true; |
232 | 232 | /// Tests may use this to capture the picture and run assertions on it. |
233 | 233 | ShaderWarmUpImageCallback debugCaptureShaderWarmUpImage = _defaultImageCapture; |
234 | 234 | bool _defaultImageCapture(Image image) => true; |
| 235 | + |
| 236 | +/// Asserts that a given [TextDirection] is not null. |
| 237 | +/// |
| 238 | +/// Used by painting library classes that require a [TextDirection] to resolve |
| 239 | +/// their properties, such as [BorderRadiusDirectional]. |
| 240 | +/// |
| 241 | +/// Does nothing if asserts are disabled. Always returns true. |
| 242 | +/// |
| 243 | +/// See also: |
| 244 | +/// |
| 245 | +/// * [debugCheckHasDirectionality], which is a similar widgets-library level function. |
| 246 | +bool debugCheckCanResolveTextDirection(TextDirection? direction, String target) { |
| 247 | + assert(() { |
| 248 | + if (direction == null) { |
| 249 | + throw FlutterError.fromParts(<DiagnosticsNode>[ |
| 250 | + ErrorSummary('No TextDirection found.'), |
| 251 | + ErrorDescription( |
| 252 | + 'To resolve $target properties, it must be provided with a TextDirection.', |
| 253 | + ), |
| 254 | + ErrorHint( |
| 255 | + 'This error usually occurs when $target is used in a widget without ' |
| 256 | + 'a Directionality ancestor.', |
| 257 | + ), |
| 258 | + ErrorHint( |
| 259 | + 'Typically, the Directionality widget is introduced by the MaterialApp ' |
| 260 | + 'or WidgetsApp widget at the top of your application widget tree. It ' |
| 261 | + 'determines the ambient reading direction and is used, for example, to ' |
| 262 | + 'determine how to lay out text, how to interpret "start" and "end" ' |
| 263 | + 'values, and to resolve EdgeInsetsDirectional, ' |
| 264 | + 'AlignmentDirectional, and other *Directional objects.', |
| 265 | + ), |
| 266 | + ]); |
| 267 | + } |
| 268 | + return true; |
| 269 | + }()); |
| 270 | + return true; |
| 271 | +} |
0 commit comments