Skip to content

Commit

Permalink
fix issue with refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
ksh-b committed Mar 24, 2024
1 parent 7bc42d5 commit 0e87ba8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
5 changes: 1 addition & 4 deletions lib/pages/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class _FeedPageState extends State<FeedPage>
List<NewsArticle> newsArticles = [];
ArticleProvider articleProvider = ArticleProvider();
TextEditingController searchController = TextEditingController();
bool isLoading = false;
double loadProgress = 0;
int page = 1;
HashMap<int, dynamic> subscriptionPage = HashMap();

@override
Expand All @@ -43,7 +40,7 @@ class _FeedPageState extends State<FeedPage>
],
),
body: FutureBuilder(
future: articleProvider.loadPage(page, query: null),
future: articleProvider.loadPage(1, query: null),
builder: (context, snapshot) {
if (snapshot.hasData) {
return FeedPageBuilder(null, snapshot.data!);
Expand Down
13 changes: 3 additions & 10 deletions lib/pages/feed_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class _FeedPageBuilderState extends State<FeedPageBuilder> {
late List<NewsArticle> newsArticles;
late ArticleProvider articleProvider;
late bool isLoading;
late double loadProgress;
late int page;
late GlobalKey<RefreshIndicatorState> _refreshIndicatorKey;

Expand All @@ -33,7 +32,6 @@ class _FeedPageBuilderState extends State<FeedPageBuilder> {
});
articleProvider = ArticleProvider();
isLoading = false;
loadProgress = 0;
page = 1;
_refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
}
Expand All @@ -42,11 +40,10 @@ class _FeedPageBuilderState extends State<FeedPageBuilder> {
Widget build(BuildContext context) {
return RefreshIndicator(
key: _refreshIndicatorKey,
strokeWidth: 4.0,
onRefresh: () async {
setState(() {
newsArticles = [];
page = 1;
page = 0;
isLoading = true;
});
loadMore();
Expand All @@ -60,9 +57,7 @@ class _FeedPageBuilderState extends State<FeedPageBuilder> {
itemBuilder: (context, index) {
if (index == 0) {
return isLoading
? LinearProgressIndicator(
value: loadProgress,
)
? LinearProgressIndicator()
: SizedBox.shrink();
}
if (index - 1 < newsArticles.length) {
Expand Down Expand Up @@ -244,9 +239,7 @@ class ArticleThumbnail extends StatelessWidget {
SizedBox(
height: 200,
),
LinearProgressIndicator(
value: progress.progress,
)
LinearProgressIndicator()
]),
errorWidget: (context, url, error) {
return SizedBox.shrink();
Expand Down
4 changes: 1 addition & 3 deletions lib/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class _SearchResultsPageState extends State<SearchResultsPage> {
List<NewsArticle> newsArticles = [];
ArticleProvider articleProvider = ArticleProvider();
bool isLoading = false;
double loadProgress = 0;
int page = 1;

@override
void initState() {
Expand All @@ -30,7 +28,7 @@ class _SearchResultsPageState extends State<SearchResultsPage> {
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: articleProvider.loadPage(page, query: widget.query),
future: articleProvider.loadPage(1, query: widget.query),
builder: (context, snapshot) {
if (snapshot.hasData) {
return FeedPageBuilder(widget.query, snapshot.data!);
Expand Down

0 comments on commit 0e87ba8

Please sign in to comment.