We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My load more is loading all the data at once even if I have three different request bringing data at different time.
import 'package:flutter/material.dart'; import 'package:page_transition/page_transition.dart'; import 'package:smcmemberapp/Pages/SikhPhulwari/create.dart'; import 'package:loadmore/loadmore.dart'; import 'package:smcmemberapp/Router/ApiRouter.dart'; import 'package:smcmemberapp/utils.dart'; class SikhPhulwariPage extends StatefulWidget { const SikhPhulwariPage({Key? key}) : super(key: key); @override State<SikhPhulwariPage> createState() => _SikhPhulwariPageState(); } class _SikhPhulwariPageState extends State<SikhPhulwariPage> { int get count => list.length; int totalCount = 10; List<dynamic> list = []; bool isLoading = true; ApiRoute router = ApiRoute(); int page = 1; int totalPages = 1; Utils utils = Utils(); Future<bool> _loadMore() async { await Future.delayed(Duration(seconds: 0, milliseconds: 100)); if (page > totalPages) { return false; } load(); return true; } void load() async { var req = await router .postResponseFromRoute("mobile_member_listMagazines_api", body: { "page": page.toString(), "limit": "10", }); var res = await jsonDecode(req.body); if (res["status"] == "success") { print(res); if (mounted) { setState(() { list.addAll(res["data"]["rowData"]); totalCount = res["data"]["stats"]["rowCount"]; totalPages = utils.countTotalPages(totalCount, 10); }); page++; } } // print(list); } @override void initState() { // TODO: implement initState super.initState(); // this.load(); isLoading = false; } @override void dispose() { // TODO: implement dispose super.dispose(); } @override Widget build(BuildContext context) { if (isLoading) { return Scaffold( appBar: AppBar( title: Text("ਸਿੱਖ ਫੁੱਲਵਾੜੀ / Sikh Philwari"), ), body: Center( child: CircularProgressIndicator(), ), ); } return Scaffold( bottomNavigationBar: BottomAppBar( // clipBehaviour: Clip.antiAlias, clipBehavior: Clip.antiAliasWithSaveLayer, shape: CircularNotchedRectangle(), notchMargin: 6, child: Container( height: 50.0, color: Colors.indigo, ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () { Navigator.push( context, PageTransition( type: PageTransitionType.bottomToTop, child: SikhPhulwariCreate()), ); }, ), appBar: AppBar( title: Text("ਸਿੱਖ ਫੁੱਲਵਾੜੀ / Sikh Philwari"), actions: [], ), body: Container( child: RefreshIndicator( onRefresh: () async { await Future.delayed(Duration(seconds: 0, milliseconds: 100)); setState(() { list = []; page = 1; load(); }); }, child: LoadMore( isFinish: count >= totalCount, whenEmptyLoad: true, onLoadMore: _loadMore, textBuilder: DefaultLoadMoreTextBuilder.english, delegate: MyLoadMoreDelegate(), child: ListView.builder( itemBuilder: (BuildContext context, int index) { return Container( child: ListTile( title: Text(list[index]["name"]), subtitle: Text(list[index]["id"].toString()), ), ); }, itemCount: count, ), ), ), ), ); } } class MyLoadMoreDelegate extends LoadMoreDelegate { const MyLoadMoreDelegate(); @override Widget buildChild(LoadMoreStatus status, {LoadMoreTextBuilder builder = DefaultLoadMoreTextBuilder.english}) { double _defaultLoadMoreHeight = 100.0; double _loadmoreIndicatorSize = 50.0; String text = builder(status); if (status == LoadMoreStatus.fail) { return Container( child: Text(text), ); } if (status == LoadMoreStatus.idle) { return Text(text); } if (status == LoadMoreStatus.loading) { return Container( alignment: Alignment.center, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ SizedBox( width: _loadmoreIndicatorSize, height: _loadmoreIndicatorSize, child: CircularProgressIndicator( backgroundColor: Colors.blue, ), ), Padding( padding: const EdgeInsets.all(8.0), child: Text(text), ), ], ), ); } if (status == LoadMoreStatus.nomore) { return Text(text); } return Text(text); } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
My load more is loading all the data at once even if I have three different request bringing data at different time.
The text was updated successfully, but these errors were encountered: