E/flutter (13373): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 112 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.
class ArticlesList extends StatefulWidget {
@override
_ArticlesListState createState() => _ArticlesListState();
class _ArticlesListState extends State<ArticlesList> {
final _scrollController = ScrollController();
ArticleBloc _articleBloc;
@override
void initState() {
super.initState();
_scrollController.addListener(_onScroll);
_articleBloc = context.bloc<ArticleBloc>();
@override
Widget build(BuildContext context) {
return BlocConsumer<ArticleBloc, ArticleState>(
listener: (context, state) {
if (!state.hasReachedMax && _isBottom) {
_articleBloc.add(Fetch());
builder: (context, state) {
switch (state.status) {
case ArticleStatus.failure:
return const Center(
child: Text("Возникли проблемы с загрузкой 😕"));
case ArticleStatus.success:
if (state.articles.isEmpty) {
return const Center(child: Text('Статей пока нет...'));
return ListView.builder(
physics: BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return index >= state.articles.length
? BottomLoader()
: ArticleCardItem(article: state.articles[index]);
itemCount: state.hasReachedMax
? state.articles.length
: state.articles.length + 1,
controller: _scrollController,
default:
return const Center(child: CircularProgressIndicator());
@override
void dispose() {
_scrollController.dispose();
super.dispose();
void _onScroll() {
if (_isBottom) _articleBloc.add(Fetch());
bool get _isBottom {
final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.offset;
return currentScroll >= (maxScroll * 0.9);
Current:
bool get _isBottom {
final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.offset;
return currentScroll >= (maxScroll * 0.9);
bool get _isBottom {
if (_scrollController.hasClients) {
final maxScroll = _scrollController.position.maxScrollExtent;
final currentScroll = _scrollController.offset;
return currentScroll >= (maxScroll * 0.9);
return false;