super_list_view 0.0.5
with this package you can make a dynamic listView with less code and its load more item with more scroll,and can refresh items with just pulling up
SUPER LIST VIEW
With this Package you can have a dynamic super ListView Widget allows to you:
- less code to create ListView
- scroll to load Items
- refresh and reUpdate ListViewItems with pulling top
Installation
Run following command at terminal:
dart pub add super_list_view
or add this line to pubspec.yaml
dependencies:
super_list_view: ^0.0.1
then
flutter get pub
usage
let's know what we need to build this widget:
-
listViewItems: a variable every time update withsetState()It will stack to previous Data inListViewItemsso you should not add new data to previous data as follow. simple:if you wans show new items, just put new item in this variable withsetState. -
getListViewItems: a Function what load data and changelistViewItemswithsetState(). it has just has one parampage -
page: what is page? its a value say to you, what you have to load from your api or etc. -
SuperListView().build(): it has 3 params and rerutns your
SuperListView.a.
contextis your BuildContext for your Viewb.
listViewItems:your new items for your superListViewc.
item builder: its a function has 3 params and returns a Widget which is your View per your items. we can see this function prams:-
context: no need to explain :) -
item: its your item for this index of yourlistViewItems. -
index: your item counter
d.
set: a callBackFunction runs whensuperListViewwant new data. you can handle that just with a Function and its pareter ispagewhat you can pass togetListViewItemsfunction to load new data -
-
refresh(): this method clear and refreshe yoursuperListView.
import 'package:flutter/material.dart';
import 'package:flutter/SuperListView.dart';
.
.
.
class ThisState extends State {
List listViewItems = [];
@override
void initState() {
super.initState();
//get first data from api
getListViewItems(0);
}
getListViewItems(int page) async {
//this Function update and load ListViewItems from every where you want
//you have to update ListViewItem Variable here to effect to superListView with setState()
//Note: you have to just add NewItems to "ListViewItems",because SuperListView stack new data to old data
List res = Requst.fromSomeWhere();
setState(() {
listViewItems = res;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('title'),
),
body: SuperListView().build(context,
listViewItems,
(BuildContext context, item, index) {
//with this item you can access to data for this index of ListViewItems
retrun Text(index.toString()+ '. ' +item['name']);
}, (int page) {
//this function runs after ListView needed to load more data, its return page and you have to update "listViewItems" with setData method
getListViewItems(page);
}),
);
}
}