Add drawer

This commit is contained in:
Aaron Fischer 2019-06-27 00:16:58 +02:00
parent 46f738775a
commit 35276cf974
2 changed files with 82 additions and 17 deletions

View file

@ -67,8 +67,8 @@ class HenchmenGroup extends Unit {
var matches = re.allMatches(header).toList().first; var matches = re.allMatches(header).toList().first;
h['name'] = matches.group(1); h['name'] = matches.group(1);
h['type'] = matches.group(2); h['number'] = matches.group(2);
h['number'] = matches.group(3); h['type'] = matches.group(3);
h['experience'] = matches.group(4); h['experience'] = matches.group(4);
return h; return h;

View file

@ -1,5 +1,6 @@
import 'dart:collection';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as prefix0;
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:toolheim/WarbandRoaster.dart'; import 'package:toolheim/WarbandRoaster.dart';
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
@ -28,8 +29,7 @@ class RoasterWidget extends StatefulWidget {
class _RoasterWidgetState extends State<RoasterWidget> { class _RoasterWidgetState extends State<RoasterWidget> {
Future<WarbandRoaster> roaster; Future<WarbandRoaster> roaster;
static Future<WarbandRoaster> fetchWarband() async { static Future<WarbandRoaster> fetchWarband(urlPath) async {
final String urlPath = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Aaron/aaron.mordheim.yml';
http.Response response = await http.get(urlPath); http.Response response = await http.get(urlPath);
YamlMap yamlObject = loadYaml(response.body); YamlMap yamlObject = loadYaml(response.body);
return WarbandRoaster.fromJson(yamlObject); return WarbandRoaster.fromJson(yamlObject);
@ -37,7 +37,49 @@ class _RoasterWidgetState extends State<RoasterWidget> {
void initState() { void initState() {
super.initState(); super.initState();
roaster = fetchWarband(); roaster = fetchWarband(players()['Aaron']);
}
HashMap players() {
HashMap players = new HashMap();
players['Aaron'] = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Aaron/aaron.mordheim.yml';
players['Kai'] = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/kai/kai.mordheim_post5.yml';
players['Fabian'] = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Fabian/fabian.mordheim.yml';
players['Marius'] = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Marius/Marius_Post_5.mordheim.yml';
players['Stefan'] = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Stefan/Pit%20Fighter.yml';
return players;
}
List<Widget> playerList() {
List<Widget> tiles = new List();
// Show some stats for the own warband
tiles.add(UserAccountsDrawerHeader(
accountName: Text('The Revolting Dwarfs'),
accountEmail: Text('Dwarf Rangers'),
currentAccountPicture: CircleAvatar(
child: Text('Aa'),
),
));
// TODO: Order Players on CP or rating
players().forEach((player, url) {
tiles.add(ListTile(
title: Text(player.toString()),
leading: CircleAvatar(
child: Text('WB'),
),
trailing: Chip(
label: Text('326 XP')
)
));
});
tiles.add(Divider());
return tiles;
} }
@override @override
@ -56,20 +98,43 @@ class _RoasterWidgetState extends State<RoasterWidget> {
appBar: AppBar( appBar: AppBar(
title: Text(roaster.name), title: Text(roaster.name),
), ),
drawer: Drawer(
child: Column(
children: this.playerList()
),
),
body: ListView.builder( body: ListView.builder(
itemCount: roaster.heros.length, itemCount: roaster.heros.length + roaster.henchmenGroups.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
var hero = roaster.heros[index]; // TODO: Sort by initiative
if (index < roaster.heros.length) {
var hero = roaster.heros[index];
return ListTile( return ListTile(
title: Text(hero.name), title: Text(hero.name),
leading: CircleAvatar( leading: CircleAvatar(
child: Text(hero.experience.toString()), child: Text(hero.experience.toString()),
backgroundColor: Colors.green, backgroundColor: Colors.green,
foregroundColor: Colors.greenAccent, foregroundColor: Colors.greenAccent,
), ),
subtitle: Text(hero.type), subtitle: Text(hero.type),
); );
} else {
var henchmenGroup = roaster.henchmenGroups[index-roaster.heros.length];
return ListTile(
title: Text(henchmenGroup.name),
trailing: Chip(
label: Text(henchmenGroup.number.toString() + 'x')
),
leading: CircleAvatar(
child: Text(henchmenGroup.experience.toString()),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
subtitle: Text(henchmenGroup.type),
);
}
} }
) )
); );