Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created March 4, 2025 22:18
Show Gist options
  • Save loic-sharma/837a45540c821e37593bed92dc121631 to your computer and use it in GitHub Desktop.
Save loic-sharma/837a45540c821e37593bed92dc121631 to your computer and use it in GitHub Desktop.
Cupertino scrolling app bar
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 App Bar';
return CupertinoApp(
title: title,
home: CupertinoPageScaffold(
// No appbar provided to the Scaffold, only a body with a
// CustomScrollView.
child: CustomScrollView(
slivers: [
// Add the app bar to the CustomScrollView.
CupertinoSliverNavigationBar(
// Provide a standard title.
largeTitle: Text(title),
),
// 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 1000 ListTiles
childCount: 1000,
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment