loadmore 2.1.0 loadmore: ^2.1.0 copied to clipboard
listview scroll to bottom ,can load more data. help developer paging load data.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:loadmore/loadmore.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.red,
platform: TargetPlatform.iOS,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int get count => list.length;
List<int> list = [];
@override
void initState() {
super.initState();
// list.addAll(List.generate(30, (v) => v));
}
void load() {
print("load");
setState(() {
list.addAll(List.generate(5, (v) => v));
print("data count = ${list.length}");
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: RefreshIndicator(
onRefresh: _refresh,
child: LoadMore(
isFinish: count >= 60,
onLoadMore: _loadMore,
whenEmptyLoad: true,
delegate: const DefaultLoadMoreDelegate(),
textBuilder: DefaultLoadMoreTextBuilder.chinese,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('Item $index'),
subtitle: Text('The value: ${list[index]}'),
);
},
itemCount: count,
),
),
),
);
}
Future<bool> _loadMore() async {
print("onLoadMore");
await Future.delayed(const Duration(seconds: 0, milliseconds: 100));
load();
return true;
}
Future<void> _refresh() async {
await Future.delayed(const Duration(seconds: 0, milliseconds: 100));
list.clear();
load();
}
}