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
bf47b34b
Commit
bf47b34b
authored
Aug 23, 2017
by
Ian Hickson
Committed by
GitHub
Aug 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Directionality widget (#11739)
parent
9d4dd10f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
0 deletions
+119
-0
basic.dart
packages/flutter/lib/src/widgets/basic.dart
+50
-0
directionality_test.dart
packages/flutter/test/widgets/directionality_test.dart
+69
-0
No files found.
packages/flutter/lib/src/widgets/basic.dart
View file @
bf47b34b
...
...
@@ -55,6 +55,56 @@ export 'package:flutter/rendering.dart' show
WrapAlignment
,
WrapCrossAlignment
;
// BIDIRECTIONAL TEXT SUPPORT
/// A widget that determines the ambient directionality of text and
/// text-direction-sensitive render objects.
///
/// For example, [Padding] depends on the [Directionality] to resolve
/// [EdgeInsetsDirectional] objects into absolute [EdgeInsets] objects.
class
Directionality
extends
InheritedWidget
{
/// Creates a widget that determines the directionality of text and
/// text-direction-sensitive render objects.
///
/// The [textDirection] and [child] arguments must not be null.
const
Directionality
({
Key
key
,
@required
this
.
textDirection
,
@required
Widget
child
})
:
assert
(
textDirection
!=
null
),
assert
(
child
!=
null
),
super
(
key:
key
,
child:
child
);
/// The text direction for this subtree.
final
TextDirection
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.of(context);
/// ```
static
TextDirection
of
(
BuildContext
context
)
{
final
Directionality
widget
=
context
.
inheritFromWidgetOfExactType
(
Directionality
);
return
widget
?.
textDirection
;
}
@override
bool
updateShouldNotify
(
Directionality
old
)
=>
textDirection
!=
old
.
textDirection
;
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
description
)
{
super
.
debugFillProperties
(
description
);
description
.
add
(
new
EnumProperty
<
TextDirection
>(
'textDirection'
,
textDirection
));
}
}
// PAINTING NODES
/// A widget that makes its child partially transparent.
...
...
packages/flutter/test/widgets/directionality_test.dart
0 → 100644
View file @
bf47b34b
// Copyright 2015 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/widgets.dart'
;
void
main
(
)
{
testWidgets
(
'Directionality'
,
(
WidgetTester
tester
)
async
{
final
List
<
TextDirection
>
log
=
<
TextDirection
>[];
final
Widget
inner
=
new
Builder
(
builder:
(
BuildContext
context
)
{
log
.
add
(
Directionality
.
of
(
context
));
return
new
Placeholder
();
}
);
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
inner
,
),
);
expect
(
log
,
<
TextDirection
>[
TextDirection
.
ltr
]);
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
inner
,
),
);
expect
(
log
,
<
TextDirection
>[
TextDirection
.
ltr
]);
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
rtl
,
child:
inner
,
),
);
expect
(
log
,
<
TextDirection
>[
TextDirection
.
ltr
,
TextDirection
.
rtl
]);
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
rtl
,
child:
inner
,
),
);
expect
(
log
,
<
TextDirection
>[
TextDirection
.
ltr
,
TextDirection
.
rtl
]);
await
tester
.
pumpWidget
(
new
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
inner
,
),
);
expect
(
log
,
<
TextDirection
>[
TextDirection
.
ltr
,
TextDirection
.
rtl
,
TextDirection
.
ltr
]);
});
testWidgets
(
'Directionality default'
,
(
WidgetTester
tester
)
async
{
bool
good
=
false
;
await
tester
.
pumpWidget
(
new
Builder
(
builder:
(
BuildContext
context
)
{
expect
(
Directionality
.
of
(
context
),
isNull
);
good
=
true
;
return
new
Placeholder
();
},
));
expect
(
good
,
isTrue
);
});
testWidgets
(
'Directionality can
\'
t be null'
,
(
WidgetTester
tester
)
async
{
expect
(()
{
new
Directionality
(
textDirection:
null
,
child:
new
Placeholder
());
},
throwsAssertionError
);
});
}
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