Expose alwaysShowMiddle in CupertinoSliverNavigationBar (#113544)
* SLFLF-5: Expose `alwaysShowMiddle` in `CupertinoSliverNavigationBar` * SLFLF-5: Remove space in docstring * SLFLF-5: Add test and update documentation * SLFLF-5: Remove trailing whitespace (again)
This commit is contained in:
@@ -586,6 +586,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
|
||||
this.leading,
|
||||
this.automaticallyImplyLeading = true,
|
||||
this.automaticallyImplyTitle = true,
|
||||
this.alwaysShowMiddle = true,
|
||||
this.previousPageTitle,
|
||||
this.middle,
|
||||
this.trailing,
|
||||
@@ -645,13 +646,25 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
|
||||
/// This value cannot be null.
|
||||
final bool automaticallyImplyTitle;
|
||||
|
||||
/// Controls whether [middle] widget should always be visible (even in
|
||||
/// expanded state).
|
||||
///
|
||||
/// If true (default) and [middle] is not null, [middle] widget is always
|
||||
/// visible. If false, [middle] widget is visible only in collapsed state if
|
||||
/// it is provided.
|
||||
///
|
||||
/// This should be set to false if you only want to show [largeTitle] in
|
||||
/// expanded state and [middle] in collapsed state.
|
||||
final bool alwaysShowMiddle;
|
||||
|
||||
/// {@macro flutter.cupertino.CupertinoNavigationBar.previousPageTitle}
|
||||
final String? previousPageTitle;
|
||||
|
||||
/// A widget to place in the middle of the static navigation bar instead of
|
||||
/// the [largeTitle].
|
||||
///
|
||||
/// This widget is visible in both collapsed and expanded states. The text
|
||||
/// This widget is visible in both collapsed and expanded states if
|
||||
/// [alwaysShowMiddle] is true, otherwise just in collapsed state. The text
|
||||
/// supplied in [largeTitle] will no longer appear in collapsed state if a
|
||||
/// [middle] widget is provided.
|
||||
final Widget? middle;
|
||||
@@ -742,7 +755,7 @@ class _CupertinoSliverNavigationBarState extends State<CupertinoSliverNavigation
|
||||
transitionBetweenRoutes: widget.transitionBetweenRoutes,
|
||||
heroTag: widget.heroTag,
|
||||
persistentHeight: _kNavBarPersistentHeight + MediaQuery.of(context).padding.top,
|
||||
alwaysShowMiddle: widget.middle != null,
|
||||
alwaysShowMiddle: widget.alwaysShowMiddle && widget.middle != null,
|
||||
stretchConfiguration: widget.stretch ? OverScrollHeaderStretchConfiguration() : null,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -532,6 +532,52 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('User specified middle is only visible when sliver is collapsed if alwaysShowMiddle is false', (WidgetTester tester) async {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: CustomScrollView(
|
||||
controller: scrollController,
|
||||
slivers: const <Widget>[
|
||||
CupertinoSliverNavigationBar(
|
||||
largeTitle: Text('Large'),
|
||||
middle: Text('Middle'),
|
||||
alwaysShowMiddle: false,
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: SizedBox(
|
||||
height: 1200.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(scrollController.offset, 0.0);
|
||||
expect(find.text('Middle'), findsOneWidget);
|
||||
|
||||
// Initially (in expanded state) middle widget is not visible.
|
||||
RenderAnimatedOpacity middleOpacity = tester.element(find.text('Middle')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
|
||||
expect(middleOpacity.opacity.value, 0.0);
|
||||
|
||||
scrollController.jumpTo(600.0);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Middle widget is visible when nav bar is collapsed.
|
||||
middleOpacity = tester.element(find.text('Middle')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
|
||||
expect(middleOpacity.opacity.value, 1.0);
|
||||
|
||||
scrollController.jumpTo(0.0);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Middle widget is not visible when nav bar is again expanded.
|
||||
middleOpacity = tester.element(find.text('Middle')).findAncestorRenderObjectOfType<RenderAnimatedOpacity>()!;
|
||||
expect(middleOpacity.opacity.value, 0.0);
|
||||
});
|
||||
|
||||
testWidgets('Small title can be overridden', (WidgetTester tester) async {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
await tester.pumpWidget(
|
||||
|
||||
Reference in New Issue
Block a user