-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
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
FeedPage・ページネーション #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントしました
修正は任意です
qiita_app/lib/main.dart
Outdated
QiitaRepository.fetchQiitaItems(); | ||
QiitaRepository.fetchQiitaItems(PaginatedDataTable.defaultRowsPerPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ビルドの度にこのメソッドが実行されているので、削除しちゃってもいいかもしれないです。
qiita_app/lib/pages/feed_page.dart
Outdated
void fetchArticles() async { | ||
// QiitaRepositoryから記事データを非同期で取得 | ||
List<Article> fetchedArticles = await QiitaRepository.fetchQiitaItems(); | ||
// 取得した記事データをステートにセット | ||
setState(() { | ||
articles = fetchedArticles; | ||
}); | ||
if (!isLoading) { | ||
setState(() { | ||
isLoading = true; | ||
}); | ||
List<Article> fetchedArticles = | ||
await QiitaRepository.fetchQiitaItems(currentPage); | ||
setState(() { | ||
articles.addAll(fetchedArticles); | ||
isLoading = false; | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLoading
はこういう風に使うとインデントが深くならずに済みますよ
void fetchArticles() async {
if (isLoading) return;
setState(() {
isLoading = true;
});
List<Article> fetchedArticles =
await QiitaRepository.fetchQiitaItems(currentPage);
setState(() {
articles.addAll(fetchedArticles);
isLoading = false;
});
}
qiita_app/lib/pages/feed_page.dart
Outdated
void _scrollListener() { | ||
if (_scrollController.position.pixels == | ||
_scrollController.position.maxScrollExtent) { | ||
// 最下部にスクロールした時に次のページを読み込む | ||
currentPage++; // 次のページ番号を更新 | ||
fetchArticles(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
難しくて苦戦するポイントですが、しっかり実装できています✨
しかも1日足らずで!
qiita_app/lib/pages/feed_page.dart
Outdated
@override | ||
void dispose() { | ||
_scrollController.dispose(); // スクロールコントローラーを破棄 | ||
super.dispose(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大事です👍
static Future<List<Article>> fetchQiitaItems() async { | ||
final url = Uri.parse('${Urls.qiitaBaseUrl}/items'); | ||
static Future<List<Article>> fetchQiitaItems(int page) async { | ||
final url = Uri.parse('${Urls.qiitaBaseUrl}/items?page=$page'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
引数とページネーションについてしっかり理解できています👍
しっかり修正できています👍 |
LGTMです🎉 何点か気になった箇所があるので下記に記しておきます。 isLoading フラグの制御
|
merged👍 別ブランチで以下のissueにも対応してもらえると! |
概要
FeedPageのページネーションを実装しました。
CLIENT_IDとCLIENT_SECRET
実装した内容
UI
Screen_recording_20240324_185038.webm
動作確認
参考
その他