| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  | import 'package:aidedejeu_flutter/database.dart'; | 
					
						
							|  |  |  | import 'package:aidedejeu_flutter/models/items.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  | import 'package:aidedejeu_flutter/widgets/library.dart'; | 
					
						
							| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  | import 'package:flutter_markdown/flutter_markdown.dart'; | 
					
						
							| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PCEditorPage extends StatefulWidget { | 
					
						
							|  |  |  |   PCEditorPage({Key key}) : super(key: key); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |         appBar: AppBar( | 
					
						
							|  |  |  |           title: Text("Personnage"), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         body: Column()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<StatefulWidget> createState() => _PCEditorPageState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _PCEditorPageState extends State<PCEditorPage> { | 
					
						
							| 
									
										
										
										
											2020-03-01 00:27:51 +01:00
										 |  |  |   RaceItem _race; | 
					
						
							|  |  |  |   SubRaceItem _subRace; | 
					
						
							|  |  |  |   List<RaceItem> _races; | 
					
						
							|  |  |  |   List<SubRaceItem> _subRaces; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void initState() { | 
					
						
							|  |  |  |     // TODO: implement initState
 | 
					
						
							|  |  |  |     super.initState(); | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |     _initRaces(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void _initRaces() async { | 
					
						
							|  |  |  |     var races = await loadRaces(); | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       _races = races.map((e) => e as RaceItem).toList(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void _initSubRaces(RaceItem race) async { | 
					
						
							|  |  |  |     var subRaces = await loadSubRaces(race); | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       _subRaces = subRaces.map((e) => e as SubRaceItem).toList(); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-01 00:27:51 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void _setRace(RaceItem race) { | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       this._race = race; | 
					
						
							|  |  |  |       this._subRace = null; | 
					
						
							|  |  |  |       this._subRaces = null; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |     _initSubRaces(race); | 
					
						
							| 
									
										
										
										
											2020-03-01 00:27:51 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void _setSubRace(SubRaceItem subRace) { | 
					
						
							|  |  |  |     setState(() { | 
					
						
							|  |  |  |       this._subRace = subRace; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _loadRacesWidget() { | 
					
						
							|  |  |  |     return DropdownButton( | 
					
						
							|  |  |  |       hint: Text("Race"), | 
					
						
							|  |  |  |       value: _races != null ? _race : "", | 
					
						
							|  |  |  |       onChanged: (value) { | 
					
						
							|  |  |  |         _setRace(value); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       items: _races != null | 
					
						
							|  |  |  |           ? _races | 
					
						
							|  |  |  |               .map((e) => DropdownMenuItem( | 
					
						
							|  |  |  |                     value: e, | 
					
						
							|  |  |  |                     child: Text(e.name), | 
					
						
							|  |  |  |                   )) | 
					
						
							|  |  |  |               .toList() | 
					
						
							|  |  |  |           : null, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |   Widget _loadRaceSubRaceWidget() { | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  |     return _race != null ? Column( | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  |         Text("Augmentation de caractéristiques"), | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: (_race?.abilityScoreIncrease ?? "") + | 
					
						
							|  |  |  |               "\n\n" + | 
					
						
							|  |  |  |               (_subRace?.abilityScoreIncrease ?? ""), | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  |         ), | 
					
						
							|  |  |  |         Text("Âge"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.age ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         Text("Alignement"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.alignment ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         Text("Taille"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.size ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         Text("Vitesse"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.speed ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         Text("Vision dans le noir"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.darkvision ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         Text("Langues"), | 
					
						
							|  |  |  |         MarkdownBody( | 
					
						
							|  |  |  |           data: _race?.languages ?? "", | 
					
						
							|  |  |  |           onTapLink: (link) => Navigator.push( | 
					
						
							|  |  |  |             context, | 
					
						
							|  |  |  |             MaterialPageRoute(builder: (context) => LibraryPage(id: link)), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |       ], | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  |     ): SizedBox.shrink(); | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-01 00:27:51 +01:00
										 |  |  |   Widget _loadSubRacesWidget() { | 
					
						
							|  |  |  |     return _subRaces != null | 
					
						
							|  |  |  |         ? DropdownButton( | 
					
						
							|  |  |  |             hint: Text("Sous-Race"), | 
					
						
							|  |  |  |             value: _subRaces != null ? _subRace : "", | 
					
						
							|  |  |  |             onChanged: (value) { | 
					
						
							|  |  |  |               _setSubRace(value); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             items: _subRaces != null | 
					
						
							|  |  |  |                 ? _subRaces | 
					
						
							|  |  |  |                     .map((e) => DropdownMenuItem( | 
					
						
							|  |  |  |                           value: e, | 
					
						
							|  |  |  |                           child: Text(e.name), | 
					
						
							|  |  |  |                         )) | 
					
						
							|  |  |  |                     .toList() | 
					
						
							|  |  |  |                 : null, | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         : SizedBox.shrink(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       appBar: AppBar( | 
					
						
							|  |  |  |         title: Text("Personnage"), | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  |       body: ListView( | 
					
						
							| 
									
										
										
										
											2020-03-01 01:44:08 +01:00
										 |  |  |         children: <Widget>[ | 
					
						
							|  |  |  |           _loadRacesWidget(), | 
					
						
							|  |  |  |           _loadSubRacesWidget(), | 
					
						
							|  |  |  |           _loadRaceSubRaceWidget() | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  |       ), | 
					
						
							| 
									
										
										
										
											2020-03-01 02:16:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 02:36:15 +01:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |