Created
May 15, 2019 02:22
-
-
Save Andrious/3bc72239aae61c8bf652210f4046f23d to your computer and use it in GitHub Desktop.
Change size and colour of SliverAppBar
This file contains 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/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
MyApp({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final title = 'Floating App Bar'; | |
return MaterialApp( | |
title: title, | |
home: Scaffold( | |
// No appbar provided to the Scaffold, only a body with a | |
// CustomScrollView | |
body: CustomScrollView( | |
slivers: <Widget>[ | |
// Add the app bar to the CustomScrollView | |
SliverAppBar( | |
leading: IconButton( | |
icon: Icon(Icons.home), | |
tooltip: 'Click to Home Screen', | |
onPressed: () { | |
// handle the press | |
}), | |
// Provide a standard title | |
title: Text(title), | |
actions: <Widget>[ | |
IconButton( | |
icon: Icon(Icons.shopping_cart), | |
tooltip: 'Open shopping cart', | |
onPressed: () { | |
// handle the press | |
}, | |
), | |
], | |
brightness: Brightness.light, | |
backgroundColor: Colors.transparent, | |
iconTheme: IconThemeData( | |
color: Colors.yellowAccent, | |
), | |
textTheme: TextTheme( | |
title: | |
TextStyle(fontFamily: 'RobotoMono', color: Colors.deepOrange, | |
fontSize: 36.0), | |
), | |
forceElevated: true, | |
floating: true, | |
pinned: true, | |
// Make the initial height of the SliverAppBar larger than normal | |
expandedHeight: 200, | |
), | |
// 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) => ListTile(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