Flutter: How many blocs to do? Looking for an architectural advice. I am new to BloC and planning to write an app

Viewed 105

I need an advice concerning an architectural solution. My app has 5 screens that use information from the same JSON file.

  • (1) List of companies,
  • (2) List of companies on the Google Map,
  • (3) Detailed information about a company,
  • (4) Search of a company by name,
  • (5) Comparison of prices provided by each company.

The prices change every minute and can be fetched by a user.

Additionally, I have other screens, that do not depend from this first JSON data:

  • (6) favorites,
  • (7) about project, and
  • (8) one page that shows information from other JSON file.

Also, I keep in mind global variables for whole app such as:

  • language,
  • type of device.

What would you recommend:

1) Make 4 separate blocs for:

  • language and type device
  • 5 screens that depend from the first JSON
  • Favorites
  • One screen that depends from other JSON

2) Make separate bloc for each screen

3) Any other more suitable solution?

Thank you very much in advance!

1 Answers

I'd create a separate bloc for each screen, but only if that screen has a logic. If a screen simply displays some info, like yours (3) Detailed information about a company, then bloc isn't required.

language,

type of device.

These aren't global variables, and can be accessed from BuildContext. For example, you can get the current platform by accessing Theme.of(context).platform

Related