Last active
September 1, 2020 08:43
-
-
Save Sandfone/44717e84159644cebe652bcf5d138af1 to your computer and use it in GitHub Desktop.
bidirectional list view #flutter #bidirectional
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
| // FROM: https://github.com/flutter/flutter/issues/20608 | |
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/rendering.dart'; | |
| import 'package:flutter/widgets.dart'; | |
| class EndlessListExampleApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| Key forwardListKey = UniqueKey(); | |
| Widget forwardList = SliverList( | |
| delegate: SliverChildBuilderDelegate((BuildContext context, int index) { | |
| return Container( | |
| color: index % 2 == 0 ? Colors.green : Colors.yellow, | |
| child: Text('fordward $index'), | |
| height: 100.0, | |
| ); | |
| }), | |
| key: forwardListKey, | |
| ); | |
| Widget reverseList = SliverList( | |
| delegate: SliverChildBuilderDelegate((BuildContext context, int index) { | |
| return Container( | |
| color: index % 2 == 0 ? Colors.green : Colors.yellow, | |
| child: Text('reverse $index'), | |
| height: 100.0, | |
| ); | |
| }), | |
| ); | |
| return MaterialApp( | |
| home: Scaffold( | |
| appBar: AppBar( | |
| title: Text('Endless List'), | |
| ), | |
| body: Scrollable( | |
| viewportBuilder: (BuildContext context, ViewportOffset offset) { | |
| return Viewport( | |
| offset: offset, | |
| center: forwardListKey, | |
| slivers: [ | |
| reverseList, | |
| forwardList, | |
| ], | |
| ); | |
| }, | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| void main() { | |
| runApp(EndlessListExampleApp()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment