Flutter app bar scrolling with overlapping content in Flexible space. You can listen to the ScrollController and use a Stack to achieve the effect you’re interested in based on the scroll offset.
Here is a quick example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Scroll demo', home: new Scaffold( appBar: new AppBar(elevation: 0.0), body: new CustomScroll(), ), ); } } class CustomScroll extends StatefulWidget { @override State createState() => new CustomScrollState(); } class CustomScrollState extends State<CustomScroll> { ScrollController scrollController; double offset = 0.0; static const double kEffectHeight = 100.0; @override Widget build(BuildContext context) { return new Stack( alignment: AlignmentDirectional.topCenter, children: <Widget> [ new Container( color: Colors.blue, height: (kEffectHeight - offset * 0.5).clamp(0.0, kEffectHeight), ), new Positioned( child: new Container( width: 200.0, child: new ListView.builder( itemCount: 100, itemBuilder: buildListItem, controller: scrollController, ), ), ), ], ); } Widget buildListItem(BuildContext context, int index) { return new Container( color: Colors.white, child: new Text('Item $index') ); } void updateOffset() { setState(() { offset = scrollController.offset; }); } @override void initState() { super.initState(); scrollController = new ScrollController(); scrollController.addListener(updateOffset); } @override void dispose() { super.dispose(); scrollController.removeListener(updateOffset); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.