Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cupertino examples to the Floating App Bar recipe. #11821

Merged
merged 5 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/cupertino.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
const title = 'Floating Navigation Bar';

return CupertinoApp(
title: title,
home: CupertinoPageScaffold(
// No navigation bar provided to CupertinoPageScaffold,
// only a body with a CustomScrollView.
child: CustomScrollView(
slivers: [
// Add the navigation bar to the CustomScrollView.
const CupertinoSliverNavigationBar(
// Provide a standard title.
largeTitle: Text(title),
),
// #docregion SliverList
// Next, create a SliverList
SliverList(
// Use a delegate to build items as they're scrolled on screen.
delegate: SliverChildBuilderDelegate(
// The builder function returns a ListTile with a title that
// displays the index of the current item.
(context, index) =>
CupertinoListTile(title: Text('Item #$index')),
// Builds 50 ListTiles
childCount: 50,
),
),
// #enddocregion SliverList
],
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: title,
home: Scaffold(
// No appbar provided to the Scaffold, only a body with a
// No app bar provided to Scaffold, only a body with a
// CustomScrollView.
body: CustomScrollView(
slivers: [
Expand All @@ -21,6 +21,8 @@ class MyApp extends StatelessWidget {
// Provide a standard title.
title: Text(title),
// Allows the user to reveal the app bar if they begin scrolling
pinned: true,
// Allows the user to reveal the app bar if they begin scrolling
// back up the list of items.
floating: true,
// Display a placeholder widget to visualize the shrinking size.
Expand All @@ -36,8 +38,8 @@ class MyApp extends StatelessWidget {
// The builder function returns a ListTile with a title that
// displays the index of the current item.
(context, index) => ListTile(title: Text('Item #$index')),
// Builds 1000 ListTiles
childCount: 1000,
// Builds 50 ListTiles
childCount: 50,
),
),
// #enddocregion SliverList
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/cupertino.dart';

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
// #docregion CustomScrollView
return const CupertinoApp(
home: CupertinoPageScaffold(
// No navigation bar property provided yet.
child: CustomScrollView(
// Add the navigation bar and list of items as slivers in the next steps.
slivers: <Widget>[],
),
),
);
// #enddocregion CustomScrollView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
// #docregion CustomScrollView
return const Scaffold(
// No appBar property provided, only the body.
// No app bar property provided yet.
body: CustomScrollView(
// Add the app bar and list of items as slivers in the next steps.
slivers: <Widget>[],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/cupertino.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
const title = 'Floating Navigation Bar';

return CupertinoApp(
title: title,
home: CupertinoPageScaffold(
// No navigation bar provided to CupertinoPageScaffold,
// only a body with a CustomScrollView.
// #docregion SliverAppBar
child: CustomScrollView(
slivers: [
// Add the navigation bar to the CustomScrollView.
const CupertinoSliverNavigationBar(
// Provide a standard title.
largeTitle: Text(title),
),
],
),
// #enddocregion SliverAppBar
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MyApp extends StatelessWidget {
// Provide a standard title.
title: Text(title),
// Allows the user to reveal the app bar if they begin scrolling
pinned: true,
// Allows the user to reveal the app bar if they begin scrolling
// back up the list of items.
floating: true,
// Display a placeholder widget to visualize the shrinking size.
Expand Down
Loading
Loading