mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 00:48:47 +08:00 
			
		
		
		
	 bd7f51f5b6
			
		
	
	bd7f51f5b6
	
	
	
		
			
			This adds a proposal for a new API for flame, the ComponentNotifier.
This API offers the user change notifiers classes that are tied to FlameGame and its components so the user can be notified when a component is added, removed or updated.
This will enable users to:
    Take the benefit of reactive programming inside the game
    Have a simple way of watching certain states from the game, on Flutter Widgets
One important note here is that this proposal does not mean to replace integrations like flame_bloc, but rather provider an simple and out of the box solution, without any need of additional packages, since change notifiers are provided by flutter itself.
Opening this as draft for now to get feedback on the implementation, will write tests and docs once we have the final implementation.
		
	
		
			
				
	
	
		
			71 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:dashbook/dashbook.dart';
 | |
| import 'package:examples/commons/commons.dart';
 | |
| import 'package:examples/stories/components/clip_component_example.dart';
 | |
| import 'package:examples/stories/components/components_notifier_example.dart';
 | |
| import 'package:examples/stories/components/components_notifier_provider_example.dart';
 | |
| import 'package:examples/stories/components/composability_example.dart';
 | |
| import 'package:examples/stories/components/debug_example.dart';
 | |
| import 'package:examples/stories/components/game_in_game_example.dart';
 | |
| import 'package:examples/stories/components/look_at_example.dart';
 | |
| import 'package:examples/stories/components/look_at_smooth_example.dart';
 | |
| import 'package:examples/stories/components/priority_example.dart';
 | |
| import 'package:flame/game.dart';
 | |
| 
 | |
| void addComponentsStories(Dashbook dashbook) {
 | |
|   dashbook.storiesOf('Components')
 | |
|     ..add(
 | |
|       'Composability',
 | |
|       (_) => GameWidget(game: ComposabilityExample()),
 | |
|       codeLink: baseLink('components/composability_example.dart'),
 | |
|       info: ComposabilityExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Priority',
 | |
|       (_) => GameWidget(game: PriorityExample()),
 | |
|       codeLink: baseLink('components/priority_example.dart'),
 | |
|       info: PriorityExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Debug',
 | |
|       (_) => GameWidget(game: DebugExample()),
 | |
|       codeLink: baseLink('components/debug_example.dart'),
 | |
|       info: DebugExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Game-in-game',
 | |
|       (_) => GameWidget(game: GameInGameExample()),
 | |
|       codeLink: baseLink('components/game_in_game_example.dart'),
 | |
|       info: GameInGameExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'ClipComponent',
 | |
|       (context) => GameWidget(game: ClipComponentExample()),
 | |
|       codeLink: baseLink('components/clip_component_example.dart'),
 | |
|       info: ClipComponentExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Look At',
 | |
|       (_) => GameWidget(game: LookAtExample()),
 | |
|       codeLink: baseLink('components/look_at_example.dart'),
 | |
|       info: LookAtExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Look At Smooth',
 | |
|       (_) => GameWidget(game: LookAtSmoothExample()),
 | |
|       codeLink: baseLink('components/look_at_smooth_example.dart'),
 | |
|       info: LookAtExample.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Component Notifier',
 | |
|       (_) => const ComponentsNotifierExampleWidget(),
 | |
|       codeLink: baseLink('components/component_notifier_example.dart'),
 | |
|       info: ComponentsNotifierExampleWidget.description,
 | |
|     )
 | |
|     ..add(
 | |
|       'Component Notifier (with provider)',
 | |
|       (_) => const ComponentsNotifierProviderExampleWidget(),
 | |
|       codeLink: baseLink('components/component_notifier_provider_example.dart'),
 | |
|       info: ComponentsNotifierProviderExampleWidget.description,
 | |
|     );
 | |
| }
 |