1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 22:45:44 +00:00

Design/refactor

This commit is contained in:
Yan Maniez 2020-02-28 17:59:22 +01:00
parent 4f8a37a6b9
commit e91e7e4a39
4 changed files with 121 additions and 110 deletions

View file

@ -53,13 +53,13 @@ Future<Item> getItemWithId(String id) async {
} }
Future<Item> loadChildrenItems(Item item, List<Filter> filters) async { Future<Item> loadChildrenItems(Item item, List<Filter> filters) async {
print("getChildrenItems " + (item?.ItemType ?? "")); print("getChildrenItems " + (item?.itemType ?? ""));
if (item.ItemType.endsWith("Items")) { if (item.itemType.endsWith("Items")) {
String itemType = String itemType =
item.ItemType.substring(0, item.ItemType.length - 1); item.itemType.substring(0, item.itemType.length - 1);
String family = ""; String family = "";
if (item is FilteredItems) { if (item is FilteredItems) {
family = (item as FilteredItems)?.Family ?? ""; family = (item as FilteredItems)?.family ?? "";
} }
String whereFilter = ""; String whereFilter = "";
if(filters != null) { if(filters != null) {
@ -83,7 +83,7 @@ Future<Item> loadChildrenItems(Item item, List<Filter> filters) async {
if (response.isEmpty) { if (response.isEmpty) {
print("Children not found"); print("Children not found");
} }
item.Children = response.isNotEmpty item.children = response.isNotEmpty
? itemsFromMapList(response) ? itemsFromMapList(response)
: null; : null;
} }

View file

@ -10,9 +10,23 @@ class MyApp extends StatelessWidget {
title: 'Haches & Dés', title: 'Haches & Dés',
theme: ThemeData( theme: ThemeData(
primarySwatch: Colors.deepOrange, primarySwatch: Colors.deepOrange,
appBarTheme: AppBarTheme(
color: Colors.white,
iconTheme: IconThemeData(color: Colors.black),
textTheme: TextTheme(
headline6: TextStyle(fontSize: 28.0, color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'Cinzel')),
),
brightness: Brightness.light,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.cyan[600],
fontFamily: 'LinuxLibertine',
textTheme: TextTheme(
headline5: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold, fontFamily: 'Cinzel'),
headline6: TextStyle(fontSize: 22.0, fontStyle: FontStyle.normal),
bodyText2: TextStyle(fontSize: 16.0),
),
), ),
home: MyHomePage(id: 'index.md'), home: MyHomePage(id: 'index.md'),
); );
} }
} }

View file

@ -1,31 +1,32 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Item { class Item {
String Id; String id;
String RootId; String rootId;
String ParentLink; String parentLink;
String Name; String name;
String NormalizedName; String normalizedName;
String ParentName; String parentName;
int NameLevel; int nameLevel;
String Alias; String alias;
String AliasText; String aliasText;
String NormalizedAlias; String normalizedAlias;
String Source; String source;
String Markdown; String markdown;
String FullText; String fullText;
String ItemType; String itemType;
List<Item> Children; List<Item> children;
Item({this.Id, this.Name, this.Alias, this.Markdown, this.ItemType}); Item({this.id, this.name, this.alias, this.markdown, this.itemType});
Item.fromMap(Map<String, dynamic> map) { Item.fromMap(Map<String, dynamic> map) {
this.Id = map["Id"]; this.id = map["Id"];
this.Name = map["Name"]; this.rootId = map["RootId"];
this.Alias = map["AltName"]; this.name = map["Name"];
this.AliasText = map["AltNameText"]; this.alias = map["AltName"];
this.Markdown = map["Markdown"]; this.aliasText = map["AltNameText"];
this.ItemType = map["ItemType"]; this.markdown = map["Markdown"];
this.itemType = map["ItemType"];
} }
/*factory Item.fromMap(Map<String, dynamic> json) => new Item( /*factory Item.fromMap(Map<String, dynamic> json) => new Item(
@ -37,70 +38,70 @@ class Item {
);*/ );*/
Map<String, dynamic> toMap() => { Map<String, dynamic> toMap() => {
"Id": Id, "Id": id,
"RootId": Id, "RootId": rootId,
"Name": Name, "Name": name,
"AltName": Alias, "AltName": alias,
"AltNameText": AliasText, "AltNameText": aliasText,
"Markdown": Markdown, "Markdown": markdown,
"ItemType": ItemType, "ItemType": itemType,
}; };
} }
class MonsterItem extends Item { class MonsterItem extends Item {
String Family; String family;
String Type; String type;
String Size; String size;
String Alignment; String alignment;
String Terrain; String terrain;
String Legendary; String legendary;
String ArmorClass; String armorClass;
String HitPoints; String hitPoints;
String Speed; String speed;
String Strength; String strength;
String Dexterity; String dexterity;
String Constitution; String constitution;
String Intelligence; String intelligence;
String Wisdom; String wisdom;
String Charisma; String charisma;
String SavingThrows; String savingThrows;
String Skills; String skills;
String DamageVulnerabilities; String damageVulnerabilities;
String DamageImmunities; String damageImmunities;
String ConditionImmunities; String conditionImmunities;
String DamageResistances; String damageResistances;
String Senses; String senses;
String Languages; String languages;
String Challenge; String challenge;
int XP; int xp;
MonsterItem.fromMap(Map<String, dynamic> map) MonsterItem.fromMap(Map<String, dynamic> map)
: super.fromMap(map) { : super.fromMap(map) {
this.Family = map["Family"]; this.family = map["Family"];
this.Type = map["Type"]; this.type = map["Type"];
this.Size = map["Size"]; this.size = map["Size"];
this.Alignment = map["Alignment"]; this.alignment = map["Alignment"];
this.Terrain = map["Terrain"]; this.terrain = map["Terrain"];
this.Legendary = map["Legendary"]; this.legendary = map["Legendary"];
this.ArmorClass = map["ArmorClass"]; this.armorClass = map["ArmorClass"];
this.HitPoints = map["HitPoints"]; this.hitPoints = map["HitPoints"];
this.Speed = map["Speed"]; this.speed = map["Speed"];
this.Strength = map["Strength"]; this.strength = map["Strength"];
this.Dexterity = map["Dexterity"]; this.dexterity = map["Dexterity"];
this.Constitution = map["Constitution"]; this.constitution = map["Constitution"];
this.Intelligence = map["Intelligence"]; this.intelligence = map["Intelligence"];
this.Wisdom = map["Wisdom"]; this.wisdom = map["Wisdom"];
this.Charisma = map["Charisma"]; this.charisma = map["Charisma"];
this.SavingThrows = map["SavingThrows"]; this.savingThrows = map["SavingThrows"];
this.Skills = map["Skills"]; this.skills = map["Skills"];
this.DamageVulnerabilities = map["DamageVulnerabilities"]; this.damageVulnerabilities = map["DamageVulnerabilities"];
this.DamageImmunities = map["DamageImmunities"]; this.damageImmunities = map["DamageImmunities"];
this.ConditionImmunities = map["ConditionImmunities"]; this.conditionImmunities = map["ConditionImmunities"];
this.DamageResistances = map["DamageResistances"]; this.damageResistances = map["DamageResistances"];
this.Senses = map["Senses"]; this.senses = map["Senses"];
this.Languages = map["Languages"]; this.languages = map["Languages"];
this.Challenge = map["Challenge"]; this.challenge = map["Challenge"];
this.XP = map["XP"]; this.xp = map["XP"];
} }
} }
@ -112,11 +113,11 @@ class Items extends Item {
} }
abstract class FilteredItems extends Items { abstract class FilteredItems extends Items {
String Family; String family;
FilteredItems.fromMap(Map<String, dynamic> map) FilteredItems.fromMap(Map<String, dynamic> map)
: super.fromMap(map) { : super.fromMap(map) {
this.Family = map["Family"]; this.family = map["Family"];
} }
List<Filter> toFilterList(); List<Filter> toFilterList();

View file

@ -25,7 +25,7 @@ class _MyHomePageState extends State<MyHomePage> {
this.filters = null; this.filters = null;
} }
this.markdown = this.markdown =
item.Markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) { item.markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
return ''; return '';
}); });
}); });
@ -40,25 +40,19 @@ class _MyHomePageState extends State<MyHomePage> {
void initState() { void initState() {
super.initState(); super.initState();
ThemeData theme = ThemeData(
brightness: Brightness.light,
primaryColor: Colors.lightBlue[800],
accentColor: Colors.cyan[600],
fontFamily: 'LinuxLibertine',
textTheme: TextTheme(
headline: TextStyle(fontSize: 28.0, fontWeight: FontWeight.bold),
title: TextStyle(fontSize: 22.0, fontStyle: FontStyle.italic),
body1: TextStyle(fontSize: 16.0, fontFamily: 'Hind'),
),
);
styleSheet = MarkdownStyleSheet.fromTheme(theme).copyWith(
tableColumnWidth: IntrinsicColumnWidth(),
tableCellsPadding: EdgeInsets.all(0.2));
_loadItem().then((item) => setItem(item)); _loadItem().then((item) => setItem(item));
} }
@protected
@mustCallSuper
void didChangeDependencies() {
styleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
tableColumnWidth: IntrinsicColumnWidth(),
tableCellsPadding: EdgeInsets.all(0.2),
);
}
Future<Item> _loadItem() async { Future<Item> _loadItem() async {
var item = await getItemWithId(this.widget.id); var item = await getItemWithId(this.widget.id);
var items = await loadChildrenItems(item, filters); var items = await loadChildrenItems(item, filters);
@ -78,23 +72,25 @@ class _MyHomePageState extends State<MyHomePage> {
} }
Widget _buildMarkdownBody(BuildContext context) { Widget _buildMarkdownBody(BuildContext context) {
return MarkdownBody( return Container(
margin: const EdgeInsets.all(10.0),
child: MarkdownBody(
data: markdown, data: markdown,
styleSheet: styleSheet, styleSheet: styleSheet,
onTapLink: (link) => Navigator.push( onTapLink: (link) => Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => MyHomePage(id: link)), MaterialPageRoute(builder: (context) => MyHomePage(id: link)),
), ),
); ));
} }
Widget _buildChildTile(BuildContext context, Item item) { Widget _buildChildTile(BuildContext context, Item item) {
return ListTile( return ListTile(
title: Text(item.Name), title: Text(item.name),
subtitle: Text(item.AliasText ?? ""), subtitle: Text(item.aliasText ?? ""),
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => MyHomePage(id: item.Id)), MaterialPageRoute(builder: (context) => MyHomePage(id: item.id)),
), ),
); );
} }
@ -103,11 +99,11 @@ class _MyHomePageState extends State<MyHomePage> {
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
ListView.builder( ListView.builder(
itemCount: (item?.Children?.length ?? 0) + 1, itemCount: (item?.children?.length ?? 0) + 1,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return index == 0 return index == 0
? _buildMarkdownBody(context) ? _buildMarkdownBody(context)
: _buildChildTile(context, item.Children[index - 1]); : _buildChildTile(context, item.children[index - 1]);
}) })
], ],
); );