Flutter CustomScrollView slivers stacking.
Step one: Use ListView inside SliverAppBar widget. To make css overflow:hidden effect.
Step two: Add controller to NestedScrollView and move the button on scrolling in a stack. Plus calculate where you want to stop button moving.
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { ScrollController scrollController; final double expandedHight = 150.0; @override void initState() { super.initState(); scrollController = new ScrollController(); scrollController.addListener(() => setState(() {})); } @override void dispose() { scrollController.dispose(); super.dispose(); } double get top { double res = expandedHight; if (scrollController.hasClients) { double offset = scrollController.offset; if (offset < (res - kToolbarHeight)) { res -= offset; } else { res = kToolbarHeight; } } return res; } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, body: Stack( children: [ NestedScrollView( controller: scrollController, headerSliverBuilder: (context, value) { return [ SliverAppBar( pinned: true, expandedHeight: expandedHight, flexibleSpace: ListView( physics: const NeverScrollableScrollPhysics(), children: [ AppBar( title: Text('AfroJack'), elevation: 0.0, ), Container( color: Colors.blue, height: 100, alignment: Alignment.center, child: RaisedButton( child: Text('folow'), onPressed: () => print('folow pressed'), ), ), ], ), ), ]; }, body: ListView.builder( physics: const NeverScrollableScrollPhysics(), itemCount: 80, itemBuilder: (BuildContext context, int index) { return Text( 'text_string'.toUpperCase(), style: TextStyle( color: Colors.white, ), ); }, ), ), Positioned( top: top, width: MediaQuery.of(context).size.width, child: Align( child: RaisedButton( onPressed: () => print('shuffle pressed'), child: Text('Suffle'), ), ), ), ], ), ); } } |
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.