I want to implement Infinite scrolling how to do it… · The Chat Archive
Explore I want to implement Infinite scrolling how to do it , import… Save Share Download ▾ ReportI want to implement Infinite scrolling how to do it , import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:learning/Domain/Entites/novel.dart';
import 'package:learning/Domain/Usecase/get_completed_novels_usecase.dart';
import 'package:learning/Domain/Usecase/get_genres_usecase.dart';
import 'package:learning/Domain/Usecase/get_latest_release_novels_usecase.dart';
import 'package:learning/Domain/Usecase/get_most_popular_novels_usecase.dart';
import 'package:learning/Domain/Usecase/get_novels_details_usecase.dart';
import 'package:learning/Domain/Usecase/get_searched_novels_usecase.dart';
import '../../../Domain/Entites/chapter_content.dart';
import '../../../Domain/Usecase/get_chapter_content_usecase.dart';
import '../../../Domain/Usecase/get_hot_novels_usecase.dart';
part 'novel_state.dart';
class NovelCubit extends Cubit {
final GetCompletedNovelsUsecase getCompletedNovelsUsecase;
final GetChapterContentUsecase getChapterContentUsecase;
final GetGenresUsecase getGenresUsecase;
final GetHotNovelsUsecase getHotNovelsUsecase;
final GetMostPopularNovelsUsecase getMostPopularNovelsUsecase;
final GetLatestReleaseNovelsUsecase getLatestReleaseNovelsUsecase;
final GetSearchedNovelsUsecase searchedNovelsUsecase;
final GetNovelsDetailsUsecase getNovelsDetailsUsecase;
int _currentPageNumber = 1;
List currentNovels = [];
NovelCubit(
this.getChapterContentUsecase,
this.getCompletedNovelsUsecase,
this.getGenresUsecase,
this.getHotNovelsUsecase,
this.getMostPopularNovelsUsecase,
this.getLatestReleaseNovelsUsecase,
this.searchedNovelsUsecase,
this.getNovelsDetailsUsecase,
) : super(
NovelLoading(),
);
Future getCompletedNovels() async {
emit(NovelLoading());
final getCompletedNovelsUsecaseResult =
await getCompletedNovelsUsecase.execute(_currentPageNumber);
getCompletedNovelsUsecaseResult.fold(
(error) => emit(
NovelError(
errorMessage: error.errorMessageError,
),
), (success) {
currentNovels.addAll(success);
emit(NovelSuccessfullyLoaded(currentNovels));
emit(
NovelSuccessfullyLoaded(
currentNovels,
),
);
});
}
Future updatePage() async {
_currentPageNumber++;
await getCompletedNovels();
}
Future getHotNovels(int page) async {
emit(NovelLoading());
final getHotNovelsUsecaseResult = await getHotNovelsUsecase.execute(page);
getHotNovelsUsecaseResult.fold(
(error) => emit(
NovelError(
errorMessage: error.errorMessageError,
),
),
(success) => emit(
NovelSuccessfullyLoaded(
success,
),
),
);
}
Future getNovelsDetails(String id) async {
emit(NovelLoading());
final getNovelsDetailsUsecaseResult =
await getNovelsDetailsUsecase.execute(id);
getNovelsDetailsUsecaseResult.fold(
(error) => emit(
NovelError(
errorMessage: error.errorMessageError,
),
),
(success) => emit(
NovelDaitelsLoaded(
success,
),
),
);
}
Assistant2024-10-04 22:01 UTC Copy response
I want the loading Indicitor to be in the bottom when load new page without make the prevaouse data disapeare
Assistant2024-10-04 22:07 UTC Copy response
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 2 (4 messages)
Language en
Conversation date Oct 4, 2024
Added to archive Nov 16, 2026
ID 01m7h41wndz5fbcr0rmjwzxmszSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: 9377b6255861b7200184b4dcfd20fc80
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
Future getChapterContent(String href) async {
emit(ChapterContentLoading());
final getChapterContentUsecaseResult =
await getChapterContentUsecase.execute(href);
getChapterContentUsecaseResult.fold(
(error) => emit(
ChapterContentError(
errorMessage: error.errorMessageError,
),
),
(success) => emit(
ChapterContentSuccessfullyLoaded(
chapterContent: success,
),
),
);
}
Future getSearchedNovels(String query, int page) async {
emit(NovelLoading());
final getSearchedNovelsUsecaseResult =
await searchedNovelsUsecase.execute(query, page);
getSearchedNovelsUsecaseResult.fold(
(error) => emit(NovelError(errorMessage: error.errorMessageError)),
(success) => emit(
NovelSuccessfullyLoaded(success),
),
);
}
void reverseChapters() {
final novel = (state as NovelDaitelsLoaded).novel;
final reversedNovel = novel.copyWith(
chapters: novel.chapters.reversed.toList(),
);
emit(NovelDaitelsLoaded(reversedNovel));
}
Future getGenres() async {
emit(GenresLoading());
final getGenresUsecaseResult = await getGenresUsecase.execute();
getGenresUsecaseResult.fold(
(error) => emit(
GenresError(
errorMessage: error.errorMessageError,
),
),
(success) => emit(
GenresLoadedSuccessfully(success),
),
);
}
} , import 'dart:developer';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:learning/App/Contanse/app_contanse.dart';
import 'package:learning/Core/Services/services_locator.dart';
import 'package:learning/Core/Utils/size.dart';
import 'package:learning/Domain/Entites/novel.dart';
import 'package:learning/Presentation/Controller/Novel/novel_cubit.dart';
import 'package:learning/Presentation/Resources/Fonts/style_manager.dart';
import 'package:skeletonizer/skeletonizer.dart';
import '../Resources/Colors/color_manger.dart';
import '../Resources/Strings/stings_manager.dart';
import '../Resources/Theme/theme_manager.dart';
import '../Resources/Values/values_manger.dart';
import 'detail_screen.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final containerHeight =
SizeConfig.size.height * 0.5; // 50% of the screen height
final containerWidth =
SizeConfig.size.width * 0.95; // 95% of the screen widt
final ScrollController _scrollController = ScrollController();
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: Theme.of(context).brightness == Brightness.light
? ColorManger.homePageGradiantLight
: ColorManger.homePageGradiantDark,
),
),
child: CustomScrollView(
controller: _scrollController,
slivers: [
SliverToBoxAdapter(
child: BlocBuilder<NovelCubit, NovelState>(
builder: (context, novelState) {
if (novelState is NovelLoading) {
return Skeletonizer(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: SizeConfig.size.height * 0.30,
width: SizeConfig.size.width * 0.45,
decoration: BoxDecoration(
color: Colors.grey[800], // Placeholder for image
borderRadius: BorderRadius.circular(
BorderRadiusManager.b16),
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 8),
height: 20,
width: SizeConfig.size.width * 0.6,
color: Colors.grey[700], // Placeholder for title
),
Container(
height: 16,
width: SizeConfig.size.width * 0.3,
color: Colors.grey[700], // Placeholder for author
),
const SizedBox(height: 5),
Container(
height: 40,
width: SizeConfig.size.width * 0.3,
decoration: BoxDecoration(
color: Colors.grey[800], // Placeholder for button
borderRadius: BorderRadius.circular(
BorderRadiusManager.b19),
),
),
],
),
);
} else if (novelState is NovelSuccessfullyLoaded) {
return SafeArea(
child: CarouselSlider.builder(
itemCount: novelState.novels.length,
itemBuilder: (context, index, realIndex) {
final novel = novelState.novels[index];
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
imageSlider(novel),
novelTitle(novel, context),
authorName(novel, context),
const SizedBox(
height: 5,
),
buttomReadNow(context, novel.id),
],
);
},
options: CarouselOptions(
height: SizeConfig.size.height * 0.65,
autoPlay: true,
enlargeCenterPage: true,
viewportFraction: 0.8,
),
),
);
} else if (novelState is NovelError) {
return Center(
child: Text(novelState.errorMessage),
);
}
return const SizedBox.shrink();
},
),
),
SliverToBoxAdapter(
child: BlocProvider(
create: (_) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getGenres(),
child: BlocBuilder<NovelCubit, NovelState>(
builder: (context, genresState) {
if (genresState is GenresLoading) {
return Skeletonizer(
child: Padding(
padding: const EdgeInsets.only(top: PaddingManger.p24),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
...List.generate(
30,
(_) {
return Container(
margin: const EdgeInsets.only(
left: MarginManger.m8),
height: SizeConfig.size.height * 0.0606,
width: SizeConfig.size.width * 0.2778,
decoration: BoxDecoration(
border: Border.all(),
borderRadius: BorderRadius.circular(
BorderRadiusManager.b8),
color: Colors.grey[900],
));
},
)
],
),
),
),
);
} else if (genresState is GenresLoadedSuccessfully) {
return Padding(
padding: const EdgeInsets.only(top: PaddingManger.p24),
child: SizedBox(
height: SizeConfig.size.height * 0.069,
width: double.infinity,
child: GridView.builder(
scrollDirection: Axis.horizontal,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
mainAxisExtent: SizeConfig.size.width * 0.25,
crossAxisSpacing: 50,
childAspectRatio: 1 / 2,
),
itemCount: genresState.genres.length,
itemBuilder: (context, index) => Container(
margin:
const EdgeInsets.only(left: MarginManger.m8),
height: SizeConfig.size.height * 0.0606,
width: SizeConfig.size.width * 0.2778,
decoration: BoxDecoration(
color: ColorManger.grenresConteinerColor,
border: Border.all(),
borderRadius:
BorderRadius.circular(BorderRadiusManager.b8),
),
child: Center(
child: Text(
style: getTitleMediumStyle(
color: ColorManger.whiteColor),
textAlign: TextAlign.center,
genresState.genres[index],
),
),
),
),
),
);
}
return const SizedBox.shrink();
}),
),
),
SliverToBoxAdapter(
child: BlocProvider(
create: (_) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getCompletedNovels(),
child: BlocBuilder<NovelCubit, NovelState>(
builder: (context, completeNovelState) {
if (completeNovelState is NovelLoading) {
return loadingIndicitor(containerHeight, containerWidth);
} else if (completeNovelState is NovelSuccessfullyLoaded) {
return successResult(containerHeight, containerWidth,
completeNovelState, context);
} else if (completeNovelState is NovelError) {
return errorResult(completeNovelState);
}
return const SizedBox.shrink();
}),
),
),
SliverToBoxAdapter(
child: Container(
height: containerHeight,
width: containerWidth,
decoration: const BoxDecoration(color: Colors.blue),
),
),
],
),
),
);
Container loadingIndicitor(double containerHeight, double containerWidth) {
return Container(
margin: const EdgeInsets.only(top: MarginManger.m24),
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(BorderRadiusManager.b10),
),
height: containerHeight,
width: containerWidth,
child: const Center(
child: CircularProgressIndicator(),
),
);
}
Container errorResult(NovelError completeNovelState) {
return Container(
margin: const EdgeInsets.only(top: MarginManger.m24),
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(BorderRadiusManager.b10),
),
height: SizeConfig.size.height * 0.3,
width: SizeConfig.size.width * 0.6,
child: Center(
child: Text(completeNovelState.errorMessage),
),
);
}
Column successResult(double containerHeight, double containerWidth,
NovelSuccessfullyLoaded completeNovelState, context) {
return Column(
children: [
Container(
height: containerHeight / 8,
width: containerWidth,
margin: const EdgeInsets.only(top: MarginManger.m24),
decoration: BoxDecoration(
color: Colors.black,
border: Border(
top: BorderSide(color: ColorManger.whiteColor),
left: BorderSide(color: ColorManger.whiteColor),
right: BorderSide(color: ColorManger.whiteColor),
),
borderRadius: BorderRadius.circular(BorderRadiusManager.b10),
),
child: const Center(
child: Text(
StingsManager.completedNovels,
),
),
),
Container(
decoration: BoxDecoration(
color: Colors.black,
border: Border(
bottom: BorderSide(color: ColorManger.whiteColor),
left: BorderSide(color: ColorManger.whiteColor),
right: BorderSide(color: ColorManger.whiteColor),
),
borderRadius: BorderRadius.circular(BorderRadiusManager.b10),
),
height: containerHeight,
width: containerWidth,
child: SingleChildScrollView(
child: SizedBox(
height: containerHeight,
width: containerWidth,
child: NotificationListener(
onNotification: (scrollInfo) {
if (scrollInfo.metrics.pixels ==
scrollInfo.metrics.maxScrollExtent &&
scrollInfo is ScrollEndNotification) {
BlocProvider.of(context).updatePage();
}
return true;
},
child: GridView.builder(
physics: const AlwaysScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 5,
childAspectRatio: 0.65,
),
itemCount: completeNovelState.novels.length,
itemBuilder: (context, index) {
return Column(
children: [
Flexible(
child: SizedBox(
height: containerHeight * 0.5,
width: containerWidth / 4,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BlocProvider(
create: (context) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getNovelsDetails(
completeNovelState.novels[index].id),
child: const DetailScreen(),
),
),
);
},
child: Column(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(
BorderRadiusManager.b8),
child: Image.network(AppContanse
.baseImageUrl +
completeNovelState.novels[index].image),
),
Flexible(
child: Text(
completeNovelState.novels[index].title,
maxLines: 2,
style: getLabelSmallStyle(
color: ColorManger.whiteColor),
textAlign: TextAlign.center,
),
)
],
),
),
),
),
],
);
},
),
),
),
),
),
],
);
}
Text authorName(Novel novel, BuildContext context) {
return Text(
novel.author,
style: getLabelLargeStyle(
color: Theme.of(context).brightness == Brightness.light
? ColorManger.authorNamedColorlight
: ColorManger.authorNamedColordark),
);
}
ElevatedButton buttomReadNow(context, id) {
return ElevatedButton(
style: buttonStyle(),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BlocProvider(
create: (context) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getNovelsDetails(id),
child: const DetailScreen(),
),
),
);
},
child: Text(
StingsManager.readNow,
style: getLabelLargeStyle(
color: ColorManger.whiteColor,
),
));
}
Flexible novelTitle(Novel novel, BuildContext context) {
return Flexible(
child: Text(
novel.title,
maxLines: 2,
textAlign: TextAlign.center,
style: getTitleLargeStyle(
color: Theme.of(context).brightness == Brightness.light
? ColorManger.blackColor
: ColorManger.whiteColor,
),
),
);
}
ClipRRect imageSlider(Novel novel) {
return ClipRRect(
borderRadius: BorderRadius.circular(BorderRadiusManager.b16),
child: Container(
height: SizeConfig.size.height * 0.40,
width: SizeConfig.size.width * 0.45,
decoration: const BoxDecoration(),
child: image(AppContanse.baseImageUrl + novel.image),
),
);
}
}
Widget image(String url) {
return Image.network(
url,
fit: BoxFit.fitHeight,
);
}
To implement infinite scrolling in your Flutter app using the BLoC pattern with the current code structure, follow these steps:
1. Set Up the Scroll Controller
You already have a ScrollController in your HomeScreen widget. You'll use it to detect when the user has scrolled to the bottom of the list.
2. Modify NovelCubit for Pagination
Ensure that your NovelCubit can handle loading more data. You've already set up the _currentPageNumber and the currentNovels list. Make sure that your API calls support pagination.
3. Update the HomeScreen Widget
Make sure you're using the ScrollController to listen for scroll events and trigger loading of additional data. You're already wrapping the GridView.builder with a NotificationListener.
Implementation Details
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final containerHeight = SizeConfig.size.height * 0.5;
final containerWidth = SizeConfig.size.width * 0.95;
final ScrollController _scrollController = ScrollController();
// Listen for scroll events on controller
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
BlocProvider.of<NovelCubit>(context).updatePage();
}
});
return Scaffold(
body: BlocProvider(
create: (_) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getCompletedNovels(),
child: BlocBuilder<NovelCubit, NovelState>(
builder: (context, state) {
// Existing implementation...
return CustomScrollView(
controller: _scrollController,
slivers: [
// Other Sliver Widgets...
SliverToBoxAdapter(
child: _buildCompletedNovelsSliver(
containerHeight, containerWidth, context, state),
),
// Other Sliver Widgets...
if (state is NovelLoading) // Add loading indicator at bottom
SliverToBoxAdapter(
child: Center(
child: CircularProgressIndicator(),
),
),
],
);
},
),
),
);
}
Widget _buildCompletedNovelsSliver(double containerHeight,
double containerWidth, BuildContext context, NovelState state) {
// Content generation logic
}
}
Notes
Scroll Event Listener : The ScrollController is used to detect when the user scrolls to the bottom of the ListView. The NovelCubit.updatePage() method is called, which will increment the page number and fetch more novels.
Loading State Handling : The BlocBuilder listens to changes in the NovelState. It's already displaying loading indicators, but ensure that the list is updated properly without resetting it.
API Considerations : Ensure your API supports pagination and that you handle any potential end of data scenarios (when there are no more pages to load).
State Management : Ensure your NovelCubit is properly updating its state and maintaining a list of loaded data (currentNovels) to append new data without losing existing data.
These steps effectively enable infinite scrolling by leveraging the BLoC pattern and Dart/Flutter tools. The key is managing state changes and ensuring smooth user experience when loading more content.
To implement infinite scrolling with a loading indicator at the bottom without making the previous data disappear, you'll need to ensure that your Bloc only updates the state to add data without clearing the previously loaded data. Additionally, you should handle the loading state at the bottom of the list separately. Here's how you can achieve this:
Step-by-Step Implementation
Update the State Management : Ensure that your NovelSuccessfullyLoaded state includes a list of all loaded novels and retains them across new fetches.
Modify the BLoC : Ensure the NovelSuccessfullyLoaded state keeps appending new novels to the currentNovels.
Implement Bottom Loading Indicator : Display a loading indicator at the bottom when new data is loading.
Here's a more detailed approach:
Update the NovelCubit
Ensure that the NovelCubit maintains a list of novels and updates this list as new data is fetched.
class NovelCubit extends Cubit<NovelState> {
// Keep track of loading more state
bool isLoadingMore = false;
// Method to load more novels
Future<void> getCompletedNovels() async {
if (isLoadingMore) return; // Don't fetch if already fetching
emit(NovelLoading());
isLoadingMore = true; // Start fetching
final result = await getCompletedNovelsUsecase.execute(_currentPageNumber);
result.fold(
(error) {
isLoadingMore = false;
emit(NovelError(errorMessage: error.errorMessageError));
},
(novels) {
currentNovels.addAll(novels);
isLoadingMore = false;
emit(NovelSuccessfullyLoaded(currentNovels));
},
);
_currentPageNumber++; // Increment page number
}
}
Modify the HomeScreen Widget
Ensure the loading indicator shows when new data is being fetched.
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final containerHeight = SizeConfig.size.height * 0.5;
final containerWidth = SizeConfig.size.width * 0.95;
final ScrollController _scrollController = ScrollController();
// Listen for scroll events on controller
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
BlocProvider.of<NovelCubit>(context).getCompletedNovels();
}
});
return Scaffold(
body: BlocProvider(
create: (_) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getCompletedNovels(),
child: BlocBuilder<NovelCubit, NovelState>(
builder: (context, state) {
return CustomScrollView(
controller: _scrollController,
slivers: [
// Other Slivers...
SliverToBoxAdapter(
child: _buildCompletedNovels(
containerHeight, containerWidth, context, state),
),
// Other Slivers...
if (BlocProvider.of<NovelCubit>(context).isLoadingMore)
const SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Center(
child: CircularProgressIndicator(),
),
),
),
],
);
},
),
),
);
}
Widget _buildCompletedNovels(double containerHeight, double containerWidth,
BuildContext context, NovelState state) {
if (state is NovelLoading && BlocProvider.of<NovelCubit>(context).currentNovels.isEmpty) {
// Initial loading state
return loadingIndicitor(containerHeight, containerWidth);
} else if (state is NovelError) {
// Show error state
return errorResult(state);
} else if (state is NovelSuccessfullyLoaded || BlocProvider.of<NovelCubit>(context).currentNovels.isNotEmpty) {
// Display list of novels
return successResult(containerHeight, containerWidth,
BlocProvider.of<NovelCubit>(context).currentNovels, context);
}
return const SizedBox.shrink();
}
Widget successResult(double containerHeight, double containerWidth,
List<Novel> novels, BuildContext context) {
// Use novels list
return Column(
children: [
// Other UI elements...
Container(
height: containerHeight,
width: containerWidth,
child: GridView.builder(
physics: const AlwaysScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 5,
childAspectRatio: 0.65,
),
itemCount: novels.length,
itemBuilder: (context, index) {
return Column(
children: [
Flexible(
child: SizedBox(
height: containerHeight * 0.5,
width: containerWidth / 4,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BlocProvider(
create: (context) => NovelCubit(
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
serverLocator(),
)..getNovelsDetails(novels[index].id),
child: const DetailScreen(),
),
),
);
},
child: Column(
children: [
ClipRRect(
borderRadius:
BorderRadius.circular(BorderRadiusManager.b8),
child: Image.network(
AppContanse.baseImageUrl + novels[index].image),
),
Flexible(
child: Text(
novels[index].title,
maxLines: 2,
style: getLabelSmallStyle(
color: ColorManger.whiteColor),
textAlign: TextAlign.center,
),
)
],
),
),
),
),
],
);
},
),
),
],
);
}
}
Explanation
State Management : The NovelSuccessfullyLoaded state maintains a list of all the novels loaded so far, appending new data to it.
Loading Indicator : A loading indicator is shown at the bottom whenever a new page is being loaded, managed by the isLoadingMore state.
Bottom Detection : The ScrollController is used to detect when the user has scrolled to the bottom, triggering the getCompletedNovels() function in the NovelCubit to fetch more data.
This approach ensures that the previous data does not disappear when new data is being fetched, providing seamless infinite scrolling with a bottom loading indicator.
Copy first response
Not yet included in a published release.