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
34f39a20
Unverified
Commit
34f39a20
authored
Jun 14, 2023
by
Ian Hickson
Committed by
GitHub
Jun 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ContextAction.isEnabled needs a context (#127721)
...and lots of things that fall out from that
parent
4effd9c4
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
148 additions
and
52 deletions
+148
-52
actions.dart
packages/flutter/lib/src/widgets/actions.dart
+88
-28
scrollable.dart
packages/flutter/lib/src/widgets/scrollable.dart
+8
-1
scrollable_helpers.dart
packages/flutter/lib/src/widgets/scrollable_helpers.dart
+16
-20
shortcuts.dart
packages/flutter/lib/src/widgets/shortcuts.dart
+7
-3
scrollable_helpers_test.dart
packages/flutter/test/widgets/scrollable_helpers_test.dart
+29
-0
No files found.
packages/flutter/lib/src/widgets/actions.dart
View file @
34f39a20
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/widgets/scrollable.dart
View file @
34f39a20
...
...
@@ -320,6 +320,10 @@ class Scrollable extends StatefulWidget {
/// the nearest enclosing [ScrollableState] in that [Axis] is returned, or
/// null if there is none.
///
/// This finds the nearest _ancestor_ [Scrollable] of the `context`. This
/// means that if the `context` is that of a [Scrollable], it will _not_ find
/// _that_ [Scrollable].
///
/// See also:
///
/// * [Scrollable.of], which is similar to this method, but asserts
...
...
@@ -359,6 +363,10 @@ class Scrollable extends StatefulWidget {
/// target [Scrollable] is not the closest instance. When [axis] is provided,
/// the nearest enclosing [ScrollableState] in that [Axis] is returned.
///
/// This finds the nearest _ancestor_ [Scrollable] of the `context`. This
/// means that if the `context` is that of a [Scrollable], it will _not_ find
/// _that_ [Scrollable].
///
/// If no [Scrollable] ancestor is found, then this method will assert in
/// debug mode, and throw an exception in release mode.
///
...
...
@@ -943,7 +951,6 @@ class ScrollableState extends State<Scrollable> with TickerProviderStateMixin, R
Widget
result
=
_ScrollableScope
(
scrollable:
this
,
position:
position
,
// TODO(ianh): Having all these global keys is sad.
child:
Listener
(
onPointerSignal:
_receivedPointerSignal
,
child:
RawGestureDetector
(
...
...
packages/flutter/lib/src/widgets/scrollable_helpers.dart
View file @
34f39a20
...
...
@@ -10,7 +10,6 @@ import 'package:flutter/rendering.dart';
import
'actions.dart'
;
import
'basic.dart'
;
import
'focus_manager.dart'
;
import
'framework.dart'
;
import
'primary_scroll_controller.dart'
;
import
'scroll_configuration.dart'
;
...
...
@@ -377,10 +376,10 @@ class ScrollIntent extends Intent {
final
ScrollIncrementType
type
;
}
/// An [Action] that scrolls the
[Scrollable] that encloses the current
///
[primaryFocus] by the amount configured
in the [ScrollIntent] given to it.
/// An [Action] that scrolls the
relevant [Scrollable] by the amount configured
/// in the [ScrollIntent] given to it.
///
/// If a Scrollable cannot be found above the
current [primaryFocus
], the
/// If a Scrollable cannot be found above the
given [BuildContext
], the
/// [PrimaryScrollController] will be considered for default handling of
/// [ScrollAction]s.
///
...
...
@@ -388,21 +387,17 @@ class ScrollIntent extends Intent {
/// for a [ScrollIntent.type] set to [ScrollIncrementType.page] is 80% of the
/// size of the scroll window, and for [ScrollIncrementType.line], 50 logical
/// pixels.
class
ScrollAction
extends
Action
<
ScrollIntent
>
{
class
ScrollAction
extends
Context
Action
<
ScrollIntent
>
{
@override
bool
isEnabled
(
ScrollIntent
intent
)
{
final
FocusNode
?
focus
=
primaryFocus
;
final
bool
contextIsValid
=
focus
!=
null
&&
focus
.
context
!=
null
;
if
(
contextIsValid
)
{
// Check for primary scrollable within the current context
if
(
Scrollable
.
maybeOf
(
focus
.
context
!)
!=
null
)
{
return
true
;
}
// Check for fallback scrollable with context from PrimaryScrollController
final
ScrollController
?
primaryScrollController
=
PrimaryScrollController
.
maybeOf
(
focus
.
context
!);
return
primaryScrollController
!=
null
&&
primaryScrollController
.
hasClients
;
bool
isEnabled
(
ScrollIntent
intent
,
[
BuildContext
?
context
])
{
if
(
context
==
null
)
{
return
false
;
}
if
(
Scrollable
.
maybeOf
(
context
)
!=
null
)
{
return
true
;
}
return
false
;
final
ScrollController
?
primaryScrollController
=
PrimaryScrollController
.
maybeOf
(
context
);
return
(
primaryScrollController
!=
null
)
&&
(
primaryScrollController
.
hasClients
);
}
/// Returns the scroll increment for a single scroll request, for use when
...
...
@@ -480,10 +475,11 @@ class ScrollAction extends Action<ScrollIntent> {
}
@override
void
invoke
(
ScrollIntent
intent
)
{
ScrollableState
?
state
=
Scrollable
.
maybeOf
(
primaryFocus
!.
context
!);
void
invoke
(
ScrollIntent
intent
,
[
BuildContext
?
context
])
{
assert
(
context
!=
null
,
'Cannot scroll without a context.'
);
ScrollableState
?
state
=
Scrollable
.
maybeOf
(
context
!);
if
(
state
==
null
)
{
final
ScrollController
primaryScrollController
=
PrimaryScrollController
.
of
(
primaryFocus
!.
context
!
);
final
ScrollController
primaryScrollController
=
PrimaryScrollController
.
of
(
context
);
assert
(()
{
if
(
primaryScrollController
.
positions
.
length
!=
1
)
{
throw
FlutterError
.
fromParts
(<
DiagnosticsNode
>[
...
...
packages/flutter/lib/src/widgets/shortcuts.dart
View file @
34f39a20
...
...
@@ -843,9 +843,13 @@ class ShortcutManager with Diagnosticable, ChangeNotifier {
primaryContext
,
intent:
matchedIntent
,
);
if
(
action
!=
null
&&
action
.
isEnabled
(
matchedIntent
))
{
final
Object
?
invokeResult
=
Actions
.
of
(
primaryContext
).
invokeAction
(
action
,
matchedIntent
,
primaryContext
);
return
action
.
toKeyEventResult
(
matchedIntent
,
invokeResult
);
if
(
action
!=
null
)
{
final
(
bool
enabled
,
Object
?
invokeResult
)
=
Actions
.
of
(
primaryContext
).
invokeActionIfEnabled
(
action
,
matchedIntent
,
primaryContext
,
);
if
(
enabled
)
{
return
action
.
toKeyEventResult
(
matchedIntent
,
invokeResult
);
}
}
}
}
...
...
packages/flutter/test/widgets/scrollable_helpers_test.dart
View file @
34f39a20
...
...
@@ -549,4 +549,33 @@ void main() {
equals
(
const
Rect
.
fromLTRB
(
0.0
,
100.0
,
800.0
,
200.0
)),
);
},
variant:
KeySimulatorTransitModeVariant
.
all
());
testWidgets
(
'Can scroll using intents only'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
ListView
(
children:
const
<
Widget
>[
SizedBox
(
height:
600.0
,
child:
Text
(
'The cow as white as milk'
)),
SizedBox
(
height:
600.0
,
child:
Text
(
'The cape as red as blood'
)),
SizedBox
(
height:
600.0
,
child:
Text
(
'The hair as yellow as corn'
)),
],
),
),
);
expect
(
find
.
text
(
'The cow as white as milk'
),
findsOneWidget
);
expect
(
find
.
text
(
'The cape as red as blood'
),
findsNothing
);
expect
(
find
.
text
(
'The hair as yellow as corn'
),
findsNothing
);
Actions
.
invoke
(
tester
.
element
(
find
.
byType
(
SliverList
)),
const
ScrollIntent
(
direction:
AxisDirection
.
down
,
type:
ScrollIncrementType
.
page
));
await
tester
.
pump
();
// start scroll
await
tester
.
pump
(
const
Duration
(
milliseconds:
1000
));
// end scroll
expect
(
find
.
text
(
'The cow as white as milk'
),
findsOneWidget
);
expect
(
find
.
text
(
'The cape as red as blood'
),
findsOneWidget
);
expect
(
find
.
text
(
'The hair as yellow as corn'
),
findsNothing
);
Actions
.
invoke
(
tester
.
element
(
find
.
byType
(
SliverList
)),
const
ScrollIntent
(
direction:
AxisDirection
.
down
,
type:
ScrollIncrementType
.
page
));
await
tester
.
pump
();
// start scroll
await
tester
.
pump
(
const
Duration
(
milliseconds:
1000
));
// end scroll
expect
(
find
.
text
(
'The cow as white as milk'
),
findsNothing
);
expect
(
find
.
text
(
'The cape as red as blood'
),
findsOneWidget
);
expect
(
find
.
text
(
'The hair as yellow as corn'
),
findsOneWidget
);
});
}
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