flutterdartflame

What is the purpose and significance of the Flame Provider?


I am reading the source code of Flame.

It seems that Flame has its own Provider, separate from those provided by https://pub.dev/packages/provider and https://riverpod.dev/.

Definition: https://github.com/flame-engine/flame/blob/fabbf928d04a47693aeabd1386fe89fbe179ffa7/packages/flame/lib/src/effects/provider_interfaces.dart#L71

/// Interface for a component that can be affected by size effects.
abstract class SizeProvider extends ReadOnlySizeProvider {
  set size(Vector2 value);
}

Usage: https://github.com/flame-engine/flame/blob/fabbf928d04a47693aeabd1386fe89fbe179ffa7/packages/flame/lib/src/geometry/circle_component.dart#L10

class CircleComponent extends ShapeComponent implements SizeProvider {
  ...
}

/// Interface for a component that can be affected by size effects.

It says "Interface for a component that can be affected by size effects," but I don't quite understand what it means.

For example:

These are hints when reading the code, but what does the Provider in this case suggest or what is its purpose?

The code itself has only a simple signature: set size(Vector2 value); So, I couldn't understand how it is used or what its purpose is.

I'm not very good at reading source code for abstract classes. I believe there should be code that implements this method, but I haven't been able to find it. If I could locate the implementation, I think I would understand it better. Again, as you can see, I am not good at reading abstract classes because I am not good at finding all the code in the project to understand them(I can't find its implementation this time).


Solution

  • The providers inside of Flame has nothing to do with the Provider package. The Flame classes named providers are just interfaces used internally to make sure that you can use different functionality on multiple different classes implementing those providers, for example the SizeEffect can be used on anything that implements the SizeProvider.

    Most of the time you don't have to care about these providers, they are just internal implementation details of Flame. They are exposed if you want to create classes that aren't following our opinionated way of doing things, but you rarely do.