mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-31 07:26:09 +00:00 
			
		
		
		
	BloC
This commit is contained in:
		
							parent
							
								
									0bb1ce43b1
								
							
						
					
					
						commit
						b758deab1a
					
				
					 4 changed files with 383 additions and 76 deletions
				
			
		|  | @ -0,0 +1,228 @@ | ||||||
|  | import 'package:aidedejeu_flutter/database.dart'; | ||||||
|  | import 'package:aidedejeu_flutter/models/items.dart'; | ||||||
|  | import 'package:bloc/bloc.dart'; | ||||||
|  | import 'package:equatable/equatable.dart'; | ||||||
|  | import 'package:flutter/cupertino.dart'; | ||||||
|  | 
 | ||||||
|  | class PlayerCharacterState { | ||||||
|  |   final BuildContext context; | ||||||
|  | 
 | ||||||
|  |   PlayerCharacterState({ | ||||||
|  |     this.context, | ||||||
|  |     this.race, | ||||||
|  |     this.races, | ||||||
|  |     this.subRace, | ||||||
|  |     this.subRaces, | ||||||
|  |     this.background, | ||||||
|  |     this.backgrounds, | ||||||
|  |     this.subBackground, | ||||||
|  |     this.subBackgrounds, | ||||||
|  |   }) {} | ||||||
|  | 
 | ||||||
|  |   PlayerCharacterState copyWith({ | ||||||
|  |     BuildContext context, | ||||||
|  |     RaceItem race, | ||||||
|  |     List<RaceItem> races, | ||||||
|  |     SubRaceItem subRace, | ||||||
|  |     List<SubRaceItem> subRaces, | ||||||
|  |     BackgroundItem background, | ||||||
|  |     List<BackgroundItem> backgrounds, | ||||||
|  |     SubBackgroundItem subBackground, | ||||||
|  |     List<SubBackgroundItem> subBackgrounds, | ||||||
|  |   }) { | ||||||
|  |     return PlayerCharacterState( | ||||||
|  |       context: context ?? this.context, | ||||||
|  |       race: race ?? this.race, | ||||||
|  |       races: races ?? this.races, | ||||||
|  |       subRace: subRace ?? this.subRace, | ||||||
|  |       subRaces: subRaces ?? this.subRaces, | ||||||
|  |       background: background ?? this.background, | ||||||
|  |       backgrounds: backgrounds ?? this.backgrounds, | ||||||
|  |       subBackground: subBackground ?? this.subBackground, | ||||||
|  |       subBackgrounds: subBackgrounds ?? this.subBackgrounds, | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   RaceItem race; | ||||||
|  |   SubRaceItem subRace; | ||||||
|  |   List<RaceItem> races; | ||||||
|  |   List<SubRaceItem> subRaces; | ||||||
|  | 
 | ||||||
|  |   BackgroundItem background; | ||||||
|  |   SubBackgroundItem subBackground; | ||||||
|  |   List<BackgroundItem> backgrounds; | ||||||
|  |   List<SubBackgroundItem> subBackgrounds; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => [ | ||||||
|  |         race, | ||||||
|  |         subRace, | ||||||
|  |         races, | ||||||
|  |         subRaces, | ||||||
|  |         background, | ||||||
|  |         subBackground, | ||||||
|  |         backgrounds, | ||||||
|  |         subBackgrounds | ||||||
|  |       ]; | ||||||
|  | 
 | ||||||
|  |   Future<void> initRaces() async { | ||||||
|  |     print("initRaces"); | ||||||
|  |     var races = await loadRaces(context); | ||||||
|  |     this.races = races.toList(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> initSubRaces(RaceItem race) async { | ||||||
|  |     print("initSubRaces"); | ||||||
|  |     var subRaces = await loadSubRaces(context, race); | ||||||
|  |     this.subRaces = subRaces; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> initBackgrounds() async { | ||||||
|  |     print("initBackgrounds"); | ||||||
|  |     var backgrounds = await loadBackgrounds(context); | ||||||
|  |     this.backgrounds = backgrounds; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> initSubBackgrounds(BackgroundItem background) async { | ||||||
|  |     print("initSubBackgrounds"); | ||||||
|  |     var subBackgrounds = await loadSubBackgrounds(context, background); | ||||||
|  |     this.subBackgrounds = subBackgrounds; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   // setters | ||||||
|  | 
 | ||||||
|  |   Future<void> setRace(RaceItem race) async { | ||||||
|  |     this.race = race; | ||||||
|  |     this.subRace = null; | ||||||
|  |     this.subRaces = null; | ||||||
|  |     await initSubRaces(race); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> setSubRace(SubRaceItem subRace) async { | ||||||
|  |     this.subRace = subRace; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> setBackground(BackgroundItem background) async { | ||||||
|  |     this.background = background; | ||||||
|  |     this.subBackground = null; | ||||||
|  |     this.subBackgrounds = null; | ||||||
|  |     await initSubBackgrounds(background); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Future<void> setSubBackground(SubBackgroundItem subBackground) async { | ||||||
|  |     this.subBackground = subBackground; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | abstract class PlayerCharacterEvent extends Equatable {} | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  | class RacesEvent extends PlayerCharacterEvent { | ||||||
|  |   List<RaceItem> races; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => [races]; | ||||||
|  | } | ||||||
|  | */ | ||||||
|  | class RaceEvent extends PlayerCharacterEvent { | ||||||
|  |   RaceItem race; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => [race]; | ||||||
|  | 
 | ||||||
|  |   RaceEvent(RaceItem race) { | ||||||
|  |     this.race = race; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class SubRaceEvent extends PlayerCharacterEvent { | ||||||
|  |   SubRaceItem subRace; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => [subRace]; | ||||||
|  | 
 | ||||||
|  |   SubRaceEvent(SubRaceItem subRace) { | ||||||
|  |     this.subRace = subRace; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class SetItemEvent<T> extends PlayerCharacterEvent { | ||||||
|  |   T item; | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => [item]; | ||||||
|  | 
 | ||||||
|  |   SetItemEvent(T item) { | ||||||
|  |     this.item = item; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class BackgroundEvent extends SetItemEvent<BackgroundItem> { | ||||||
|  |   BackgroundEvent(BackgroundItem item) : super(item); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class SubBackgroundEvent extends SetItemEvent<SubBackgroundItem> { | ||||||
|  |   SubBackgroundEvent(SubBackgroundItem item) : super(item); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | class LoadEvent extends PlayerCharacterEvent { | ||||||
|  |   @override | ||||||
|  |   List<Object> get props => []; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | //enum PlayerCharacterEvent { setRace, setSubRace, } | ||||||
|  | class PlayerCharacterBloc | ||||||
|  |     extends Bloc<PlayerCharacterEvent, PlayerCharacterState> { | ||||||
|  |   BuildContext context; | ||||||
|  | 
 | ||||||
|  |   PlayerCharacterBloc(BuildContext context) { | ||||||
|  |     this.context = context; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   PlayerCharacterState get initialState => PlayerCharacterState(context: context); | ||||||
|  | 
 | ||||||
|  |   @override | ||||||
|  |   Stream<PlayerCharacterState> mapEventToState( | ||||||
|  |       PlayerCharacterEvent event) async* { | ||||||
|  |     if (event is RaceEvent) { | ||||||
|  |       yield* _mapRaceEventToState(event); | ||||||
|  |     } else if (event is SubRaceEvent) { | ||||||
|  |       yield* _mapSubRaceEventToState(event); | ||||||
|  |     } else if (event is BackgroundEvent) { | ||||||
|  |       yield* _mapBackgroundEventToState(event); | ||||||
|  |     } else if (event is SubBackgroundEvent) { | ||||||
|  |       yield* _mapSubBackgroundEventToState(event); | ||||||
|  |     } else if (event is LoadEvent) { | ||||||
|  |       final currentState = state.copyWith(); // state; | ||||||
|  |       await currentState.initRaces(); | ||||||
|  |       await currentState.initBackgrounds(); | ||||||
|  |       yield currentState; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |   } | ||||||
|  |   Stream<PlayerCharacterState> _mapRaceEventToState( | ||||||
|  |       RaceEvent event) async* { | ||||||
|  |     final currentState = state.copyWith(); | ||||||
|  |     await currentState.setRace(event.race); | ||||||
|  |     yield currentState; | ||||||
|  |   } | ||||||
|  |   Stream<PlayerCharacterState> _mapSubRaceEventToState( | ||||||
|  |       SubRaceEvent event) async* { | ||||||
|  |     final currentState = state.copyWith(); | ||||||
|  |     await currentState.setSubRace(event.subRace); | ||||||
|  |     yield currentState; | ||||||
|  |   } | ||||||
|  |   Stream<PlayerCharacterState> _mapBackgroundEventToState( | ||||||
|  |       BackgroundEvent event) async* { | ||||||
|  |     final currentState = state.copyWith(); | ||||||
|  |     await currentState.setBackground(event.item); | ||||||
|  |     yield currentState; | ||||||
|  |   } | ||||||
|  |   Stream<PlayerCharacterState> _mapSubBackgroundEventToState( | ||||||
|  |       SubBackgroundEvent event) async* { | ||||||
|  |     final currentState = state.copyWith(); | ||||||
|  |     await currentState.setSubBackground(event.item); | ||||||
|  |     yield currentState; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -1,21 +1,24 @@ | ||||||
|  | import 'package:aidedejeu_flutter/blocs/player_character/player_character_bloc.dart'; | ||||||
| import 'package:aidedejeu_flutter/database.dart'; | import 'package:aidedejeu_flutter/database.dart'; | ||||||
| import 'package:aidedejeu_flutter/localization.dart'; | import 'package:aidedejeu_flutter/localization.dart'; | ||||||
| import 'package:aidedejeu_flutter/models/items.dart'; | import 'package:aidedejeu_flutter/models/items.dart'; | ||||||
| import 'package:aidedejeu_flutter/theme.dart'; | import 'package:aidedejeu_flutter/theme.dart'; | ||||||
| import 'package:aidedejeu_flutter/widgets/library.dart'; | import 'package:aidedejeu_flutter/widgets/library.dart'; | ||||||
|  | import 'package:bloc/bloc.dart'; | ||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
|  | import 'package:flutter_bloc/flutter_bloc.dart'; | ||||||
| import 'package:flutter_markdown/flutter_markdown.dart'; | import 'package:flutter_markdown/flutter_markdown.dart'; | ||||||
|  | import 'package:equatable/equatable.dart'; | ||||||
| 
 | 
 | ||||||
| class PCEditorPage extends StatefulWidget { | class PCEditorPage extends StatelessWidget { | ||||||
|   PCEditorPage({Key key}) : super(key: key); |   // StatefulWidget { | ||||||
|  | /*  PCEditorPage({Key key}) : super(key: key); | ||||||
| 
 | 
 | ||||||
|   @override |   @override | ||||||
|   State<StatefulWidget> createState() => _PCEditorPageState(); |   State<StatefulWidget> createState() => _PCEditorPageState(); | ||||||
| } | }*/ | ||||||
| 
 | /* | ||||||
| class _PCEditorPageState extends State<PCEditorPage> { | class PCEditorViewModel { | ||||||
|   MarkdownStyleSheet styleSheet; |  | ||||||
| 
 |  | ||||||
|   RaceItem _race; |   RaceItem _race; | ||||||
|   SubRaceItem _subRace; |   SubRaceItem _subRace; | ||||||
|   List<RaceItem> _races; |   List<RaceItem> _races; | ||||||
|  | @ -26,55 +29,45 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|   List<BackgroundItem> _backgrounds; |   List<BackgroundItem> _backgrounds; | ||||||
|   List<SubBackgroundItem> _subBackgrounds; |   List<SubBackgroundItem> _subBackgrounds; | ||||||
| 
 | 
 | ||||||
|   // inits |   _PCEditorPageState state; | ||||||
| 
 |   BuildContext context; | ||||||
|   @override |   PCEditorViewModel(_PCEditorPageState state, BuildContext context) { | ||||||
|   void initState() { |     this.state = state; | ||||||
|     super.initState(); |     this.context = context; | ||||||
|     _initRaces(); |  | ||||||
|     _initBackgrounds(); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   @protected |  | ||||||
|   @mustCallSuper |  | ||||||
|   void didChangeDependencies() { |  | ||||||
|     super.didChangeDependencies(); |  | ||||||
|     styleSheet = mainMarkdownStyleSheet(context); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _initRaces() async { |   void _initRaces() async { | ||||||
|     var races = await loadRaces(context); |     var races = await loadRaces(context); | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       _races = races.toList(); |       _races = races.toList(); | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _initSubRaces(RaceItem race) async { |   void _initSubRaces(RaceItem race) async { | ||||||
|     var subRaces = await loadSubRaces(context, race); |     var subRaces = await loadSubRaces(context, race); | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       _subRaces = subRaces; |       _subRaces = subRaces; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _initBackgrounds() async { |   void _initBackgrounds() async { | ||||||
|     var backgrounds = await loadBackgrounds(context); |     var backgrounds = await loadBackgrounds(context); | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       _backgrounds = backgrounds; |       _backgrounds = backgrounds; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _initSubBackgrounds(BackgroundItem background) async { |   void _initSubBackgrounds(BackgroundItem background) async { | ||||||
|     var subBackgrounds = await loadSubBackgrounds(context, background); |     var subBackgrounds = await loadSubBackgrounds(context, background); | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       _subBackgrounds = |       _subBackgrounds = subBackgrounds; | ||||||
|           subBackgrounds; |  | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // setters |   // setters | ||||||
| 
 | 
 | ||||||
|   void _setRace(RaceItem race) { |   void _setRace(RaceItem race) { | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       this._race = race; |       this._race = race; | ||||||
|       this._subRace = null; |       this._subRace = null; | ||||||
|       this._subRaces = null; |       this._subRaces = null; | ||||||
|  | @ -83,13 +76,13 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _setSubRace(SubRaceItem subRace) { |   void _setSubRace(SubRaceItem subRace) { | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       this._subRace = subRace; |       this._subRace = subRace; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _setBackground(BackgroundItem background) { |   void _setBackground(BackgroundItem background) { | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       this._background = background; |       this._background = background; | ||||||
|       this._subBackground = null; |       this._subBackground = null; | ||||||
|       this._subBackgrounds = null; |       this._subBackgrounds = null; | ||||||
|  | @ -98,14 +91,41 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   void _setSubBackground(SubBackgroundItem subBackground) { |   void _setSubBackground(SubBackgroundItem subBackground) { | ||||||
|     setState(() { |     state.setState(() { | ||||||
|       this._subBackground = subBackground; |       this._subBackground = subBackground; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | //class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|  |   MarkdownStyleSheet styleSheet; | ||||||
|  | 
 | ||||||
|  |   //PCEditorViewModel vm; | ||||||
|  |   // inits | ||||||
|  | /* | ||||||
|  |   @override | ||||||
|  |   void initState() { | ||||||
|  |     super.initState(); | ||||||
|  |     //vm = PCEditorViewModel(this, context); | ||||||
|  |     //vm._initRaces(); | ||||||
|  |     //vm._initBackgrounds(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @protected | ||||||
|  |   @mustCallSuper | ||||||
|  |   void didChangeDependencies() { | ||||||
|  |     super.didChangeDependencies(); | ||||||
|  |     styleSheet = mainMarkdownStyleSheet(context); | ||||||
|  |   } | ||||||
|  | */ | ||||||
|   // widgets generics |   // widgets generics | ||||||
| 
 | 
 | ||||||
|   Widget _buildMarkdown(String markdown) { |   Widget _buildMarkdown( | ||||||
|  |       BuildContext context, PlayerCharacterState state, String markdown) { | ||||||
|     return MarkdownBody( |     return MarkdownBody( | ||||||
|       data: markdown ?? "", |       data: markdown ?? "", | ||||||
|       styleSheet: styleSheet, |       styleSheet: styleSheet, | ||||||
|  | @ -116,7 +136,8 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildSubTitle(String title) { |   Widget _buildSubTitle( | ||||||
|  |       BuildContext context, PlayerCharacterState state, String title) { | ||||||
|     return Text(title, |     return Text(title, | ||||||
|         style: TextStyle( |         style: TextStyle( | ||||||
|           fontSize: 16, |           fontSize: 16, | ||||||
|  | @ -125,6 +146,7 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildItemsWidget<T extends Item>( |   Widget _buildItemsWidget<T extends Item>( | ||||||
|  |       BuildContext context, PlayerCharacterState state, | ||||||
|       {String hintText, |       {String hintText, | ||||||
|       List<T> items, |       List<T> items, | ||||||
|       T selectedItem, |       T selectedItem, | ||||||
|  | @ -148,80 +170,111 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
| 
 | 
 | ||||||
|   // widgets specifics |   // widgets specifics | ||||||
| 
 | 
 | ||||||
|   Widget _buildRacesWidget() { |   Widget _buildRacesWidget(BuildContext context, PlayerCharacterState state) { | ||||||
|     return _buildItemsWidget<RaceItem>( |     return _buildItemsWidget<RaceItem>( | ||||||
|  |       context, | ||||||
|  |       state, | ||||||
|       hintText: "Race", |       hintText: "Race", | ||||||
|       items: _races, |       items: state.races, | ||||||
|       selectedItem: _race, |       selectedItem: state.race, | ||||||
|       onChanged: (value) { |       onChanged: (value) { | ||||||
|         _setRace(value); |         //state.setRace(value); | ||||||
|  |         BlocProvider.of<PlayerCharacterBloc>(context).add(RaceEvent(value)); | ||||||
|       }, |       }, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildSubRacesWidget() { |   Widget _buildSubRacesWidget( | ||||||
|     return _subRaces != null |       BuildContext context, PlayerCharacterState state) { | ||||||
|  |     return state.subRaces != null | ||||||
|         ? _buildItemsWidget<SubRaceItem>( |         ? _buildItemsWidget<SubRaceItem>( | ||||||
|  |             context, | ||||||
|  |             state, | ||||||
|             hintText: "Variante", |             hintText: "Variante", | ||||||
|             items: _subRaces, |             items: state.subRaces, | ||||||
|             selectedItem: _subRace, |             selectedItem: state.subRace, | ||||||
|             onChanged: (value) { |             onChanged: (value) { | ||||||
|               _setSubRace(value); |               //state.setSubRace(value); | ||||||
|  |               BlocProvider.of<PlayerCharacterBloc>(context) | ||||||
|  |                   .add(SubRaceEvent(value)); | ||||||
|             }, |             }, | ||||||
|           ) |           ) | ||||||
|         : SizedBox.shrink(); |         : SizedBox.shrink(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildRaceDetailsWidget() { |   Widget _buildRaceDetailsWidget( | ||||||
|     return _race != null |       BuildContext context, PlayerCharacterState state) { | ||||||
|  |     return state.race != null | ||||||
|         ? Column( |         ? Column( | ||||||
|             crossAxisAlignment: CrossAxisAlignment.start, |             crossAxisAlignment: CrossAxisAlignment.start, | ||||||
|             children: [ |             children: [ | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceAbilityScoreIncrease), |               _buildSubTitle(context, state, | ||||||
|               _buildMarkdown(_race?.abilityScoreIncrease), |                   AppLocalizations.of(context).raceAbilityScoreIncrease), | ||||||
|               _buildMarkdown(_subRace?.abilityScoreIncrease), |               _buildMarkdown(context, state, state.race?.abilityScoreIncrease), | ||||||
|  |               _buildMarkdown( | ||||||
|  |                   context, state, state.subRace?.abilityScoreIncrease), | ||||||
|               Text(""), |               Text(""), | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceAge), |               _buildSubTitle( | ||||||
|               _buildMarkdown(_race?.age), |                   context, state, AppLocalizations.of(context).raceAge), | ||||||
|  |               _buildMarkdown(context, state, state.race?.age), | ||||||
|               Text(""), |               Text(""), | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceAlignment), |               _buildSubTitle( | ||||||
|               _buildMarkdown(_race?.alignment), |                   context, state, AppLocalizations.of(context).raceAlignment), | ||||||
|  |               _buildMarkdown(context, state, state.race?.alignment), | ||||||
|               Text(""), |               Text(""), | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceSize), |               _buildSubTitle( | ||||||
|               _buildMarkdown(_race?.size), |                   context, state, AppLocalizations.of(context).raceSize), | ||||||
|  |               _buildMarkdown(context, state, state.race?.size), | ||||||
|               Text(""), |               Text(""), | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceSpeed), |               _buildSubTitle( | ||||||
|               _buildMarkdown(_race?.speed), |                   context, state, AppLocalizations.of(context).raceSpeed), | ||||||
|               _race?.darkvision != null ? Text("") : SizedBox.shrink(), |               _buildMarkdown(context, state, state.race?.speed), | ||||||
|               _race?.darkvision != null ? _buildSubTitle(AppLocalizations.of(context).raceDarkvision) : SizedBox.shrink(), |               state.race?.darkvision != null ? Text("") : SizedBox.shrink(), | ||||||
|               _race?.darkvision != null ? _buildMarkdown(_race?.darkvision) : SizedBox.shrink(), |               state.race?.darkvision != null | ||||||
|  |                   ? _buildSubTitle(context, state, | ||||||
|  |                       AppLocalizations.of(context).raceDarkvision) | ||||||
|  |                   : SizedBox.shrink(), | ||||||
|  |               state.race?.darkvision != null | ||||||
|  |                   ? _buildMarkdown(context, state, state.race?.darkvision) | ||||||
|  |                   : SizedBox.shrink(), | ||||||
|               Text(""), |               Text(""), | ||||||
|               _buildSubTitle(AppLocalizations.of(context).raceLanguages), |               _buildSubTitle( | ||||||
|               _buildMarkdown(_race?.languages), |                   context, state, AppLocalizations.of(context).raceLanguages), | ||||||
|  |               _buildMarkdown(context, state, state.race?.languages), | ||||||
|             ], |             ], | ||||||
|           ) |           ) | ||||||
|         : SizedBox.shrink(); |         : SizedBox.shrink(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildBackgroundsWidget() { |   Widget _buildBackgroundsWidget( | ||||||
|  |       BuildContext context, PlayerCharacterState state) { | ||||||
|     return _buildItemsWidget<BackgroundItem>( |     return _buildItemsWidget<BackgroundItem>( | ||||||
|  |       context, | ||||||
|  |       state, | ||||||
|       hintText: "Historique", |       hintText: "Historique", | ||||||
|       items: _backgrounds, |       items: state.backgrounds, | ||||||
|       selectedItem: _background, |       selectedItem: state.background, | ||||||
|       onChanged: (value) { |       onChanged: (value) { | ||||||
|         _setBackground(value); |         //state.setBackground(value); | ||||||
|  |         BlocProvider.of<PlayerCharacterBloc>(context) | ||||||
|  |             .add(BackgroundEvent(value)); | ||||||
|       }, |       }, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Widget _buildSubBackgroundsWidget() { |   Widget _buildSubBackgroundsWidget( | ||||||
|     return _subBackgrounds != null |       BuildContext context, PlayerCharacterState state) { | ||||||
|  |     return state.subBackgrounds != null | ||||||
|         ? _buildItemsWidget<SubBackgroundItem>( |         ? _buildItemsWidget<SubBackgroundItem>( | ||||||
|  |             context, | ||||||
|  |             state, | ||||||
|             hintText: "Variante", |             hintText: "Variante", | ||||||
|             items: _subBackgrounds, |             items: state.subBackgrounds, | ||||||
|             selectedItem: _subBackground, |             selectedItem: state.subBackground, | ||||||
|             onChanged: (value) { |             onChanged: (value) { | ||||||
|               _setSubBackground(value); |               //state.setSubBackground(value); | ||||||
|  |               BlocProvider.of<PlayerCharacterBloc>(context) | ||||||
|  |                   .add(SubBackgroundEvent(value)); | ||||||
|             }, |             }, | ||||||
|           ) |           ) | ||||||
|         : SizedBox.shrink(); |         : SizedBox.shrink(); | ||||||
|  | @ -229,6 +282,26 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
| 
 | 
 | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|  |     return MultiBlocProvider( | ||||||
|  |       providers: [ | ||||||
|  |         BlocProvider<PlayerCharacterBloc>( | ||||||
|  |           create: (context) { | ||||||
|  |             return PlayerCharacterBloc(context) | ||||||
|  |               ..add( | ||||||
|  |                 LoadEvent(), | ||||||
|  |               ); | ||||||
|  |           }, | ||||||
|  |         ), | ||||||
|  |       ], | ||||||
|  |       child: BlocBuilder<PlayerCharacterBloc, PlayerCharacterState>( | ||||||
|  |         builder: (context, state) { | ||||||
|  |           return buildUI(context, state); | ||||||
|  |         }, | ||||||
|  |       ), | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   Widget buildUI(BuildContext context, PlayerCharacterState state) { | ||||||
|     return DefaultTabController( |     return DefaultTabController( | ||||||
|       length: 5, |       length: 5, | ||||||
|       child: Scaffold( |       child: Scaffold( | ||||||
|  | @ -285,9 +358,9 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|               margin: EdgeInsets.all(10.0), |               margin: EdgeInsets.all(10.0), | ||||||
|               child: ListView( |               child: ListView( | ||||||
|                 children: <Widget>[ |                 children: <Widget>[ | ||||||
|                   _buildRacesWidget(), |                   _buildRacesWidget(context, state), | ||||||
|                   _buildSubRacesWidget(), |                   _buildSubRacesWidget(context, state), | ||||||
|                   _buildRaceDetailsWidget(), |                   _buildRaceDetailsWidget(context, state), | ||||||
|                 ], |                 ], | ||||||
|               ), |               ), | ||||||
|             ), |             ), | ||||||
|  | @ -295,8 +368,8 @@ class _PCEditorPageState extends State<PCEditorPage> { | ||||||
|               margin: EdgeInsets.all(10.0), |               margin: EdgeInsets.all(10.0), | ||||||
|               child: ListView( |               child: ListView( | ||||||
|                 children: <Widget>[ |                 children: <Widget>[ | ||||||
|                   _buildBackgroundsWidget(), |                   _buildBackgroundsWidget(context, state), | ||||||
|                   _buildSubBackgroundsWidget(), |                   _buildSubBackgroundsWidget(context, state), | ||||||
|                 ], |                 ], | ||||||
|               ), |               ), | ||||||
|             ), |             ), | ||||||
|  |  | ||||||
|  | @ -99,6 +99,13 @@ packages: | ||||||
|       url: "https://pub.dartlang.org" |       url: "https://pub.dartlang.org" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "1.3.3" |     version: "1.3.3" | ||||||
|  |   equatable: | ||||||
|  |     dependency: "direct main" | ||||||
|  |     description: | ||||||
|  |       name: equatable | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "1.1.1" | ||||||
|   flutter: |   flutter: | ||||||
|     dependency: "direct main" |     dependency: "direct main" | ||||||
|     description: flutter |     description: flutter | ||||||
|  |  | ||||||
|  | @ -30,9 +30,8 @@ dependencies: | ||||||
|   flutter_svg: |   flutter_svg: | ||||||
|   bloc: |   bloc: | ||||||
|   flutter_bloc: |   flutter_bloc: | ||||||
|   # The following adds the Cupertino Icons font to your application. |  | ||||||
|   # Use with the CupertinoIcons class for iOS style icons. |  | ||||||
|   cupertino_icons: ^0.1.2 |   cupertino_icons: ^0.1.2 | ||||||
|  |   equatable: ^1.0.0 | ||||||
| 
 | 
 | ||||||
| dev_dependencies: | dev_dependencies: | ||||||
|   flutter_test: |   flutter_test: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez