Git Product home page Git Product logo

Comments (2)

harchani-ritik avatar harchani-ritik commented on May 24, 2024 1

Nice @rj-since-2000👏🏻. So you can replace all "consumer" usages with "Provider" wherever necessary and properly test all the functionalities once from your side too before pushing the changes.

from rutorrent-flutter.

rj-since-2000 avatar rj-since-2000 commented on May 24, 2024

@harchani-ritik Probably yes because the switch is actually present in the main screen, so we only need to refresh the main screen and the torrents list on toggle switch. Rest of the widgets can use Provider when they come in focus.

Actually after more research, I realised why do we even need a Consumer in the main screen. Let's try to analyse -

There are three providers - Api, GeneralFeatures and Mode

*(Api does not even extend ChangeNotifierProvider)
Api is used in -

'api.username'
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => MainScreen())); is already calling the MainScreen to refresh on switching between accounts in the drawer. Thus it doesn't need a consumer to update in the UI.

'_getAccountsList(api, modeTheme, general)' in Drawer
Same as above

if (_currentIndex == 0) { showModalBottomSheet( isScrollControlled: true, context: context, builder: (BuildContext bc) { return AddBottomSheet( api: api, apiRequest: (url) { ApiRequests.addTorrent(api, url); }, dialogHint: 'Enter Torrent Url', ); }, ); } else { showModalBottomSheet( isScrollControlled: true, context: context, builder: (BuildContext bc) { return AddBottomSheet( apiRequest: (url) async { await ApiRequests.addRSS(api, url); setState(() {}); }, dialogHint: 'Enter Rss Url', ); }, ); }
Same as above

Now the GeneralFeatures -

It is used inside Drawer

'_getAccountsList(api, modeTheme, general)'
This just needs to pass provider of GeneralFeatures, so instead we can just pass provider. No need of Consumer.

'general.filterTileList' and 'general.listOfLabels'
These functions return data which isn't part of a Stream or any automatic change. Provider will work here.

'general.pageController'
This returns a controller defined in GeneralFeatures so it does not need a Consumer.

'general.pageController.jumpToPage(index)'
Same as above

Only the HomePage needs to be inside Consumer of GeneralFeatures because it has TorrentLists which is already inside a Consumer.
The DownloadsPage only needs homeDirectory to get the list of files. No need of Consumer.
RSSFeeds is already inside a Consumer it needs.
RSSFilterDetails just uses - rssFilters = await ApiRequests.getRSSFilters(Provider.of<Api>(context, listen: false)); so it also doesn't needs a Consumer in the tree root.

I tried debugging using a simple print('widget tree updated') inside the root widget of the main screen and with two providers(Mode and GeneralFeatures) and one Api class inside as it is now in the codebase, the print was being executed multiple times per second which is highly inefficient.

FUN FACT - I tried removing all the three Consumer in the root of the MainScreen and the app was working all fine with all updates in the torrent list, account change, account deletion, list sort, mode change, etc.

from rutorrent-flutter.

Related Issues (20)

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.