Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7d51af

Browse files
committedMar 14, 2025·
Add cupertino examples to the Floating App Bar recipe.
1 parent 4968173 commit c7d51af

File tree

7 files changed

+323
-66
lines changed

7 files changed

+323
-66
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
void main() => runApp(const MyApp());
4+
5+
class MyApp extends StatelessWidget {
6+
const MyApp({super.key});
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
const title = 'Floating Navigation Bar';
11+
12+
return CupertinoApp(
13+
title: title,
14+
home: CupertinoPageScaffold(
15+
// No navigation bar provided to CupertinoPageScaffold,
16+
// only a body with a CustomScrollView.
17+
child: CustomScrollView(
18+
slivers: [
19+
// Add the navigation bar to the CustomScrollView.
20+
const CupertinoSliverNavigationBar(
21+
// Provide a standard title.
22+
largeTitle: Text(title),
23+
),
24+
// #docregion SliverList
25+
// Next, create a SliverList
26+
SliverList(
27+
// Use a delegate to build items as they're scrolled on screen.
28+
delegate: SliverChildBuilderDelegate(
29+
// The builder function returns a ListTile with a title that
30+
// displays the index of the current item.
31+
(context, index) =>
32+
CupertinoListTile(title: Text('Item #$index')),
33+
// Builds 50 ListTiles
34+
childCount: 50,
35+
),
36+
),
37+
// #enddocregion SliverList
38+
],
39+
),
40+
),
41+
);
42+
}
43+
}

‎examples/cookbook/lists/floating_app_bar/lib/main.dart ‎examples/cookbook/lists/floating_app_bar/lib/main_material.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class MyApp extends StatelessWidget {
1212
return MaterialApp(
1313
title: title,
1414
home: Scaffold(
15-
// No appbar provided to the Scaffold, only a body with a
15+
// No app bar provided to Scaffold, only a body with a
1616
// CustomScrollView.
1717
body: CustomScrollView(
1818
slivers: [
@@ -21,6 +21,8 @@ class MyApp extends StatelessWidget {
2121
// Provide a standard title.
2222
title: Text(title),
2323
// Allows the user to reveal the app bar if they begin scrolling
24+
pinned: true,
25+
// Allows the user to reveal the app bar if they begin scrolling
2426
// back up the list of items.
2527
floating: true,
2628
// Display a placeholder widget to visualize the shrinking size.
@@ -36,8 +38,8 @@ class MyApp extends StatelessWidget {
3638
// The builder function returns a ListTile with a title that
3739
// displays the index of the current item.
3840
(context, index) => ListTile(title: Text('Item #$index')),
39-
// Builds 1000 ListTiles
40-
childCount: 1000,
41+
// Builds 50 ListTiles
42+
childCount: 50,
4143
),
4244
),
4345
// #enddocregion SliverList
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
class MyApp extends StatelessWidget {
4+
const MyApp({super.key});
5+
6+
@override
7+
Widget build(BuildContext context) {
8+
// #docregion CustomScrollView
9+
return const CupertinoApp(
10+
home: CupertinoPageScaffold(
11+
// No navigation bar property provided yet.
12+
child: CustomScrollView(
13+
// Add the navigation bar and list of items as slivers in the next steps.
14+
slivers: <Widget>[],
15+
),
16+
),
17+
);
18+
// #enddocregion CustomScrollView
19+
}
20+
}

‎examples/cookbook/lists/floating_app_bar/lib/starter.dart ‎examples/cookbook/lists/floating_app_bar/lib/starter_material.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MyApp extends StatelessWidget {
77
Widget build(BuildContext context) {
88
// #docregion CustomScrollView
99
return const Scaffold(
10-
// No appBar property provided, only the body.
10+
// No app bar property provided yet.
1111
body: CustomScrollView(
1212
// Add the app bar and list of items as slivers in the next steps.
1313
slivers: <Widget>[],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
void main() => runApp(const MyApp());
4+
5+
class MyApp extends StatelessWidget {
6+
const MyApp({super.key});
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
const title = 'Floating Navigation Bar';
11+
12+
return CupertinoApp(
13+
title: title,
14+
home: CupertinoPageScaffold(
15+
// No navigation bar provided to CupertinoPageScaffold,
16+
// only a body with a CustomScrollView.
17+
// #docregion SliverAppBar
18+
child: CustomScrollView(
19+
slivers: [
20+
// Add the navigation bar to the CustomScrollView.
21+
const CupertinoSliverNavigationBar(
22+
// Provide a standard title.
23+
largeTitle: Text(title),
24+
),
25+
],
26+
),
27+
// #enddocregion SliverAppBar
28+
),
29+
);
30+
}
31+
}

‎examples/cookbook/lists/floating_app_bar/lib/step2.dart ‎examples/cookbook/lists/floating_app_bar/lib/step2_material.dart

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class MyApp extends StatelessWidget {
2222
// Provide a standard title.
2323
title: Text(title),
2424
// Allows the user to reveal the app bar if they begin scrolling
25+
pinned: true,
26+
// Allows the user to reveal the app bar if they begin scrolling
2527
// back up the list of items.
2628
floating: true,
2729
// Display a placeholder widget to visualize the shrinking size.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.