GithubHelp home page GithubHelp logo

movies_app's Issues

Got error when calculate index pass to provider when use CustomScrollView

I got error in this logic handle for load more

final AsyncValue<Timeline> currentTimelineFromIndex = ref
                      .watch(testTimelineFutureProvider(idx ~/ 20))
                      .whenData((pageData) => pageData.results[idx % 20]);

I try to debug with the code at below sometime the index is null when scroll at itemCount = 20 -> 40 -> 60 ...

Screen Shot 2022-11-01 at 20 20 37

Could you please help me resolve it?

Screen Shot 2022-11-01 at 20 04 03

import 'package:app/enums/constant.dart';
import 'package:app/hooks/hook_providers.dart';
import 'package:app/hooks/timeline/timeline_count_provider.dart';
import 'package:app/hooks/timeline/timeline_scroll_controller_provider.dart';
import 'package:app/models/timeline/timeline.dart';
import 'package:app/ui/screens/timeline/timeline_list_item.dart';
import 'package:app/ui/widgets/common/common_sliver_app_bar.dart';
import 'package:app/ui/widgets/loading/icon_loading.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class TimelineTwoScreen extends HookConsumerWidget {
  final bool isLoading = false;
  const TimelineTwoScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final timelineCount = ref.watch(timelineCountProvider);
    final scrollController = ref.watch(timelineScrollControllerProvider);

    return timelineCount.when(
      loading: () => Container(
        color: Colors.white,
        child: const Center(child: IconLoading()),
      ),
      error: (err, stack) {
        return Scaffold(
          appBar: AppBar(title: const Text('Error')),
          body: Center(
            child: Text('$err'),
          ),
        );
      },
      data: (countItem) {
        return CustomScrollView(
          controller: scrollController,
          slivers: [
            const CommonSliverAppBar(title: ScreenName.timeLine),
            CupertinoSliverRefreshControl(
              onRefresh: () async {
                ref.refresh(timelineFutureProvider(0).future);
              },
              refreshTriggerPullDistance: 150,
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate(
                childCount: countItem,
                (context, idx) {
                  final AsyncValue<Timeline> currentTimelineFromIndex = ref
                      .watch(testTimelineFutureProvider(idx ~/ 20))
                      .whenData((pageData) => pageData.results[idx % 20]);

                  print(
                      'From index: ${currentTimelineFromIndex.asData?.value}');

                  return ProviderScope(
                    overrides: [
                      currentTimelineProvider
                          .overrideWithValue(currentTimelineFromIndex)
                    ],
                    child: const TimelineListItem(),
                  );
                },
              ),
            ),
          ],
        );
      },
    );
  }
}

can you explain currentPopularPersonProvider

what is the purpose of this one?

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:movies_app/features/people/models/person.dart';

final currentPopularPersonProvider = Provider<AsyncValue<Person>>((ref) {
  throw UnimplementedError();
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.