Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

ViewModelの責務について #19

Open
YumNumm opened this issue Nov 16, 2022 · 0 comments
Open

ViewModelの責務について #19

YumNumm opened this issue Nov 16, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@YumNumm
Copy link
Owner

YumNumm commented Nov 16, 2022

問題

  • ViewModel層で処理すべき実装がView層でされている
    onNotification: (notification) {
    // 検索結果を取得していない場合・検索結果がない場合は
    // 何もしない
    if (!data.hasValue) {
    return false;
    }
    final scrollPosition = notification.metrics.pixels /
    notification.metrics.maxScrollExtent;
    if (scrollPosition > 0.8 && (data.value!.isNotEmpty)) {
    // 既に検索結果を全て読み込んでいる場合は、
    // 次のページを読み込む処理を行わない
    if (data.value!.length ==
    (ref.read(totalRepositoryCountProvider).value ?? 0)) {
    return false;
    }
    ref
    .read(repositorySearchViewModel.notifier)
    .loadMoreRepositories();
    return true;
    }
    return false;
    },

    itemBuilder: (context, index) {
    if (index == items.length) {
    // InfiniteScroll Indicator
    return const Padding(
    padding: EdgeInsets.symmetric(vertical: 32),
    child: Center(
    child: CircularProgressIndicator.adaptive(),
    ),
    );
    }
    final item = items[index];
    return RepositoryItemWidget(
    item: item,
    term: ref.watch(searchRepositoryNameProvider) ?? '',
    );
    },

参考

@YumNumm YumNumm added the enhancement New feature or request label Nov 16, 2022
@YumNumm YumNumm self-assigned this Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant