Created
March 4, 2025 22:18
-
-
Save loic-sharma/837a45540c821e37593bed92dc121631 to your computer and use it in GitHub Desktop.
Cupertino scrolling app bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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