FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.75k stars 1.76k forks source link

sample infinite list with provider #12

Closed pratamawijaya closed 5 years ago

pratamawijaya commented 5 years ago

hi, any sample for infinite list with provider ? i have trying to implement provider with your architecture, but get some trouble with infinite list

FilledStacks commented 5 years ago

Hi there.

No I didn't make an example of that. it'll be a normal implementation but the logic will all be in the model.

Have a list in your model with your list items. Track your offset or page in the model, when you call your fetch items future you request with the current page index number. Add the new results into the list, increment the count and call notifyListeners().

What exactly are you having trouble with?


From: Pratama Nur Wijaya notifications@github.com Sent: Thursday, July 4, 2019 2:07:04 PM To: FilledStacks/flutter-tutorials Cc: Subscribed Subject: [FilledStacks/flutter-tutorials] sample infinite list with provider (#12)

hi, any sample for infinite list with provider ? i have trying to implement provider with your architecture, but get some trouble with infinite list

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/FilledStacks/flutter-tutorials/issues/12?email_source=notifications&email_token=AA3M72V43WCR7FAQNU64ZGTP5XRWRA5CNFSM4H5ZGEJKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G5LTN6A, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA3M72TGUVAJ3C56VFV5ZH3P5XRWRANCNFSM4H5ZGEJA.

pratamawijaya commented 5 years ago

my trouble is, how to call, viewmodel at initState(), here my sample code https://github.com/pratamawijaya/Flutter101/blob/master/flutter_project/flutter_news_mvvmprovider/lib/ui/screens/home_screen.dart#L34

when I'm trying to get currentPage, it doesn't increased

FilledStacks commented 5 years ago

firstly, the point of the view model is to move all your business logic out of the view and manage all your state in the model. Your code is not following the architecture, there should be no business logic in your view.

In your scroll listener all you should have is

model.requestNextPageData();

When you reach your max scroll limit.

If you want to call something when the view is initialised use initState. Unfortunately I won't be able to review your code for you. You have to remove all logic from your view file, that's what the model is there for. You can't be managing state in two different places, it'll become too hard to maintain.

pratamawijaya commented 5 years ago

ok thanks for the advice

On Thu, Jul 4, 2019 at 8:21 PM Dane Mackier notifications@github.com wrote:

firstly, the point of the view model is to move all your business logic out of the view and manage all your state in the model. Your code is not following the architecture, there should be no business logic in your view.

In your scroll listener all you should have is

model.requestNextPageData();

When you reach your max scroll limit.

If you want to call something when the view is initialised use initState. Unfortunately I won't be able to review your code for you. You have to remove all logic from your view file, that's what the model is there for. You can't be managing state in two different places, it'll become too hard to maintain.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FilledStacks/flutter-tutorials/issues/12?email_source=notifications&email_token=AASXSD54XLKPDWRIZZVLMSTP5X2PFA5CNFSM4H5ZGEJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZHMZSY#issuecomment-508480715, or mute the thread https://github.com/notifications/unsubscribe-auth/AASXSD5HUIXBOE2YROQ75G3P5X2PFANCNFSM4H5ZGEJA .

--

Pratama Nur Wijaya Mobile Application Developer

twitter: @tama_hk linkedin : http://id.linkedin.com/in/pratamawijaya/ blog : http://pratamawijaya.com