Visitar URL original
[animations] Introduce layoutBuilder parameter to PageTransitionSwitcher by federunco · Pull Request #170 · flutter/packages · GitHub
Skip to content
Merged
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
Next Next commit
Make Stack alignment a property
Workaround for flutter/flutter#54585
  • Loading branch information
federunco committed Aug 17, 2020
commit b7e078c6750358106771ff986bb6ea7ed9441e06
28 changes: 18 additions & 10 deletions packages/animations/lib/src/page_transition_switcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

Expand Down Expand Up @@ -58,10 +57,10 @@ class _ChildEntry {
/// its child appears, and the secondary animation to define how its child
/// disappears.
typedef PageTransitionSwitcherTransitionBuilder = Widget Function(
Widget child,
Animation<double> primaryAnimation,
Animation<double> secondaryAnimation,
);
Widget child,

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.

revert these formatting changes.

Animation<double> primaryAnimation,
Animation<double> secondaryAnimation,
);

/// A widget that transitions from an old child to a new child whenever [child]
/// changes using an animation specified by [transitionBuilder].
Expand Down Expand Up @@ -149,6 +148,7 @@ class PageTransitionSwitcher extends StatefulWidget {
this.duration = const Duration(milliseconds: 300),
this.reverse = false,
@required this.transitionBuilder,
this.alignment = Alignment.center,

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.

assert that alignment is not null and mention that in the doc above.

this.child,
}) : assert(duration != null),
assert(reverse != null),
Expand Down Expand Up @@ -203,6 +203,14 @@ class PageTransitionSwitcher extends StatefulWidget {
/// The child provided to the transitionBuilder may be null.
final PageTransitionSwitcherTransitionBuilder transitionBuilder;

/// The alignment of [child] when its animated

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.

nit: its -> it's

///
/// The given alignment is applied during the animation of the child, when
/// the animation is finished, the original alignment is applied to the child.

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.

It's not clear what "the original alignment" is.

///
/// Defaults to Alignment.center

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.

Suggested change
/// Defaults to Alignment.center
/// Defaults to [Alignment.center].

final AlignmentGeometry alignment;

@override
_PageTransitionSwitcherState createState() => _PageTransitionSwitcherState();
}
Expand Down Expand Up @@ -310,8 +318,8 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
secondaryController,
);
assert(
transition != null,
'PageTransitionSwitcher.builder must not return null.',
transition != null,

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.

revert formatting change

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.

revert formatting change

'PageTransitionSwitcher.builder must not return null.',
);
final _ChildEntry entry = _ChildEntry(
widgetChild: child,
Expand Down Expand Up @@ -352,8 +360,8 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
entry.secondaryController,
);
assert(
transition != null,
'PageTransitionSwitcher.builder must not return null.',
transition != null,
'PageTransitionSwitcher.builder must not return null.',
);
entry.transition = KeyedSubtree(
key: entry.transition.key,
Expand All @@ -375,7 +383,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
children: _activeEntries
.map<Widget>((_ChildEntry entry) => entry.transition)
.toList(),
alignment: Alignment.center,
alignment: widget.alignment,
);
}
}