Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
f5ce6389
Unverified
Commit
f5ce6389
authored
Oct 27, 2020
by
Michael Goderbauer
Committed by
GitHub
Oct 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Directionality.maybeOf (#69117)
parent
48a9fc13
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
79 additions
and
44 deletions
+79
-44
chip.dart
packages/flutter/lib/src/material/chip.dart
+1
-1
dialog.dart
packages/flutter/lib/src/material/dialog.dart
+2
-2
drawer.dart
packages/flutter/lib/src/material/drawer.dart
+2
-2
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+2
-2
material.dart
packages/flutter/lib/src/material/material.dart
+4
-4
calendar_date_picker.dart
...lutter/lib/src/material/pickers/calendar_date_picker.dart
+4
-4
calendar_date_range_picker.dart
.../lib/src/material/pickers/calendar_date_range_picker.dart
+1
-1
animated_size.dart
packages/flutter/lib/src/widgets/animated_size.dart
+2
-2
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+40
-23
container.dart
packages/flutter/lib/src/widgets/container.dart
+1
-1
image.dart
packages/flutter/lib/src/widgets/image.dart
+1
-1
directionality_test.dart
packages/flutter/test/widgets/directionality_test.dart
+19
-1
No files found.
packages/flutter/lib/src/material/chip.dart
View file @
f5ce6389
...
...
@@ -1834,7 +1834,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
final
ThemeData
theme
=
Theme
.
of
(
context
)!;
final
ChipThemeData
chipTheme
=
ChipTheme
.
of
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
o
f
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
maybeO
f
(
context
);
final
ShapeBorder
shape
=
widget
.
shape
??
chipTheme
.
shape
;
final
double
elevation
=
widget
.
elevation
??
chipTheme
.
elevation
??
_defaultElevation
;
final
double
pressElevation
=
widget
.
pressElevation
??
chipTheme
.
pressElevation
??
_defaultPressElevation
;
...
...
packages/flutter/lib/src/material/dialog.dart
View file @
f5ce6389
...
...
@@ -469,7 +469,7 @@ class AlertDialog extends StatelessWidget {
// The paddingScaleFactor is used to adjust the padding of Dialog's
// children.
final
double
paddingScaleFactor
=
_paddingScaleFactor
(
MediaQuery
.
of
(
context
)!.
textScaleFactor
);
final
TextDirection
?
textDirection
=
Directionality
.
o
f
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
maybeO
f
(
context
);
Widget
?
titleWidget
;
Widget
?
contentWidget
;
...
...
@@ -826,7 +826,7 @@ class SimpleDialog extends StatelessWidget {
// The paddingScaleFactor is used to adjust the padding of Dialog
// children.
final
double
paddingScaleFactor
=
_paddingScaleFactor
(
MediaQuery
.
of
(
context
)!.
textScaleFactor
);
final
TextDirection
?
textDirection
=
Directionality
.
o
f
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
maybeO
f
(
context
);
Widget
?
titleWidget
;
if
(
title
!=
null
)
{
...
...
packages/flutter/lib/src/material/drawer.dart
View file @
f5ce6389
...
...
@@ -499,11 +499,11 @@ 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
)
{
switch
(
textDirection
!
)
{
switch
(
textDirection
)
{
case
TextDirection
.
ltr
:
dragAreaWidth
=
_kEdgeDragWidth
+
(
drawerIsStart
?
padding
.
left
:
padding
.
right
);
...
...
packages/flutter/lib/src/material/dropdown.dart
View file @
f5ce6389
...
...
@@ -564,7 +564,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
route
.
scrollController
=
ScrollController
(
initialScrollOffset:
menuLimits
.
scrollOffset
);
}
final
TextDirection
?
textDirection
=
Directionality
.
o
f
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
maybeO
f
(
context
);
final
Widget
menu
=
_DropdownMenu
<
T
>(
route:
route
,
padding:
padding
.
resolve
(
textDirection
),
...
...
@@ -1178,7 +1178,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
void
_handleTap
()
{
final
RenderBox
itemBox
=
context
.
findRenderObject
()!
as
RenderBox
;
final
Rect
itemRect
=
itemBox
.
localToGlobal
(
Offset
.
zero
)
&
itemBox
.
size
;
final
TextDirection
?
textDirection
=
Directionality
.
o
f
(
context
);
final
TextDirection
?
textDirection
=
Directionality
.
maybeO
f
(
context
);
final
EdgeInsetsGeometry
menuMargin
=
ButtonTheme
.
of
(
context
).
alignedDropdown
?
_kAlignedMenuMargin
:
_kUnalignedMenuMargin
;
...
...
packages/flutter/lib/src/material/material.dart
View file @
f5ce6389
...
...
@@ -453,7 +453,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
child:
child
,
clipper:
ShapeBorderClipper
(
shape:
shape
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
),
clipBehavior:
clipBehavior
,
);
...
...
@@ -787,7 +787,7 @@ class _MaterialInteriorState extends AnimatedWidgetBaseState<_MaterialInterior>
),
clipper:
ShapeBorderClipper
(
shape:
shape
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
),
clipBehavior:
widget
.
clipBehavior
,
elevation:
elevation
,
...
...
@@ -812,8 +812,8 @@ class _ShapeBorderPaint extends StatelessWidget {
Widget
build
(
BuildContext
context
)
{
return
CustomPaint
(
child:
child
,
painter:
borderOnForeground
?
null
:
_ShapeBorderPainter
(
shape
,
Directionality
.
o
f
(
context
)),
foregroundPainter:
borderOnForeground
?
_ShapeBorderPainter
(
shape
,
Directionality
.
o
f
(
context
))
:
null
,
painter:
borderOnForeground
?
null
:
_ShapeBorderPainter
(
shape
,
Directionality
.
maybeO
f
(
context
)),
foregroundPainter:
borderOnForeground
?
_ShapeBorderPainter
(
shape
,
Directionality
.
maybeO
f
(
context
))
:
null
,
);
}
}
...
...
packages/flutter/lib/src/material/pickers/calendar_date_picker.dart
View file @
f5ce6389
...
...
@@ -494,7 +494,7 @@ class _MonthPickerState extends State<_MonthPicker> {
late
DateTime
_previousMonthDate
;
PageController
?
_pageController
;
late
MaterialLocalizations
_localizations
;
TextDirection
?
_textDirection
;
late
TextDirection
_textDirection
;
Map
<
LogicalKeySet
,
Intent
>?
_shortcutMap
;
Map
<
Type
,
Action
<
Intent
>>?
_actionMap
;
FocusNode
?
_dayGridFocus
;
...
...
@@ -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
...
...
@@ -595,7 +595,7 @@ class _MonthPickerState extends State<_MonthPicker> {
if
(!
_isDisplayingLastMonth
)
{
SemanticsService
.
announce
(
_localizations
.
formatMonthYear
(
_nextMonthDate
),
_textDirection
!
,
_textDirection
,
);
_pageController
!.
nextPage
(
duration:
_monthScrollDuration
,
...
...
@@ -609,7 +609,7 @@ class _MonthPickerState extends State<_MonthPicker> {
if
(!
_isDisplayingFirstMonth
)
{
SemanticsService
.
announce
(
_localizations
.
formatMonthYear
(
_previousMonthDate
),
_textDirection
!
,
_textDirection
,
);
_pageController
!.
previousPage
(
duration:
_monthScrollDuration
,
...
...
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
View file @
f5ce6389
...
...
@@ -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
;
...
...
packages/flutter/lib/src/widgets/animated_size.dart
View file @
f5ce6389
...
...
@@ -116,7 +116,7 @@ class AnimatedSize extends SingleChildRenderObjectWidget {
reverseDuration:
reverseDuration
,
curve:
curve
,
vsync:
vsync
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
clipBehavior:
clipBehavior
,
);
}
...
...
@@ -129,7 +129,7 @@ class AnimatedSize extends SingleChildRenderObjectWidget {
..
reverseDuration
=
reverseDuration
..
curve
=
curve
..
vsync
=
vsync
..
textDirection
=
Directionality
.
o
f
(
context
)
..
textDirection
=
Directionality
.
maybeO
f
(
context
)
..
clipBehavior
=
clipBehavior
;
}
...
...
packages/flutter/lib/src/widgets/basic.dart
View file @
f5ce6389
...
...
@@ -107,11 +107,28 @@ class Directionality extends InheritedWidget {
/// ```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
;
}
/// The text direction from the closest instance of this class that encloses
/// the given context.
///
/// If there is no [Directionality] ancestor widget in the tree at the given
/// context, then this will return null.
///
/// Typical usage is as follows:
///
/// ```dart
/// TextDirection? textDirection = Directionality.maybeOf(context);
/// ```
static
TextDirection
?
maybeOf
(
BuildContext
context
)
{
final
Directionality
?
widget
=
context
.
dependOnInheritedWidgetOfExactType
<
Directionality
>();
return
widget
?.
textDirection
;
}
@override
bool
updateShouldNotify
(
Directionality
oldWidget
)
=>
textDirection
!=
oldWidget
.
textDirection
;
...
...
@@ -831,7 +848,7 @@ class ClipPath extends SingleChildRenderObjectWidget {
return
ClipPath
(
clipper:
ShapeBorderClipper
(
shape:
shape
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
),
clipBehavior:
clipBehavior
,
child:
child
,
...
...
@@ -1258,7 +1275,7 @@ class Transform extends SingleChildRenderObjectWidget {
transform:
transform
,
origin:
origin
,
alignment:
alignment
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
transformHitTests:
transformHitTests
,
);
}
...
...
@@ -1269,7 +1286,7 @@ class Transform extends SingleChildRenderObjectWidget {
..
transform
=
transform
..
origin
=
origin
..
alignment
=
alignment
..
textDirection
=
Directionality
.
o
f
(
context
)
..
textDirection
=
Directionality
.
maybeO
f
(
context
)
..
transformHitTests
=
transformHitTests
;
}
}
...
...
@@ -1495,7 +1512,7 @@ class FittedBox extends SingleChildRenderObjectWidget {
return
RenderFittedBox
(
fit:
fit
,
alignment:
alignment
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
clipBehavior:
clipBehavior
,
);
}
...
...
@@ -1505,7 +1522,7 @@ class FittedBox extends SingleChildRenderObjectWidget {
renderObject
..
fit
=
fit
..
alignment
=
alignment
..
textDirection
=
Directionality
.
o
f
(
context
)
..
textDirection
=
Directionality
.
maybeO
f
(
context
)
..
clipBehavior
=
clipBehavior
;
}
...
...
@@ -1689,7 +1706,7 @@ class Padding extends SingleChildRenderObjectWidget {
RenderPadding
createRenderObject
(
BuildContext
context
)
{
return
RenderPadding
(
padding:
padding
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
);
}
...
...
@@ -1697,7 +1714,7 @@ class Padding extends SingleChildRenderObjectWidget {
void
updateRenderObject
(
BuildContext
context
,
RenderPadding
renderObject
)
{
renderObject
..
padding
=
padding
..
textDirection
=
Directionality
.
o
f
(
context
);
..
textDirection
=
Directionality
.
maybeO
f
(
context
);
}
@override
...
...
@@ -1884,7 +1901,7 @@ class Align extends SingleChildRenderObjectWidget {
alignment:
alignment
,
widthFactor:
widthFactor
,
heightFactor:
heightFactor
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
);
}
...
...
@@ -1894,7 +1911,7 @@ class Align extends SingleChildRenderObjectWidget {
..
alignment
=
alignment
..
widthFactor
=
widthFactor
..
heightFactor
=
heightFactor
..
textDirection
=
Directionality
.
o
f
(
context
);
..
textDirection
=
Directionality
.
maybeO
f
(
context
);
}
@override
...
...
@@ -2334,7 +2351,7 @@ class UnconstrainedBox extends SingleChildRenderObjectWidget {
@override
void
updateRenderObject
(
BuildContext
context
,
covariant
RenderUnconstrainedBox
renderObject
)
{
renderObject
..
textDirection
=
textDirection
??
Directionality
.
o
f
(
context
)
..
textDirection
=
textDirection
??
Directionality
.
maybeO
f
(
context
)
..
alignment
=
alignment
..
constrainedAxis
=
constrainedAxis
..
clipBehavior
=
clipBehavior
;
...
...
@@ -2342,7 +2359,7 @@ class UnconstrainedBox extends SingleChildRenderObjectWidget {
@override
RenderUnconstrainedBox
createRenderObject
(
BuildContext
context
)
=>
RenderUnconstrainedBox
(
textDirection:
textDirection
??
Directionality
.
o
f
(
context
),
textDirection:
textDirection
??
Directionality
.
maybeO
f
(
context
),
alignment:
alignment
,
constrainedAxis:
constrainedAxis
,
clipBehavior:
clipBehavior
,
...
...
@@ -2431,7 +2448,7 @@ class FractionallySizedBox extends SingleChildRenderObjectWidget {
alignment:
alignment
,
widthFactor:
widthFactor
,
heightFactor:
heightFactor
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
);
}
...
...
@@ -2441,7 +2458,7 @@ class FractionallySizedBox extends SingleChildRenderObjectWidget {
..
alignment
=
alignment
..
widthFactor
=
widthFactor
..
heightFactor
=
heightFactor
..
textDirection
=
Directionality
.
o
f
(
context
);
..
textDirection
=
Directionality
.
maybeO
f
(
context
);
}
@override
...
...
@@ -2594,7 +2611,7 @@ class OverflowBox extends SingleChildRenderObjectWidget {
maxWidth:
maxWidth
,
minHeight:
minHeight
,
maxHeight:
maxHeight
,
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
);
}
...
...
@@ -2606,7 +2623,7 @@ class OverflowBox extends SingleChildRenderObjectWidget {
..
maxWidth
=
maxWidth
..
minHeight
=
minHeight
..
maxHeight
=
maxHeight
..
textDirection
=
Directionality
.
o
f
(
context
);
..
textDirection
=
Directionality
.
maybeO
f
(
context
);
}
@override
...
...
@@ -3400,7 +3417,7 @@ class Stack extends MultiChildRenderObjectWidget {
assert
(
_debugCheckHasDirectionality
(
context
));
return
RenderStack
(
alignment:
alignment
,
textDirection:
textDirection
??
Directionality
.
o
f
(
context
),
textDirection:
textDirection
??
Directionality
.
maybeO
f
(
context
),
fit:
fit
,
clipBehavior:
overflow
==
Overflow
.
visible
?
Clip
.
none
:
clipBehavior
,
);
...
...
@@ -3411,7 +3428,7 @@ class Stack extends MultiChildRenderObjectWidget {
assert
(
_debugCheckHasDirectionality
(
context
));
renderObject
..
alignment
=
alignment
..
textDirection
=
textDirection
??
Directionality
.
o
f
(
context
)
..
textDirection
=
textDirection
??
Directionality
.
maybeO
f
(
context
)
..
fit
=
fit
..
clipBehavior
=
overflow
==
Overflow
.
visible
?
Clip
.
none
:
clipBehavior
;
}
...
...
@@ -3461,7 +3478,7 @@ class IndexedStack extends Stack {
return
RenderIndexedStack
(
index:
index
,
alignment:
alignment
,
textDirection:
textDirection
??
Directionality
.
o
f
(
context
),
textDirection:
textDirection
??
Directionality
.
maybeO
f
(
context
),
);
}
...
...
@@ -3471,7 +3488,7 @@ class IndexedStack extends Stack {
renderObject
..
index
=
index
..
alignment
=
alignment
..
textDirection
=
textDirection
??
Directionality
.
o
f
(
context
);
..
textDirection
=
textDirection
??
Directionality
.
maybeO
f
(
context
);
}
}
...
...
@@ -4084,7 +4101,7 @@ class Flex extends MultiChildRenderObjectWidget {
/// the logic for providing a text direction only when it is necessary.
@protected
TextDirection
?
getEffectiveTextDirection
(
BuildContext
context
)
{
return
textDirection
??
(
_needTextDirection
?
Directionality
.
o
f
(
context
)
:
null
);
return
textDirection
??
(
_needTextDirection
?
Directionality
.
maybeO
f
(
context
)
:
null
);
}
@override
...
...
@@ -4954,7 +4971,7 @@ class Wrap extends MultiChildRenderObjectWidget {
runAlignment:
runAlignment
,
runSpacing:
runSpacing
,
crossAxisAlignment:
crossAxisAlignment
,
textDirection:
textDirection
??
Directionality
.
o
f
(
context
),
textDirection:
textDirection
??
Directionality
.
maybeO
f
(
context
),
verticalDirection:
verticalDirection
,
clipBehavior:
clipBehavior
,
);
...
...
@@ -4969,7 +4986,7 @@ class Wrap extends MultiChildRenderObjectWidget {
..
runAlignment
=
runAlignment
..
runSpacing
=
runSpacing
..
crossAxisAlignment
=
crossAxisAlignment
..
textDirection
=
textDirection
??
Directionality
.
o
f
(
context
)
..
textDirection
=
textDirection
??
Directionality
.
maybeO
f
(
context
)
..
verticalDirection
=
verticalDirection
..
clipBehavior
=
clipBehavior
;
}
...
...
@@ -6879,7 +6896,7 @@ class Semantics extends SingleChildRenderObjectWidget {
if
(!
containsText
)
return
null
;
return
Directionality
.
o
f
(
context
);
return
Directionality
.
maybeO
f
(
context
);
}
@override
...
...
packages/flutter/lib/src/widgets/container.dart
View file @
f5ce6389
...
...
@@ -406,7 +406,7 @@ class Container extends StatelessWidget {
assert
(
decoration
!=
null
);
current
=
ClipPath
(
clipper:
_DecorationClipper
(
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
decoration:
decoration
!,
),
clipBehavior:
clipBehavior
,
...
...
packages/flutter/lib/src/widgets/image.dart
View file @
f5ce6389
...
...
@@ -52,7 +52,7 @@ ImageConfiguration createLocalImageConfiguration(BuildContext context, { Size? s
bundle:
DefaultAssetBundle
.
of
(
context
),
devicePixelRatio:
MediaQuery
.
of
(
context
,
nullOk:
true
)?.
devicePixelRatio
??
1.0
,
locale:
Localizations
.
localeOf
(
context
,
nullOk:
true
),
textDirection:
Directionality
.
o
f
(
context
),
textDirection:
Directionality
.
maybeO
f
(
context
),
size:
size
,
platform:
defaultTargetPlatform
,
);
...
...
packages/flutter/test/widgets/directionality_test.dart
View file @
f5ce6389
...
...
@@ -55,11 +55,29 @@ void main() {
bool
good
=
false
;
await
tester
.
pumpWidget
(
Builder
(
builder:
(
BuildContext
context
)
{
expect
(
Directionality
.
o
f
(
context
),
isNull
);
expect
(
Directionality
.
maybeO
f
(
context
),
isNull
);
good
=
true
;
return
const
Placeholder
();
},
));
expect
(
good
,
isTrue
);
});
testWidgets
(
'Directionality.maybeOf'
,
(
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
.
maybeOf
(
noDirectionality
.
currentContext
!),
isNull
);
expect
(
Directionality
.
maybeOf
(
hasDirectionality
.
currentContext
!),
TextDirection
.
rtl
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment