mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make Directionality.of non-null (#69060)
This commit is contained in:
parent
156be1d894
commit
f2a25c5bd2
@ -1620,7 +1620,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
textDirection = Directionality.of(context)!;
|
||||
textDirection = Directionality.of(context);
|
||||
localizations = CupertinoLocalizations.of(context);
|
||||
|
||||
_measureLabelMetrics();
|
||||
|
||||
@ -1374,7 +1374,7 @@ class _BackChevron extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final TextStyle textStyle = DefaultTextStyle.of(context).style;
|
||||
|
||||
// Replicate the Icon logic here to get a tightly sized icon and add
|
||||
@ -1588,7 +1588,7 @@ class _NavigationBarTransition extends StatelessWidget {
|
||||
animation: animation,
|
||||
bottomNavBar: bottomNavBar,
|
||||
topNavBar: topNavBar,
|
||||
directionality: Directionality.of(context)!,
|
||||
directionality: Directionality.of(context),
|
||||
);
|
||||
|
||||
final List<Widget> children = <Widget>[
|
||||
|
||||
@ -413,14 +413,14 @@ class _CupertinoPickerSemantics extends SingleChildRenderObjectWidget {
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
return _RenderCupertinoPickerSemantics(scrollController, Directionality.of(context)!);
|
||||
return _RenderCupertinoPickerSemantics(scrollController, Directionality.of(context));
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, covariant _RenderCupertinoPickerSemantics renderObject) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
renderObject
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..controller = scrollController;
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,7 +514,7 @@ class CupertinoPageTransition extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final TextDirection? textDirection = Directionality.of(context);
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
return SlideTransition(
|
||||
position: _secondaryPositionAnimation,
|
||||
textDirection: textDirection,
|
||||
@ -578,7 +578,7 @@ class CupertinoFullscreenDialogTransition extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final TextDirection? textDirection = Directionality.of(context);
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
return SlideTransition(
|
||||
position: _secondaryPositionAnimation,
|
||||
textDirection: textDirection,
|
||||
@ -677,7 +677,7 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
|
||||
}
|
||||
|
||||
double _convertToLogical(double value) {
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
return -value;
|
||||
case TextDirection.ltr:
|
||||
|
||||
@ -283,7 +283,7 @@ class _CupertinoScrollbarState extends State<CupertinoScrollbar> with TickerProv
|
||||
_painter = _buildCupertinoScrollbarPainter(context);
|
||||
} else {
|
||||
_painter!
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..color = CupertinoDynamicColor.resolve(_kScrollbarColor, context)!
|
||||
..padding = MediaQuery.of(context).padding;
|
||||
}
|
||||
@ -309,7 +309,7 @@ class _CupertinoScrollbarState extends State<CupertinoScrollbar> with TickerProv
|
||||
ScrollbarPainter _buildCupertinoScrollbarPainter(BuildContext context) {
|
||||
return ScrollbarPainter(
|
||||
color: CupertinoDynamicColor.resolve(_kScrollbarColor, context)!,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
thickness: _thickness,
|
||||
fadeoutOpacityAnimation: _fadeoutOpacityAnimation,
|
||||
mainAxisMargin: _kScrollbarMainAxisMargin,
|
||||
|
||||
@ -448,7 +448,7 @@ class _SegmentedControlRenderWidget<T> extends MultiChildRenderObjectWidget {
|
||||
@override
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
return _RenderSegmentedControl<T>(
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
selectedIndex: selectedIndex,
|
||||
pressedIndex: pressedIndex,
|
||||
backgroundColors: backgroundColors,
|
||||
@ -459,7 +459,7 @@ class _SegmentedControlRenderWidget<T> extends MultiChildRenderObjectWidget {
|
||||
@override
|
||||
void updateRenderObject(BuildContext context, _RenderSegmentedControl<T> renderObject) {
|
||||
renderObject
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..selectedIndex = selectedIndex
|
||||
..pressedIndex = pressedIndex
|
||||
..backgroundColors = backgroundColors
|
||||
|
||||
@ -288,7 +288,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
onChangeStart: onChangeStart,
|
||||
onChangeEnd: onChangeEnd,
|
||||
vsync: vsync,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
);
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
..onChanged = onChanged
|
||||
..onChangeStart = onChangeStart
|
||||
..onChangeEnd = onChangeEnd
|
||||
..textDirection = Directionality.of(context)!;
|
||||
..textDirection = Directionality.of(context);
|
||||
// Ticker provider cannot change since there's a 1:1 relationship between
|
||||
// the _SliderRenderObjectWidget object and the _SliderState object.
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ class _SegmentedControlState<T> extends State<CupertinoSlidingSegmentedControl<T
|
||||
Widget build(BuildContext context) {
|
||||
debugCheckHasDirectionality(context);
|
||||
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.ltr:
|
||||
keys = widget.children.keys.toList(growable: false);
|
||||
break;
|
||||
|
||||
@ -254,7 +254,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
..curve = Curves.linear
|
||||
..reverseCurve = Curves.linear;
|
||||
final double delta = details.primaryDelta! / _kTrackInnerLength;
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
_positionController.value -= delta;
|
||||
break;
|
||||
@ -302,7 +302,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
|
||||
)!,
|
||||
trackColor: CupertinoDynamicColor.resolve(widget.trackColor ?? CupertinoColors.secondarySystemFill, context)!,
|
||||
onChanged: widget.onChanged,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
state: this,
|
||||
),
|
||||
);
|
||||
|
||||
@ -109,7 +109,7 @@ class AnimatedIcon extends StatelessWidget {
|
||||
final IconThemeData iconTheme = IconTheme.of(context);
|
||||
assert(iconTheme.isConcrete);
|
||||
final double iconSize = size ?? iconTheme.size!;
|
||||
final TextDirection textDirection = this.textDirection ?? Directionality.of(context)!;
|
||||
final TextDirection textDirection = this.textDirection ?? Directionality.of(context);
|
||||
final double iconOpacity = iconTheme.opacity!;
|
||||
Color iconColor = color ?? iconTheme.color!;
|
||||
if (iconOpacity != 1.0)
|
||||
|
||||
@ -940,7 +940,7 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> with TickerPr
|
||||
child: CustomPaint(
|
||||
painter: _RadialPainter(
|
||||
circles: _circles.toList(),
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
),
|
||||
child: Material( // Splashes.
|
||||
type: MaterialType.transparency,
|
||||
|
||||
@ -2129,7 +2129,7 @@ class _ChipRenderWidget extends RenderObjectWidget {
|
||||
RenderObject createRenderObject(BuildContext context) {
|
||||
return _RenderChip(
|
||||
theme: theme,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
value: value,
|
||||
isEnabled: isEnabled,
|
||||
checkmarkAnimation: checkmarkAnimation,
|
||||
|
||||
@ -407,7 +407,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
||||
delta = -delta;
|
||||
break;
|
||||
}
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
_controller.value -= delta;
|
||||
break;
|
||||
@ -434,7 +434,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
||||
visualVelocity = -visualVelocity;
|
||||
break;
|
||||
}
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
_controller.fling(velocity: -visualVelocity);
|
||||
if (widget.drawerCallback != null)
|
||||
@ -499,7 +499,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
|
||||
Widget _buildDrawer(BuildContext context) {
|
||||
final bool drawerIsStart = widget.alignment == DrawerAlignment.start;
|
||||
final EdgeInsets padding = MediaQuery.of(context).padding;
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
|
||||
double? dragAreaWidth = widget.edgeDragWidth;
|
||||
if (widget.edgeDragWidth == null) {
|
||||
|
||||
@ -252,7 +252,7 @@ class _FlexibleSpaceBarState extends State<FlexibleSpaceBar> {
|
||||
Alignment _getTitleAlignment(bool effectiveCenterTitle) {
|
||||
if (effectiveCenterTitle)
|
||||
return Alignment.bottomCenter;
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
assert(textDirection != null);
|
||||
switch (textDirection) {
|
||||
case TextDirection.rtl:
|
||||
|
||||
@ -842,7 +842,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
||||
customBorder: widget.customBorder,
|
||||
rectCallback: widget.getRectCallback!(referenceBox),
|
||||
onRemoved: handleInkRemoval,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
fadeDuration: getFadeDurationForType(type),
|
||||
);
|
||||
updateKeepAlive();
|
||||
@ -900,7 +900,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
||||
borderRadius: borderRadius,
|
||||
customBorder: customBorder,
|
||||
onRemoved: onRemoved,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
);
|
||||
|
||||
return splash;
|
||||
|
||||
@ -237,7 +237,7 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS
|
||||
border: _border,
|
||||
gapAnimation: widget.gapAnimation,
|
||||
gap: widget.gap,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
fillColor: widget.fillColor,
|
||||
hoverColorTween: _hoverColorTween,
|
||||
hoverAnimation: _hoverAnimation,
|
||||
@ -2311,7 +2311,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
|
||||
|
||||
// The _Decoration widget and _RenderDecoration assume that contentPadding
|
||||
// has been resolved to EdgeInsets.
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final EdgeInsets? decorationContentPadding = decoration!.contentPadding?.resolve(textDirection);
|
||||
|
||||
final EdgeInsets contentPadding;
|
||||
|
||||
@ -1067,7 +1067,7 @@ class ListTile extends StatelessWidget {
|
||||
}
|
||||
|
||||
const EdgeInsets _defaultContentPadding = EdgeInsets.symmetric(horizontal: 16.0);
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final EdgeInsets resolvedContentPadding = contentPadding?.resolve(textDirection)
|
||||
?? tileTheme.contentPadding?.resolve(textDirection)
|
||||
?? _defaultContentPadding;
|
||||
|
||||
@ -180,7 +180,7 @@ class _CalendarDatePickerState extends State<CalendarDatePicker> {
|
||||
assert(debugCheckHasMaterialLocalizations(context));
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
_localizations = MaterialLocalizations.of(context);
|
||||
_textDirection = Directionality.of(context)!;
|
||||
_textDirection = Directionality.of(context);
|
||||
if (!_announcedInitialDate) {
|
||||
_announcedInitialDate = true;
|
||||
SemanticsService.announce(
|
||||
@ -525,7 +525,7 @@ class _MonthPickerState extends State<_MonthPicker> {
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_localizations = MaterialLocalizations.of(context);
|
||||
_textDirection = Directionality.of(context)!;
|
||||
_textDirection = Directionality.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -709,7 +709,7 @@ class _MonthPickerState extends State<_MonthPicker> {
|
||||
}
|
||||
|
||||
DateTime? _nextDateInDirection(DateTime date, TraversalDirection direction) {
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
DateTime nextDate = utils.addDaysToDate(date, _dayDirectionOffset(direction, textDirection));
|
||||
while (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) {
|
||||
if (_isSelectable(nextDate)) {
|
||||
|
||||
@ -340,7 +340,7 @@ class _CalendarKeyboardNavigatorState extends State<_CalendarKeyboardNavigator>
|
||||
}
|
||||
|
||||
DateTime? _nextDateInDirection(DateTime date, TraversalDirection direction) {
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final DateTime nextDate = utils.addDaysToDate(date, _dayDirectionOffset(direction, textDirection));
|
||||
if (!nextDate.isBefore(widget.firstDate) && !nextDate.isAfter(widget.lastDate)) {
|
||||
return nextDate;
|
||||
@ -707,7 +707,7 @@ class _MonthItemState extends State<_MonthItem> {
|
||||
final ColorScheme colorScheme = theme.colorScheme;
|
||||
final TextTheme textTheme = theme.textTheme;
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final Color highlightColor = _highlightColor(context);
|
||||
final int day = dayToBuild.day;
|
||||
|
||||
|
||||
@ -749,7 +749,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
|
||||
position,
|
||||
itemSizes,
|
||||
selectedItemIndex,
|
||||
Directionality.of(context)!,
|
||||
Directionality.of(context),
|
||||
),
|
||||
child: capturedThemes.wrap(menu),
|
||||
);
|
||||
|
||||
@ -332,7 +332,7 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
|
||||
if (widget.value != null)
|
||||
return _buildIndicator(context, _controller.value, textDirection);
|
||||
|
||||
@ -720,7 +720,7 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
onChangeStart: onChangeStart,
|
||||
onChangeEnd: onChangeEnd,
|
||||
state: state,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
semanticFormatterCallback: semanticFormatterCallback,
|
||||
platform: Theme.of(context)!.platform,
|
||||
);
|
||||
@ -741,7 +741,7 @@ class _RangeSliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
..onChanged = onChanged
|
||||
..onChangeStart = onChangeStart
|
||||
..onChangeEnd = onChangeEnd
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..semanticFormatterCallback = semanticFormatterCallback
|
||||
..platform = Theme.of(context)!.platform;
|
||||
}
|
||||
|
||||
@ -2908,7 +2908,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
final ThemeData themeData = Theme.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
|
||||
// TODO(Piinks): Remove old SnackBar API after migrating ScaffoldMessenger
|
||||
_accessibleNavigation = mediaQuery.accessibleNavigation;
|
||||
|
||||
@ -122,7 +122,7 @@ class _ScrollbarState extends State<Scrollbar> with SingleTickerProviderStateMix
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
_themeColor = theme.highlightColor.withOpacity(1.0);
|
||||
_textDirection = Directionality.of(context)!;
|
||||
_textDirection = Directionality.of(context);
|
||||
_materialPainter = _buildMaterialScrollbarPainter();
|
||||
_useCupertinoScrollbar = false;
|
||||
_triggerScrollbar();
|
||||
|
||||
@ -550,7 +550,7 @@ class _SliderState extends State<Slider> with TickerProviderStateMixin {
|
||||
|
||||
void _actionHandler(_AdjustSliderIntent intent) {
|
||||
final _RenderSlider renderSlider = _renderObjectKey.currentContext!.findRenderObject()! as _RenderSlider;
|
||||
final TextDirection textDirection = Directionality.of(_renderObjectKey.currentContext!)!;
|
||||
final TextDirection textDirection = Directionality.of(_renderObjectKey.currentContext!);
|
||||
switch (intent.type) {
|
||||
case _SliderAdjustmentType.right:
|
||||
switch (textDirection) {
|
||||
@ -825,7 +825,7 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
onChangeStart: onChangeStart,
|
||||
onChangeEnd: onChangeEnd,
|
||||
state: state,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
semanticFormatterCallback: semanticFormatterCallback,
|
||||
platform: Theme.of(context)!.platform,
|
||||
hasFocus: hasFocus,
|
||||
@ -847,7 +847,7 @@ class _SliderRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
..onChanged = onChanged
|
||||
..onChangeStart = onChangeStart
|
||||
..onChangeEnd = onChangeEnd
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..semanticFormatterCallback = semanticFormatterCallback
|
||||
..platform = Theme.of(context)!.platform
|
||||
..hasFocus = hasFocus
|
||||
|
||||
@ -476,7 +476,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
inactiveTrackColor: inactiveTrackColor,
|
||||
configuration: configuration,
|
||||
onChanged: onChanged != null ? _handleValueChanged : null,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
additionalConstraints: additionalConstraints,
|
||||
hasFocus: hasFocus,
|
||||
hovering: hovering,
|
||||
@ -501,7 +501,7 @@ class _SwitchRenderObjectWidget extends LeafRenderObjectWidget {
|
||||
..inactiveTrackColor = inactiveTrackColor
|
||||
..configuration = configuration
|
||||
..onChanged = onChanged != null ? _handleValueChanged : null
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..additionalConstraints = additionalConstraints
|
||||
..dragStartBehavior = dragStartBehavior
|
||||
..hasFocus = hasFocus
|
||||
|
||||
@ -918,7 +918,7 @@ class _TabBarState extends State<TabBar> {
|
||||
if (!widget.isScrollable)
|
||||
return 0.0;
|
||||
double tabCenter = _indicatorPainter!.centerOf(index);
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
tabCenter = _tabStripWidth - tabCenter;
|
||||
break;
|
||||
|
||||
@ -1266,7 +1266,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin {
|
||||
accentColor: accentColor,
|
||||
dotColor: theme.colorScheme.surface,
|
||||
theta: _theta.value,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -2210,5 +2210,5 @@ Future<TimeOfDay?> showTimePicker({
|
||||
}
|
||||
|
||||
void _announceToAccessibility(BuildContext context, String message) {
|
||||
SemanticsService.announce(message, Directionality.of(context)!);
|
||||
SemanticsService.announce(message, Directionality.of(context));
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ class ToggleButtons extends StatelessWidget {
|
||||
);
|
||||
final ThemeData theme = Theme.of(context)!;
|
||||
final ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context);
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
@ -901,7 +901,7 @@ class _SelectToggleButton extends SingleChildRenderObjectWidget {
|
||||
borderRadius,
|
||||
isFirstButton,
|
||||
isLastButton,
|
||||
Directionality.of(context)!,
|
||||
Directionality.of(context),
|
||||
);
|
||||
|
||||
@override
|
||||
@ -913,7 +913,7 @@ class _SelectToggleButton extends SingleChildRenderObjectWidget {
|
||||
..borderRadius = borderRadius
|
||||
..isFirstButton = isFirstButton
|
||||
..isLastButton = isLastButton
|
||||
..textDirection = Directionality.of(context)!;
|
||||
..textDirection = Directionality.of(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -332,7 +332,7 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
|
||||
// updated values from happening to leak into the overlay when the overlay
|
||||
// rebuilds.
|
||||
final Widget overlay = Directionality(
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
child: _TooltipOverlay(
|
||||
message: widget.message,
|
||||
height: height,
|
||||
|
||||
@ -138,7 +138,7 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
|
||||
|
||||
Widget accountDetails = CustomMultiChildLayout(
|
||||
delegate: _AccountDetailsLayout(
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
),
|
||||
children: <Widget>[
|
||||
if (widget.accountName != null)
|
||||
|
||||
@ -304,9 +304,9 @@ class Banner extends StatelessWidget {
|
||||
return CustomPaint(
|
||||
foregroundPainter: BannerPainter(
|
||||
message: message,
|
||||
textDirection: textDirection ?? Directionality.of(context)!,
|
||||
textDirection: textDirection ?? Directionality.of(context),
|
||||
location: location,
|
||||
layoutDirection: layoutDirection ?? Directionality.of(context)!,
|
||||
layoutDirection: layoutDirection ?? Directionality.of(context),
|
||||
color: color,
|
||||
textStyle: textStyle,
|
||||
),
|
||||
|
||||
@ -100,17 +100,23 @@ class Directionality extends InheritedWidget {
|
||||
/// the given context.
|
||||
///
|
||||
/// If there is no [Directionality] ancestor widget in the tree at the given
|
||||
/// context, then this will return null.
|
||||
/// context, then this will throw a descriptive [FlutterError] in debug mode
|
||||
/// and an exception in release mode.
|
||||
///
|
||||
/// Typical usage is as follows:
|
||||
///
|
||||
/// ```dart
|
||||
/// TextDirection textDirection = Directionality.of(context);
|
||||
/// ```
|
||||
// TODO(goderbauer): Make this non-null when customers have upgraded to Directionality.maybeOf.
|
||||
static TextDirection? of(BuildContext context) {
|
||||
final Directionality? widget = context.dependOnInheritedWidgetOfExactType<Directionality>();
|
||||
return widget?.textDirection;
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [maybeOf], which will return null if no [Directionality] ancestor
|
||||
/// widget is in the tree.
|
||||
static TextDirection of(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final Directionality widget = context.dependOnInheritedWidgetOfExactType<Directionality>()!;
|
||||
return widget.textDirection;
|
||||
}
|
||||
|
||||
/// The text direction from the closest instance of this class that encloses
|
||||
@ -124,6 +130,11 @@ class Directionality extends InheritedWidget {
|
||||
/// ```dart
|
||||
/// TextDirection? textDirection = Directionality.maybeOf(context);
|
||||
/// ```
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [of], which will throw if no [Directionality] ancestor widget is in the
|
||||
/// tree.
|
||||
static TextDirection? maybeOf(BuildContext context) {
|
||||
final Directionality? widget = context.dependOnInheritedWidgetOfExactType<Directionality>();
|
||||
return widget?.textDirection;
|
||||
@ -3135,7 +3146,7 @@ AxisDirection getAxisDirectionFromAxisReverseAndDirectionality(
|
||||
switch (axis) {
|
||||
case Axis.horizontal:
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
|
||||
return reverse ? flipAxisDirection(axisDirection) : axisDirection;
|
||||
case Axis.vertical:
|
||||
@ -3866,7 +3877,7 @@ class PositionedDirectional extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Positioned.directional(
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
start: start,
|
||||
top: top,
|
||||
end: end,
|
||||
@ -5376,7 +5387,7 @@ class RichText extends MultiChildRenderObjectWidget {
|
||||
assert(textDirection != null || debugCheckHasDirectionality(context));
|
||||
return RenderParagraph(text,
|
||||
textAlign: textAlign,
|
||||
textDirection: textDirection ?? Directionality.of(context)!,
|
||||
textDirection: textDirection ?? Directionality.of(context),
|
||||
softWrap: softWrap,
|
||||
overflow: overflow,
|
||||
textScaleFactor: textScaleFactor,
|
||||
@ -5394,7 +5405,7 @@ class RichText extends MultiChildRenderObjectWidget {
|
||||
renderObject
|
||||
..text = text
|
||||
..textAlign = textAlign
|
||||
..textDirection = textDirection ?? Directionality.of(context)!
|
||||
..textDirection = textDirection ?? Directionality.of(context)
|
||||
..softWrap = softWrap
|
||||
..overflow = overflow
|
||||
..textScaleFactor = textScaleFactor
|
||||
|
||||
@ -274,7 +274,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|
||||
if (extent == 0.0)
|
||||
return null;
|
||||
if (_directionIsXAxis) {
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
return extent < 0 ? DismissDirection.startToEnd : DismissDirection.endToStart;
|
||||
case TextDirection.ltr:
|
||||
@ -332,7 +332,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|
||||
break;
|
||||
|
||||
case DismissDirection.endToStart:
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
if (_dragExtent + delta > 0)
|
||||
_dragExtent += delta;
|
||||
@ -345,7 +345,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|
||||
break;
|
||||
|
||||
case DismissDirection.startToEnd:
|
||||
switch (Directionality.of(context)!) {
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.rtl:
|
||||
if (_dragExtent + delta < 0)
|
||||
_dragExtent += delta;
|
||||
|
||||
@ -2429,9 +2429,9 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
}
|
||||
|
||||
TextDirection get _textDirection {
|
||||
final TextDirection? result = widget.textDirection ?? Directionality.of(context);
|
||||
final TextDirection result = widget.textDirection ?? Directionality.of(context);
|
||||
assert(result != null, '$runtimeType created without a textDirection and with no ambient Directionality.');
|
||||
return result!;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// The renderer for this widget's descendant.
|
||||
|
||||
@ -152,7 +152,7 @@ class Icon extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(this.textDirection != null || debugCheckHasDirectionality(context));
|
||||
final TextDirection textDirection = this.textDirection ?? Directionality.of(context)!;
|
||||
final TextDirection textDirection = this.textDirection ?? Directionality.of(context);
|
||||
|
||||
final IconThemeData iconTheme = IconTheme.of(context);
|
||||
|
||||
|
||||
@ -1307,7 +1307,7 @@ class _AnimatedPositionedDirectionalState extends AnimatedWidgetBaseState<Animat
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
return Positioned.directional(
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
child: widget.child,
|
||||
start: _start?.evaluate(animation!),
|
||||
top: _top?.evaluate(animation!),
|
||||
|
||||
@ -61,7 +61,7 @@ class NavigationToolbar extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
return CustomMultiChildLayout(
|
||||
delegate: _ToolbarLayout(
|
||||
centerMiddle: centerMiddle,
|
||||
|
||||
@ -225,7 +225,7 @@ class OverflowBar extends MultiChildRenderObjectWidget {
|
||||
overflowSpacing: overflowSpacing,
|
||||
overflowAlignment: overflowAlignment,
|
||||
overflowDirection: overflowDirection,
|
||||
textDirection: textDirection ?? Directionality.of(context)!,
|
||||
textDirection: textDirection ?? Directionality.of(context),
|
||||
clipBehavior: clipBehavior,
|
||||
);
|
||||
}
|
||||
@ -237,7 +237,7 @@ class OverflowBar extends MultiChildRenderObjectWidget {
|
||||
..overflowSpacing = overflowSpacing
|
||||
..overflowAlignment = overflowAlignment
|
||||
..overflowDirection = overflowDirection
|
||||
..textDirection = textDirection ?? Directionality.of(context)!
|
||||
..textDirection = textDirection ?? Directionality.of(context)
|
||||
..clipBehavior = clipBehavior;
|
||||
}
|
||||
|
||||
|
||||
@ -547,7 +547,7 @@ class _Theatre extends MultiChildRenderObjectWidget {
|
||||
_RenderTheatre createRenderObject(BuildContext context) {
|
||||
return _RenderTheatre(
|
||||
skipCount: skipCount,
|
||||
textDirection: Directionality.of(context)!,
|
||||
textDirection: Directionality.of(context),
|
||||
clipBehavior: clipBehavior,
|
||||
);
|
||||
}
|
||||
@ -556,7 +556,7 @@ class _Theatre extends MultiChildRenderObjectWidget {
|
||||
void updateRenderObject(BuildContext context, _RenderTheatre renderObject) {
|
||||
renderObject
|
||||
..skipCount = skipCount
|
||||
..textDirection = Directionality.of(context)!
|
||||
..textDirection = Directionality.of(context)
|
||||
..clipBehavior = clipBehavior;
|
||||
}
|
||||
|
||||
|
||||
@ -846,7 +846,7 @@ class _PageViewState extends State<PageView> {
|
||||
switch (widget.scrollDirection) {
|
||||
case Axis.horizontal:
|
||||
assert(debugCheckHasDirectionality(context));
|
||||
final TextDirection textDirection = Directionality.of(context)!;
|
||||
final TextDirection textDirection = Directionality.of(context);
|
||||
final AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
|
||||
return widget.reverse ? flipAxisDirection(axisDirection) : axisDirection;
|
||||
case Axis.vertical:
|
||||
|
||||
@ -491,7 +491,7 @@ class _AndroidViewState extends State<AndroidView> {
|
||||
|
||||
TextDirection _findLayoutDirection() {
|
||||
assert(widget.layoutDirection != null || debugCheckHasDirectionality(context));
|
||||
return widget.layoutDirection ?? Directionality.of(context)!;
|
||||
return widget.layoutDirection ?? Directionality.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -616,7 +616,7 @@ class _UiKitViewState extends State<UiKitView> {
|
||||
|
||||
TextDirection _findLayoutDirection() {
|
||||
assert(widget.layoutDirection != null || debugCheckHasDirectionality(context));
|
||||
return widget.layoutDirection ?? Directionality.of(context)!;
|
||||
return widget.layoutDirection ?? Directionality.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -249,7 +249,7 @@ class Table extends RenderObjectWidget {
|
||||
rows: children.length,
|
||||
columnWidths: columnWidths,
|
||||
defaultColumnWidth: defaultColumnWidth,
|
||||
textDirection: textDirection ?? Directionality.of(context)!,
|
||||
textDirection: textDirection ?? Directionality.of(context),
|
||||
border: border,
|
||||
rowDecorations: _rowDecorations,
|
||||
configuration: createLocalImageConfiguration(context),
|
||||
@ -266,7 +266,7 @@ class Table extends RenderObjectWidget {
|
||||
renderObject
|
||||
..columnWidths = columnWidths
|
||||
..defaultColumnWidth = defaultColumnWidth
|
||||
..textDirection = textDirection ?? Directionality.of(context)!
|
||||
..textDirection = textDirection ?? Directionality.of(context)
|
||||
..border = border
|
||||
..rowDecorations = _rowDecorations
|
||||
..configuration = createLocalImageConfiguration(context)
|
||||
|
||||
@ -147,7 +147,7 @@ class Viewport extends MultiChildRenderObjectWidget {
|
||||
why: 'to determine the cross-axis direction when the viewport has an \'up\' axisDirection',
|
||||
alternative: 'Alternatively, consider specifying the \'crossAxisDirection\' argument on the Viewport.',
|
||||
));
|
||||
return textDirectionToAxisDirection(Directionality.of(context)!);
|
||||
return textDirectionToAxisDirection(Directionality.of(context));
|
||||
case AxisDirection.right:
|
||||
return AxisDirection.down;
|
||||
case AxisDirection.down:
|
||||
@ -156,7 +156,7 @@ class Viewport extends MultiChildRenderObjectWidget {
|
||||
why: 'to determine the cross-axis direction when the viewport has a \'down\' axisDirection',
|
||||
alternative: 'Alternatively, consider specifying the \'crossAxisDirection\' argument on the Viewport.',
|
||||
));
|
||||
return textDirectionToAxisDirection(Directionality.of(context)!);
|
||||
return textDirectionToAxisDirection(Directionality.of(context));
|
||||
case AxisDirection.left:
|
||||
return AxisDirection.down;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ void main() {
|
||||
final List<TextDirection> log = <TextDirection>[];
|
||||
final Widget inner = Builder(
|
||||
builder: (BuildContext context) {
|
||||
log.add(Directionality.of(context)!);
|
||||
log.add(Directionality.of(context));
|
||||
return const Placeholder();
|
||||
}
|
||||
);
|
||||
@ -80,4 +80,26 @@ void main() {
|
||||
expect(Directionality.maybeOf(noDirectionality.currentContext!), isNull);
|
||||
expect(Directionality.maybeOf(hasDirectionality.currentContext!), TextDirection.rtl);
|
||||
});
|
||||
|
||||
testWidgets('Directionality.of', (WidgetTester tester) async {
|
||||
final GlobalKey hasDirectionality = GlobalKey();
|
||||
final GlobalKey noDirectionality = GlobalKey();
|
||||
await tester.pumpWidget(
|
||||
Container(
|
||||
key: noDirectionality,
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: Container(
|
||||
key: hasDirectionality,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(() => Directionality.of(noDirectionality.currentContext!), throwsA(isAssertionError.having(
|
||||
(AssertionError e) => e.message,
|
||||
'message',
|
||||
contains('No Directionality widget found.'),
|
||||
)));
|
||||
expect(Directionality.of(hasDirectionality.currentContext!), TextDirection.rtl);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user