Visitar URL original
[animations] Introduce layoutBuilder parameter to PageTransitionSwitcher by federunco · Pull Request #170 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Exposed ChildEntry
  • Loading branch information
federunco committed Aug 17, 2020
commit 17813e13af227eb7b52e0981cad2adc6b82d686a
29 changes: 14 additions & 15 deletions packages/animations/lib/src/page_transition_switcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import 'package:flutter/widgets.dart';

// Internal representation of a child that, now or in the past, was set on the
// PageTransitionSwitcher.child field, but is now in the process of
// transitioning. The internal representation includes fields that we don't want

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the comment about how we don't want to expose some of these fields?

// to expose to the public API (like the controllers).
class _ChildEntry {
_ChildEntry({
// transitioning.
class ChildEntry {
ChildEntry({
@required this.primaryController,
@required this.secondaryController,
@required this.transition,
Expand Down Expand Up @@ -51,7 +50,7 @@ class _ChildEntry {
/// handle an empty list of `_activeEntries`.
///
Comment thread
goderbauer marked this conversation as resolved.
Resolved
typedef PageTransitionSwitcherLayoutBuilder = Widget Function(
List<_ChildEntry> _activeEntries,
List<ChildEntry> _activeEntries,
);

/// Signature for builders used to generate custom transitions for
Expand Down Expand Up @@ -239,10 +238,10 @@ class PageTransitionSwitcher extends StatefulWidget {
///
/// ```dart
/// layoutBuilder: (
/// List<_ChildEntry> activeEntries,
/// List<ChildEntry> activeEntries,
/// ) => Column(
/// children: activeEntries
/// .map<Widget>((_ChildEntry entry) => entry.transition)
/// .map<Widget>((ChildEntry entry) => entry.transition)
/// .toList(),
/// ),
/// ```
Expand All @@ -256,10 +255,10 @@ class PageTransitionSwitcher extends StatefulWidget {
/// each other.
///
/// This is an [PageTransitionSwitcherTransitionBuilder] function.
static Widget defaultLayoutBuilder(List<_ChildEntry> activeEntries) {
static Widget defaultLayoutBuilder(List<ChildEntry> activeEntries) {
return Stack(
children: activeEntries
.map<Widget>((_ChildEntry entry) => entry.transition)
.map<Widget>((ChildEntry entry) => entry.transition)
.toList(),
alignment: Alignment.center,
);
Expand All @@ -271,8 +270,8 @@ class PageTransitionSwitcher extends StatefulWidget {

class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
with TickerProviderStateMixin {
final List<_ChildEntry> _activeEntries = <_ChildEntry>[];
_ChildEntry _currentEntry;
final List<ChildEntry> _activeEntries = <ChildEntry>[];
ChildEntry _currentEntry;
int _childNumber = 0;

@override
Expand Down Expand Up @@ -360,7 +359,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
}
}

_ChildEntry _newEntry({
ChildEntry _newEntry({
@required Widget child,
@required PageTransitionSwitcherTransitionBuilder builder,
@required AnimationController primaryController,
Expand All @@ -375,7 +374,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
transition != null,
'PageTransitionSwitcher.builder must not return null.',
);
final _ChildEntry entry = _ChildEntry(
final ChildEntry entry = ChildEntry(
widgetChild: child,
transition: KeyedSubtree.wrap(
transition,
Expand Down Expand Up @@ -407,7 +406,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
return entry;
}

void _updateTransitionForEntry(_ChildEntry entry) {
void _updateTransitionForEntry(ChildEntry entry) {
final Widget transition = widget.transitionBuilder(
entry.widgetChild,
entry.primaryController,
Expand All @@ -425,7 +424,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>

@override
void dispose() {
for (_ChildEntry entry in _activeEntries) {
for (ChildEntry entry in _activeEntries) {
entry.dispose();
}
super.dispose();
Expand Down
4 changes: 2 additions & 2 deletions packages/animations/test/page_transition_switcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ void main() {
});

testWidgets('using custom layout', (WidgetTester tester) async {
Widget newLayoutBuilder(List<_ChildEntry> activeEntries) {
Widget newLayoutBuilder(List<ChildEntry> activeEntries) {
return Column(
children: activeEntries
.map<Widget>((_ChildEntry entry) => entry.transition)
.map<Widget>((ChildEntry entry) => entry.transition)
.toList(),
);
}
Expand Down