|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +class Index extends StatefulWidget { |
| 4 | + @override |
| 5 | + State<StatefulWidget> createState() => _IndexState(); |
| 6 | +} |
| 7 | + |
| 8 | +class _IndexState extends State<Index> { |
| 9 | + @override |
| 10 | + void initState() { |
| 11 | + super.initState(); |
| 12 | + } |
| 13 | + |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + return Scrollable( |
| 17 | + axisDirection: AxisDirection.left, |
| 18 | + controller: ScrollController(), |
| 19 | + viewportBuilder: (context, offset) { |
| 20 | + return CustomScrollView( |
| 21 | + slivers: [ |
| 22 | + SliverAppBar( |
| 23 | + pinned: true, |
| 24 | + expandedHeight: 250.0, |
| 25 | + flexibleSpace: FlexibleSpaceBar( |
| 26 | + title: Text('这里的标题会随着滚动向移'), |
| 27 | + ), |
| 28 | + ), |
| 29 | + SliverGrid( |
| 30 | + gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( |
| 31 | + maxCrossAxisExtent: 200.0, |
| 32 | + mainAxisSpacing: 10.0, |
| 33 | + crossAxisSpacing: 10.0, |
| 34 | + childAspectRatio: 4.0, |
| 35 | + ), |
| 36 | + delegate: SliverChildBuilderDelegate( |
| 37 | + (BuildContext context, int index) { |
| 38 | + return Container( |
| 39 | + alignment: Alignment.center, |
| 40 | + color: Colors.teal[100 * (index % 9)], |
| 41 | + child: Text('grid item $index'), |
| 42 | + ); |
| 43 | + }, |
| 44 | + childCount: 20, |
| 45 | + ), |
| 46 | + ), |
| 47 | + SliverFixedExtentList( |
| 48 | + itemExtent: 50.0, |
| 49 | + delegate: SliverChildBuilderDelegate( |
| 50 | + (BuildContext context, int index) { |
| 51 | + return Container( |
| 52 | + alignment: Alignment.center, |
| 53 | + color: Colors.lightBlue[100 * (index % 9)], |
| 54 | + child: Text('list item $index'), |
| 55 | + ); |
| 56 | + }, |
| 57 | + childCount: 20 |
| 58 | + ), |
| 59 | + ), |
| 60 | + ], |
| 61 | + ); |
| 62 | + }, |
| 63 | + ); |
| 64 | + } |
| 65 | +} |
0 commit comments