Skip to content

Instantly share code, notes, and snippets.

@Sandfone
Last active September 1, 2020 08:43
Show Gist options
  • Select an option

  • Save Sandfone/44717e84159644cebe652bcf5d138af1 to your computer and use it in GitHub Desktop.

Select an option

Save Sandfone/44717e84159644cebe652bcf5d138af1 to your computer and use it in GitHub Desktop.
bidirectional list view #flutter #bidirectional
// 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