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
95d6ef74
Unverified
Commit
95d6ef74
authored
Feb 08, 2020
by
Michael Goderbauer
Committed by
GitHub
Feb 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nested TickerMode cannot turn tickers back on (#50355)
parent
0ffecc68
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
255 additions
and
11 deletions
+255
-11
ticker_provider.dart
packages/flutter/lib/src/widgets/ticker_provider.dart
+45
-11
debug_test.dart
packages/flutter/test/material/debug_test.dart
+1
-0
navigator_test.dart
packages/flutter/test/widgets/navigator_test.dart
+76
-0
ticker_mode_test.dart
packages/flutter/test/widgets/ticker_mode_test.dart
+133
-0
No files found.
packages/flutter/lib/src/widgets/ticker_provider.dart
View file @
95d6ef74
...
...
@@ -15,26 +15,35 @@ export 'package:flutter/scheduler.dart' show TickerProvider;
/// This only works if [AnimationController] objects are created using
/// widget-aware ticker providers. For example, using a
/// [TickerProviderStateMixin] or a [SingleTickerProviderStateMixin].
class
TickerMode
extends
Inherited
Widget
{
class
TickerMode
extends
Stateless
Widget
{
/// Creates a widget that enables or disables tickers.
///
/// The [enabled] argument must not be null.
const
TickerMode
({
Key
key
,
@required
this
.
enabled
,
Widget
child
,
this
.
child
,
})
:
assert
(
enabled
!=
null
),
super
(
key:
key
,
child:
child
);
super
(
key:
key
);
/// The current ticker mode of this subtree.
/// The requested ticker mode for this subtree.
///
/// The effective ticker mode of this subtree may differ from this value
/// if there is an ancestor [TickerMode] with this field set to false.
///
/// If true, then tickers in this subtree will tick.
/// If true and all ancestor [TickerMode]s are also enabled, then tickers in
/// this subtree will tick.
///
/// If false, then tickers in this subtree will not tick
. Animations driven b
y
///
such tickers are not paused, they just don't call their callbacks. Time
/// still elapses.
/// If false, then tickers in this subtree will not tick
regardless of an
y
///
ancestor [TickerMode]s. Animations driven by such tickers are not paused,
///
they just don't call their callbacks. Time
still elapses.
final
bool
enabled
;
/// The widget below this widget in the tree.
///
/// {@template flutter.widgets.child}
final
Widget
child
;
/// Whether tickers in the given subtree should be enabled or disabled.
///
/// This is used automatically by [TickerProviderStateMixin] and
...
...
@@ -49,17 +58,42 @@ class TickerMode extends InheritedWidget {
/// bool tickingEnabled = TickerMode.of(context);
/// ```
static
bool
of
(
BuildContext
context
)
{
final
TickerMode
widget
=
context
.
dependOnInheritedWidgetOfExactType
<
TickerMode
>();
final
_EffectiveTickerMode
widget
=
context
.
dependOnInheritedWidgetOfExactType
<
_Effective
TickerMode
>();
return
widget
?.
enabled
??
true
;
}
@override
bool
updateShouldNotify
(
TickerMode
oldWidget
)
=>
enabled
!=
oldWidget
.
enabled
;
Widget
build
(
BuildContext
context
)
{
return
_EffectiveTickerMode
(
enabled:
enabled
&&
TickerMode
.
of
(
context
),
child:
child
,
);
}
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
FlagProperty
(
'requested mode'
,
value:
enabled
,
ifTrue:
'enabled'
,
ifFalse:
'disabled'
,
showName:
true
));
}
}
class
_EffectiveTickerMode
extends
InheritedWidget
{
const
_EffectiveTickerMode
({
Key
key
,
@required
this
.
enabled
,
Widget
child
,
})
:
assert
(
enabled
!=
null
),
super
(
key:
key
,
child:
child
);
final
bool
enabled
;
@override
bool
updateShouldNotify
(
_EffectiveTickerMode
oldWidget
)
=>
enabled
!=
oldWidget
.
enabled
;
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
FlagProperty
(
'mode'
,
value:
enabled
,
ifTrue:
'enabled'
,
ifFalse:
'disabled'
,
showName:
true
));
properties
.
add
(
FlagProperty
(
'
effective
mode'
,
value:
enabled
,
ifTrue:
'enabled'
,
ifFalse:
'disabled'
,
showName:
true
));
}
}
...
...
packages/flutter/test/material/debug_test.dart
View file @
95d6ef74
...
...
@@ -132,6 +132,7 @@ void main() {
' Offstage
\n
'
' _ModalScopeStatus
\n
'
' _ModalScope<dynamic>-[LabeledGlobalKey<_ModalScopeState<dynamic>>#969b7]
\n
'
' _EffectiveTickerMode
\n
'
' TickerMode
\n
'
' _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#545d0]
\n
'
' _Theatre
\n
'
...
...
packages/flutter/test/widgets/navigator_test.dart
View file @
95d6ef74
...
...
@@ -5,6 +5,7 @@
import
'dart:ui'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/material.dart'
;
...
...
@@ -1650,6 +1651,81 @@ void main() {
expect
(
find
.
text
(
'Route: root'
),
findsOneWidget
);
expect
(
find
.
text
(
'Route: 4'
,
skipOffstage:
false
),
findsNothing
);
});
testWidgets
(
'Wrapping TickerMode can turn off ticking in routes'
,
(
WidgetTester
tester
)
async
{
int
tickCount
=
0
;
Widget
widgetUnderTest
({
bool
enabled
})
{
return
TickerMode
(
enabled:
enabled
,
child:
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Navigator
(
initialRoute:
'root'
,
onGenerateRoute:
(
RouteSettings
settings
)
{
return
MaterialPageRoute
<
void
>(
settings:
settings
,
builder:
(
BuildContext
context
)
{
return
_TickingWidget
(
onTick:
()
{
tickCount
++;
},
);
},
);
},
),
),
);
}
await
tester
.
pumpWidget
(
widgetUnderTest
(
enabled:
false
));
expect
(
tickCount
,
0
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tickCount
,
0
);
await
tester
.
pumpWidget
(
widgetUnderTest
(
enabled:
true
));
expect
(
tickCount
,
0
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tickCount
,
4
);
});
}
class
_TickingWidget
extends
StatefulWidget
{
const
_TickingWidget
({
this
.
onTick
});
final
VoidCallback
onTick
;
@override
State
<
_TickingWidget
>
createState
()
=>
_TickingWidgetState
();
}
class
_TickingWidgetState
extends
State
<
_TickingWidget
>
with
SingleTickerProviderStateMixin
{
Ticker
_ticker
;
@override
void
initState
()
{
super
.
initState
();
_ticker
=
createTicker
((
Duration
_
)
{
widget
.
onTick
();
})..
start
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Container
();
}
@override
void
dispose
()
{
_ticker
.
dispose
();
super
.
dispose
();
}
}
class
NoAnimationPageRoute
extends
PageRouteBuilder
<
void
>
{
...
...
packages/flutter/test/widgets/ticker_mode_test.dart
0 → 100644
View file @
95d6ef74
// Copyright 2014 The Flutter 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/scheduler.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'Nested TickerMode cannot turn tickers back on'
,
(
WidgetTester
tester
)
async
{
int
outerTickCount
=
0
;
int
innerTickCount
=
0
;
Widget
nestedTickerModes
({
bool
innerEnabled
,
bool
outerEnabled
})
{
return
Directionality
(
textDirection:
TextDirection
.
rtl
,
child:
TickerMode
(
enabled:
outerEnabled
,
child:
Row
(
children:
<
Widget
>[
_TickingWidget
(
onTick:
()
{
outerTickCount
++;
},
),
TickerMode
(
enabled:
innerEnabled
,
child:
_TickingWidget
(
onTick:
()
{
innerTickCount
++;
},
),
),
],
),
),
);
}
await
tester
.
pumpWidget
(
nestedTickerModes
(
outerEnabled:
false
,
innerEnabled:
true
,
),
);
expect
(
outerTickCount
,
0
);
expect
(
innerTickCount
,
0
);
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
outerTickCount
,
0
);
expect
(
innerTickCount
,
0
);
await
tester
.
pumpWidget
(
nestedTickerModes
(
outerEnabled:
true
,
innerEnabled:
false
,
),
);
outerTickCount
=
0
;
innerTickCount
=
0
;
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
outerTickCount
,
4
);
expect
(
innerTickCount
,
0
);
await
tester
.
pumpWidget
(
nestedTickerModes
(
outerEnabled:
true
,
innerEnabled:
true
,
),
);
outerTickCount
=
0
;
innerTickCount
=
0
;
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
outerTickCount
,
4
);
expect
(
innerTickCount
,
4
);
await
tester
.
pumpWidget
(
nestedTickerModes
(
outerEnabled:
false
,
innerEnabled:
false
,
),
);
outerTickCount
=
0
;
innerTickCount
=
0
;
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
outerTickCount
,
0
);
expect
(
innerTickCount
,
0
);
});
}
class
_TickingWidget
extends
StatefulWidget
{
const
_TickingWidget
({
this
.
onTick
});
final
VoidCallback
onTick
;
@override
State
<
_TickingWidget
>
createState
()
=>
_TickingWidgetState
();
}
class
_TickingWidgetState
extends
State
<
_TickingWidget
>
with
SingleTickerProviderStateMixin
{
Ticker
_ticker
;
@override
void
initState
()
{
super
.
initState
();
_ticker
=
createTicker
((
Duration
_
)
{
widget
.
onTick
();
})..
start
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Container
();
}
@override
void
dispose
()
{
_ticker
.
dispose
();
super
.
dispose
();
}
}
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