|
| 1 | +import 'package:flutter/cupertino.dart'; |
| 2 | +import 'package:flutter/foundation.dart'; |
| 3 | + |
| 4 | +import 'package:meta/meta.dart'; |
| 5 | + |
| 6 | +@internal |
| 7 | +bool debugCheckHasAncestor<T extends InheritedWidget>(String ancestor, BuildContext context, {bool generic = false}) { |
| 8 | + assert(() { |
| 9 | + if (context.dependOnInheritedWidgetOfExactType<T>() == null) { |
| 10 | + throw FlutterError.fromParts([ |
| 11 | + ErrorSummary('No $ancestor ancestor found.'), |
| 12 | + ErrorDescription('The ${context.widget.runtimeType} widget requires an $ancestor widget ancestor.'), |
| 13 | + context.describeWidget('The specific widget that could not find a $ancestor ancestor was'), |
| 14 | + context.describeOwnershipChain('The ownership chain for the affected widget is'), |
| 15 | + if (generic) |
| 16 | + ErrorHint( |
| 17 | + "This is likely because $ancestor's type parameter could not be inferred. To fix this, wrap " |
| 18 | + '${context.widget.runtimeType} in a $ancestor widget and explicitly specify the type parameter.', |
| 19 | + ) |
| 20 | + else |
| 21 | + ErrorHint('To fix this, wrap ${context.widget.runtimeType} in a $ancestor widget.'), |
| 22 | + ]); |
| 23 | + } |
| 24 | + return true; |
| 25 | + }()); |
| 26 | + |
| 27 | + return true; |
| 28 | +} |
| 29 | + |
| 30 | +@internal |
| 31 | +bool debugCheckInclusiveRange<T>(int min, int? max) { |
| 32 | + assert(() { |
| 33 | + if (min < 0 && (max != null && max < 0)) { |
| 34 | + throw FlutterError.fromParts([ |
| 35 | + ErrorSummary("$T's min < 0 and max < 0."), |
| 36 | + IntProperty('The offending min value is', min, style: DiagnosticsTreeStyle.errorProperty), |
| 37 | + IntProperty('The offending max value is', max, style: DiagnosticsTreeStyle.errorProperty), |
| 38 | + ErrorHint('To fix this, ensure that both min and max are non-negative.'), |
| 39 | + ]); |
| 40 | + } |
| 41 | + |
| 42 | + if (min < 0) { |
| 43 | + throw FlutterError.fromParts([ |
| 44 | + ErrorSummary("$T's min < 0."), |
| 45 | + IntProperty('The offending min value is', min, style: DiagnosticsTreeStyle.errorProperty), |
| 46 | + ErrorHint('To fix this, ensure that min is non-negative.'), |
| 47 | + ]); |
| 48 | + } |
| 49 | + |
| 50 | + if (max != null && max < 0) { |
| 51 | + throw FlutterError.fromParts([ |
| 52 | + ErrorSummary("$T's max < 0."), |
| 53 | + IntProperty('The offending max value is', max, style: DiagnosticsTreeStyle.errorProperty), |
| 54 | + ErrorHint('To fix this, ensure that max is non-negative.'), |
| 55 | + ]); |
| 56 | + } |
| 57 | + |
| 58 | + if (max != null && max < min) { |
| 59 | + throw FlutterError.fromParts([ |
| 60 | + ErrorSummary("$T's max < min."), |
| 61 | + IntProperty('The offending min value is', min, style: DiagnosticsTreeStyle.errorProperty), |
| 62 | + IntProperty('The offending max value is', max, style: DiagnosticsTreeStyle.errorProperty), |
| 63 | + ErrorHint('To fix this, ensure that min <= max.'), |
| 64 | + ]); |
| 65 | + } |
| 66 | + |
| 67 | + return true; |
| 68 | + }()); |
| 69 | + |
| 70 | + return true; |
| 71 | +} |
0 commit comments