Skip to content

Commit b7e078c

Browse files
committed
Make Stack alignment a property
Workaround for flutter/flutter#54585
1 parent 9072dd2 commit b7e078c

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎packages/animations/lib/src/page_transition_switcher.dart‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'package:flutter/animation.dart';
65
import 'package:flutter/foundation.dart';
76
import 'package:flutter/widgets.dart';
87

@@ -58,10 +57,10 @@ class _ChildEntry {
5857
/// its child appears, and the secondary animation to define how its child
5958
/// disappears.
6059
typedef PageTransitionSwitcherTransitionBuilder = Widget Function(
61-
Widget child,
62-
Animation<double> primaryAnimation,
63-
Animation<double> secondaryAnimation,
64-
);
60+
Widget child,
61+
Animation<double> primaryAnimation,
62+
Animation<double> secondaryAnimation,
63+
);
6564

6665
/// A widget that transitions from an old child to a new child whenever [child]
6766
/// changes using an animation specified by [transitionBuilder].
@@ -149,6 +148,7 @@ class PageTransitionSwitcher extends StatefulWidget {
149148
this.duration = const Duration(milliseconds: 300),
150149
this.reverse = false,
151150
@required this.transitionBuilder,
151+
this.alignment = Alignment.center,
152152
this.child,
153153
}) : assert(duration != null),
154154
assert(reverse != null),
@@ -203,6 +203,14 @@ class PageTransitionSwitcher extends StatefulWidget {
203203
/// The child provided to the transitionBuilder may be null.
204204
final PageTransitionSwitcherTransitionBuilder transitionBuilder;
205205

206+
/// The alignment of [child] when its animated
207+
///
208+
/// The given alignment is applied during the animation of the child, when
209+
/// the animation is finished, the original alignment is applied to the child.
210+
///
211+
/// Defaults to Alignment.center
212+
final AlignmentGeometry alignment;
213+
206214
@override
207215
_PageTransitionSwitcherState createState() => _PageTransitionSwitcherState();
208216
}
@@ -310,8 +318,8 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
310318
secondaryController,
311319
);
312320
assert(
313-
transition != null,
314-
'PageTransitionSwitcher.builder must not return null.',
321+
transition != null,
322+
'PageTransitionSwitcher.builder must not return null.',
315323
);
316324
final _ChildEntry entry = _ChildEntry(
317325
widgetChild: child,
@@ -352,8 +360,8 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
352360
entry.secondaryController,
353361
);
354362
assert(
355-
transition != null,
356-
'PageTransitionSwitcher.builder must not return null.',
363+
transition != null,
364+
'PageTransitionSwitcher.builder must not return null.',
357365
);
358366
entry.transition = KeyedSubtree(
359367
key: entry.transition.key,
@@ -375,7 +383,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
375383
children: _activeEntries
376384
.map<Widget>((_ChildEntry entry) => entry.transition)
377385
.toList(),
378-
alignment: Alignment.center,
386+
alignment: widget.alignment,
379387
);
380388
}
381389
}

0 commit comments

Comments
 (0)