I am using a scroll controller to detect when the user scrolls to the bottom of the screen the load more items(the load items code is emitted for briefness). However when the event is fired this error is throw and i believe it has something to do with the scroll controller.
The following ArgumentError was thrown while dispatching notifications for ScrollController:
Invalid argument (message): Must be a String: null
When the exception was thrown, this was the stack:
#0 log (dart:developer-patch/developer.dart:38:5)
#1 SellerProductService.moreProducts (package:sakaHapa/services/seller_product_service.dart:211:5)
#2 _BuyerSubCategoryPageState.loadMore(package:flutter/src/foundation/change_notifier.dart:308:24)
#5 ChangeNotifier.notifyListeners
#23 PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:286:5)
#24 _beginFrame (dart:ui/hooks.dart:104:31)
(elided 3 frames from dart:async)
The ScrollController sending notification was:
Here is the code i think is relevant to the issue,
class _BuyerSubCategoryPageState extends State<BuyerSubCategoryPage> {
final ScrollController _sC = ScrollController();
DocumentSnapshot _lastPaginationDoc;
List<SellerProduct> _products = [];
bool _loadingMore = false;
double loaderContainerHeight = 0;
// ignore: close_sinks
StreamController<List<SellerProduct>> _streamController =
StreamController<List<SellerProduct>>.broadcast();
void dispose() {
super.dispose();
_streamController.close();
_sC.dispose();
}
@override
void initState() {
super.initState();
_sC.addListener(() {
if (_sC.position.atEdge) {
if (_sC.position.pixels == _sC.position.maxScrollExtent) {
loadMore();
}
}
});
}
void loadMore() {
if (_lastPaginationDoc != null) {
if (mounted) {
setState(() => _loadingMore = true);
/// some other code here
Future.delayed(Duration(seconds: 1), () {
setState(() => _loadingMore = false);
});
}
}
}
...some other code...
Container(
color: AppColors.offWhite,
child: GridView.builder(
physics: ScrollPhysics(),
controller:_sC,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.75,
mainAxisSpacing: 2,
crossAxisSpacing: 2),
itemCount: posts.length + 1,
itemBuilder: (context, index) {
if (index == posts.length) {
if (loadMore) {
return Center(child: NetworkLoader.progressIndicator);
} else {
return Container();
}
}
return SellerProductTile(
product: posts[index],
);
}),
);