infinite_listview 1.0.0 infinite_listview: ^1.0.0 copied to clipboard
ListView with items that can be scrolled infinitely in both directions.
import 'package:flutter/material.dart';
import 'package:infinite_listview/infinite_listview.dart';
void main() => runApp(ExampleApp());
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: ExampleScreen(),
);
}
}
class ExampleScreen extends StatefulWidget {
@override
_ExampleScreenState createState() => _ExampleScreenState();
}
class _ExampleScreenState extends State<ExampleScreen> {
final InfiniteScrollController _infiniteController = InfiniteScrollController(
initialScrollOffset: 0.0,
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Example'),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.arrow_downward),
onPressed: () {
_infiniteController.animateTo(_infiniteController.offset + 2000.0, duration: const Duration(milliseconds: 250), curve: Curves.easeIn);
},
),
IconButton(
icon: const Icon(Icons.arrow_upward),
onPressed: () {
_infiniteController.animateTo(_infiniteController.offset - 2000.0, duration: const Duration(milliseconds: 250), curve: Curves.easeIn);
},
),
],
),
body: InfiniteListView.separated(
controller: _infiniteController,
itemBuilder: _buildItem,
separatorBuilder: (BuildContext context, int index) => const Divider(height: 2.0),
),
);
}
Widget _buildItem(BuildContext context, int index) {
return Material(
child: InkWell(
onTap: () {},
child: ListTile(
title: Text('Item #$index'),
subtitle: Text('Subtitle $index'),
trailing: const Icon(Icons.chevron_right),
),
),
);
}
}