1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-29 06:26:02 +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 {
print("getChildrenItems " + (item?.ItemType ?? ""));
if (item.ItemType.endsWith("Items")) {
print("getChildrenItems " + (item?.itemType ?? ""));
if (item.itemType.endsWith("Items")) {
String itemType =
item.ItemType.substring(0, item.ItemType.length - 1);
item.itemType.substring(0, item.itemType.length - 1);
String family = "";
if (item is FilteredItems) {
family = (item as FilteredItems)?.Family ?? "";
family = (item as FilteredItems)?.family ?? "";
}
String whereFilter = "";
if(filters != null) {
@ -83,7 +83,7 @@ Future<Item> loadChildrenItems(Item item, List<Filter> filters) async {
if (response.isEmpty) {
print("Children not found");
}
item.Children = response.isNotEmpty
item.children = response.isNotEmpty
? itemsFromMapList(response)
: null;
}

View file

@ -10,9 +10,23 @@ class MyApp extends StatelessWidget {
title: 'Haches & Dés',
theme: ThemeData(
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'),
);
}
}

View file

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

View file

@ -25,7 +25,7 @@ class _MyHomePageState extends State<MyHomePage> {
this.filters = null;
}
this.markdown =
item.Markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
item.markdown.replaceAllMapped(RegExp(r'<!--.*?-->'), (match) {
return '';
});
});
@ -40,25 +40,19 @@ class _MyHomePageState extends State<MyHomePage> {
void 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));
}
@protected
@mustCallSuper
void didChangeDependencies() {
styleSheet = MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
tableColumnWidth: IntrinsicColumnWidth(),
tableCellsPadding: EdgeInsets.all(0.2),
);
}
Future<Item> _loadItem() async {
var item = await getItemWithId(this.widget.id);
var items = await loadChildrenItems(item, filters);
@ -78,23 +72,25 @@ class _MyHomePageState extends State<MyHomePage> {
}
Widget _buildMarkdownBody(BuildContext context) {
return MarkdownBody(
return Container(
margin: const EdgeInsets.all(10.0),
child: MarkdownBody(
data: markdown,
styleSheet: styleSheet,
onTapLink: (link) => Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyHomePage(id: link)),
),
);
));
}
Widget _buildChildTile(BuildContext context, Item item) {
return ListTile(
title: Text(item.Name),
subtitle: Text(item.AliasText ?? ""),
title: Text(item.name),
subtitle: Text(item.aliasText ?? ""),
onTap: () => Navigator.push(
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(
children: <Widget>[
ListView.builder(
itemCount: (item?.Children?.length ?? 0) + 1,
itemCount: (item?.children?.length ?? 0) + 1,
itemBuilder: (BuildContext context, int index) {
return index == 0
? _buildMarkdownBody(context)
: _buildChildTile(context, item.Children[index - 1]);
: _buildChildTile(context, item.children[index - 1]);
})
],
);