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
d1daa5dd
Unverified
Commit
d1daa5dd
authored
Mar 03, 2022
by
Taha Tesser
Committed by
GitHub
Mar 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`CupertinoSliverNavigationBar`: Add example (#99384)
Part of #72926
parent
f320d140
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
0 deletions
+181
-0
cupertino_sliver_nav_bar.0.dart
...api/lib/cupertino/nav_bar/cupertino_sliver_nav_bar.0.dart
+106
-0
cupertino_sliver_nav_bar.0_test.dart
...st/cupertino/nav_bar/cupertino_sliver_nav_bar.0_test.dart
+68
-0
nav_bar.dart
packages/flutter/lib/src/cupertino/nav_bar.dart
+7
-0
No files found.
examples/api/lib/cupertino/nav_bar/cupertino_sliver_nav_bar.0.dart
0 → 100644
View file @
d1daa5dd
// 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.
// Flutter code sample for CupertinoSliverNavigationBar
import
'package:flutter/cupertino.dart'
;
void
main
(
)
=>
runApp
(
const
MyApp
());
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
static
const
String
_title
=
'CupertinoSliverNavigationBar Sample'
;
@override
Widget
build
(
BuildContext
context
)
{
return
const
CupertinoApp
(
title:
_title
,
home:
CupertinoNavBarSample
(),
);
}
}
class
CupertinoNavBarSample
extends
StatelessWidget
{
const
CupertinoNavBarSample
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
return
CupertinoPageScaffold
(
// A ScrollView that creates custom scroll effects using slivers.
child:
CustomScrollView
(
// A list of sliver widgets.
slivers:
<
Widget
>[
const
CupertinoSliverNavigationBar
(
leading:
Icon
(
CupertinoIcons
.
person_2
),
// This title is visible in both collapsed and expanded states.
// When the "middle" parameter is omitted, the widget provided
// in the "largeTitle" parameter is used instead in the collapsed state.
largeTitle:
Text
(
'Contacts'
),
trailing:
Icon
(
CupertinoIcons
.
add_circled
),
),
// This widget fills the remaining space in the viewport.
// Drag the scrollable area to collapse the CupertinoSliverNavigationBar.
SliverFillRemaining
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
<
Widget
>[
const
Text
(
'Drag me up'
,
textAlign:
TextAlign
.
center
),
CupertinoButton
.
filled
(
onPressed:
()
{
Navigator
.
push
(
context
,
CupertinoPageRoute
<
Widget
>(
builder:
(
BuildContext
context
)
{
return
const
NextPage
();
}));
},
child:
const
Text
(
'Go to Next Page'
),
)
],
),
),
],
),
);
}
}
class
NextPage
extends
StatelessWidget
{
const
NextPage
({
Key
?
key
})
:
super
(
key:
key
);
@override
Widget
build
(
BuildContext
context
)
{
final
Brightness
brightness
=
CupertinoTheme
.
brightnessOf
(
context
);
return
CupertinoPageScaffold
(
child:
CustomScrollView
(
slivers:
<
Widget
>[
CupertinoSliverNavigationBar
(
backgroundColor:
CupertinoColors
.
systemYellow
,
border:
Border
(
bottom:
BorderSide
(
color:
brightness
==
Brightness
.
light
?
CupertinoColors
.
black
:
CupertinoColors
.
white
,
),
),
// The middle widget is visible in both collapsed and expanded states.
middle:
const
Text
(
'Contacts Group'
),
// When the "middle" parameter is implemented, the larget title is only visible
// when the CupertinoSliverNavigationBar is fully expanded.
largeTitle:
const
Text
(
'Family'
),
),
SliverFillRemaining
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
const
<
Widget
>[
Text
(
'Drag me up'
,
textAlign:
TextAlign
.
center
),
// When the "leading" parameter is omitted on a route that has a previous page,
// the back button is automatically added to the leading position.
Text
(
'Tap on the leading button to navigate back'
,
textAlign:
TextAlign
.
center
),
],
),
),
],
),
);
}
}
examples/api/test/cupertino/nav_bar/cupertino_sliver_nav_bar.0_test.dart
0 → 100644
View file @
d1daa5dd
// 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/cupertino.dart'
;
import
'package:flutter_api_samples/cupertino/nav_bar/cupertino_sliver_nav_bar.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
const
Offset
dragUp
=
Offset
(
0.0
,
-
150.0
);
void
main
(
)
{
testWidgets
(
'Collapse and expand CupertinoSliverNavigationBar changes title position'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
MyApp
(),
);
// Large title is visible and at lower position.
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Contacts'
).
first
).
dy
,
88.0
);
await
tester
.
fling
(
find
.
text
(
'Drag me up'
),
dragUp
,
500.0
);
await
tester
.
pumpAndSettle
();
// Large title is hidden and at higher position.
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Contacts'
).
first
).
dy
,
36.0
);
});
testWidgets
(
'Middle widget is visible in both collapsed and expanded states'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
MyApp
(),
);
// Navigate to a page that has both middle and large titles.
final
Finder
nextButton
=
find
.
text
(
'Go to Next Page'
);
expect
(
nextButton
,
findsOneWidget
);
await
tester
.
tap
(
nextButton
);
await
tester
.
pumpAndSettle
();
// Both middle and large titles are visible.
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Contacts Group'
).
first
).
dy
,
30.5
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Family'
).
first
).
dy
,
88.0
);
await
tester
.
fling
(
find
.
text
(
'Drag me up'
),
dragUp
,
500.0
);
await
tester
.
pumpAndSettle
();
// Large title is hidden and middle title is visible.
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Contacts Group'
).
first
).
dy
,
30.5
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'Family'
).
first
).
dy
,
36.0
);
});
testWidgets
(
'CupertinoSliverNavigationBar with previous route has back button'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
MyApp
(),
);
// Navigate to a page that has back button
final
Finder
nextButton
=
find
.
text
(
'Go to Next Page'
);
expect
(
nextButton
,
findsOneWidget
);
await
tester
.
tap
(
nextButton
);
await
tester
.
pumpAndSettle
();
expect
(
nextButton
,
findsNothing
);
// Go back to the previous page.
final
Finder
backButton
=
find
.
byType
(
CupertinoButton
);
expect
(
backButton
,
findsOneWidget
);
await
tester
.
tap
(
backButton
);
await
tester
.
pumpAndSettle
();
expect
(
nextButton
,
findsOneWidget
);
});
}
packages/flutter/lib/src/cupertino/nav_bar.dart
View file @
d1daa5dd
...
@@ -564,10 +564,17 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
...
@@ -564,10 +564,17 @@ class _CupertinoNavigationBarState extends State<CupertinoNavigationBar> {
/// user scrolls, but it will also stretch when the user over-scrolls if the
/// user scrolls, but it will also stretch when the user over-scrolls if the
/// [stretch] value is `true`. Defaults to `false`.
/// [stretch] value is `true`. Defaults to `false`.
///
///
/// {@tool dartpad}
/// This example shows [CupertinoSliverNavigationBar] in action inside a [CustomScrollView].
///
/// ** See code in examples/api/lib/cupertino/nav_bar/cupertino_sliver_nav_bar.0.dart **
/// {@end-tool}
///
/// See also:
/// See also:
///
///
/// * [CupertinoNavigationBar], an iOS navigation bar for use on non-scrolling
/// * [CupertinoNavigationBar], an iOS navigation bar for use on non-scrolling
/// pages.
/// pages.
/// * [CustomScrollView], a ScrollView that creates custom scroll effects using slivers.
class
CupertinoSliverNavigationBar
extends
StatefulWidget
{
class
CupertinoSliverNavigationBar
extends
StatefulWidget
{
/// Creates a navigation bar for scrolling lists.
/// Creates a navigation bar for scrolling lists.
///
///
...
...
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