Flutter: infinite list example
這是一個flutter infinite list example:
https://github.com/flutter/samples/tree/master/infinite_list
看不太懂,目前還在研究中...
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<Catalog>(
create: (context) => Catalog(),
child: MaterialApp(
title: 'Infinite List Sample',
home: MyHomePage(),
),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Infinite List Sample'),
),
body: Selector<Catalog, int?>(
// Selector is a widget from package:provider. It allows us to listen
// to only one aspect of a provided value. In this case, we are only
// listening to the catalog's `itemCount`, because that's all we need
// at this level.
selector: (context, catalog) => catalog.itemCount,
builder: (context, itemCount, child) => ListView.builder(
// When `itemCount` is null, `ListView` assumes an infinite list.
// Once we provide a value, it will stop the scrolling beyond
// the last element.
itemCount: itemCount,
padding: const EdgeInsets.symmetric(vertical: 18),
itemBuilder: (context, index) {
// Every item of the `ListView` is individually listening
// to the catalog.
var catalog = Provider.of<Catalog>(context);
// Catalog provides a single synchronous method for getting
// the current data.
var item = catalog.getByIndex(index);
if (item.isLoading) {
return LoadingItemTile();
}
return ItemTile(item: item);
},
),
),
);
}
}
1.可以知道的是這是用 ListView.builder
2. 還用到很多 Future<ItemPage> fetchPage(int startingIndex) async 語法....
3. app using provider.
然後這個listview沒有 scroll indicator.
又要自己加:
可參考一下這個連結:
https://stackoverflow.com/questions/53030672/flutter-how-to-add-scroll-indicator-in-listview
跟android差很多...
留言
張貼留言