I've called post type api to load data asynchronously on ListView using FutureBuilder but it called only once, I want to display infinite data loading on my ListView.
Is their I missing to add some properties of FutureBuilder or ListView.
Can anyone help me solved this issue, I'm new to flutter.
I'm using stateful widget to achieve this functionality.
Please refer below code,
import 'package:flutter/material.dart';
import 'package:testlistviewlazyload/Utils.dart';
import 'package:testlistviewlazyload/ServiceManager.dart';
import 'package:testlistviewlazyload/Constant.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class ClassHome extends StatefulWidget {
@override
stateClassHome createState() => stateClassHome();
}
class stateClassHome extends State<ClassHome> {
bool isLoading = false;
List<dynamic> arrayFoodList = List<dynamic>();
@override
void initState() {
super.initState();
}
Future<List<dynamic>> funcLoadMore() async{
var dicArguments = {'restaurant_id': '3',
'menu_id': '0',
'offset': '0'
};
final dictResponse = await ServiceManager().callWebservice(
enumMethodType.POST, ConstantApi.keyRestaurantMenuFoodList,
dicArguments, {
'Authorization':
await Utils().funcGetSession(ConstantSession.keyAuthToken)
}, 'tagRestaurantMenuFoodList');
if (dictResponse['error'] == false) {
if (dictResponse['mainResponse']['error'] == false) {
return dictResponse['mainResponse']['data']['food_items']
as List<dynamic>;
} else {
Utils()
.funcDisplayAlertView(
'', "${dictResponse['message']}", context);
}
} else {
Utils().funcDisplayAlertView(
'', "${dictResponse['message']}", context);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('hello')),
body: Container(
color: Colors.pink[50],
child: Column(
children: <Widget>[
Expanded(
child: FutureBuilder<List<dynamic>>(
future: funcLoadMore(), // a previously-obtained Future<String> or null
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
List<dynamic> arrayTest = snapshot.data ?? [];
return Scrollbar(
child: ListView.builder(
itemCount: arrayTest.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(arrayTest[index]['name']),
);
},
)
);
},
),
),
Container(
height: isLoading ? 50.0 : 0,
color: Colors.white,
child: Center(
child: new CircularProgressIndicator(),
),
),
],
),
)
);
}
}