meta information

This commit is contained in:
Aaron Fischer 2019-08-13 22:37:22 +02:00
parent ceae866d97
commit b5a5f60618
5 changed files with 228 additions and 110 deletions

View file

@ -375,6 +375,18 @@ class WarbandRoster {
return rating;
}
int routLimit() {
var unitCount = heros.length;
henchmenGroups.forEach((group) => unitCount += group.number);
var routLimit = (unitCount / 4).round();
if (unitCount / 4 > routLimit) {
routLimit++;
}
return routLimit;
}
static HashMap<String, String> _warbandNameAndRaceFromJson(
String nameAndRace) {
HashMap<String, String> nr = new HashMap();

View file

@ -1,18 +1,18 @@
import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:timeago_flutter/timeago_flutter.dart';
import 'package:toolheim/data/github_adapter.dart';
import 'package:toolheim/widgets/stats_widget.dart';
import 'package:toolheim/data/warband_roster.dart';
import 'package:toolheim/widgets/henchmengroup_list_tile_widget.dart';
import 'package:toolheim/widgets/hero_list_tile_widget.dart';
import 'package:toolheim/widgets/value_chip_widget.dart';
import 'package:toolheim/widgets/warband_drawer_widget.dart';
class WarbandRosterScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
if (github.activeRoster == null) {
if (github(context).activeRoster == null) {
return Scaffold(
appBar: AppBar(title: const Text('Toolheim')),
body: Builder(builder: (BuildContext context) {
@ -40,113 +40,90 @@ class WarbandRosterScreen extends StatelessWidget {
child: SingleChildScrollView(child: WarbandDrawerWidget())));
}
WarbandRoster roster = github(context).activeRoster;
return Scaffold(
appBar: AppBar(
title: Text(github.activeRoster.name),
drawer: warbandDrawer(context),
appBar: AppBar(title: Text(roster.name)),
body: SingleChildScrollView(
child: Column(children: [
Padding(
padding: const EdgeInsets.only(left: 10),
child: Row(
children: <Widget>[
ValueChipWidget('CP', roster.campaignPoints.toString()),
ValueChipWidget('Rating', roster.rating().toString()),
ValueChipWidget('Rout Limit', roster.routLimit().toString()),
],
),
),
Divider(),
...units(roster),
warbandMetaInformation(roster)
])));
}
Widget warbandMetaInformation(WarbandRoster roster) {
return Padding(
padding: const EdgeInsets.only(left: 40, right: 40, top: 30),
child: Table(
columnWidths: {0: FixedColumnWidth(80)},
children: <TableRow>[
metaTableRow('Alignment', roster.alignment),
metaTableRow('Objective', roster.objective),
metaTableRow('Achivements', roster.achievments),
metaTableRow('Shards', roster.shards),
metaTableRow('GC', roster.gc),
metaTableRow('Equipment', roster.equipment),
],
),
drawer: Drawer(
child: Column(children: <Widget>[
Expanded(child: SingleChildScrollView(child: WarbandDrawerWidget())),
Container(
color: Colors.brown,
padding: EdgeInsets.all(10),
child: Align(
alignment: Alignment.bottomLeft,
child: Timeago(
date: github.lastSync,
builder: (_, value) => Text(
'Last sync: ' + value,
style: TextStyle(color: Colors.white),
))))
])),
body: SingleChildScrollView(
child: Column(children: [
for (var hero in github.activeRoster.heros)
ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 5),
child: Text(hero.name,
style: TextStyle(
fontWeight: hero.rules.contains('Leader')
? FontWeight.bold
: FontWeight.normal)),
),
Text(
'(' + hero.type + ')',
style: TextStyle(fontSize: 10),
)
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(hero.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: hero.hiredSword ? Colors.black : Colors.green,
foregroundColor:
hero.hiredSword ? Colors.grey : Colors.greenAccent,
),
subtitle: StatsWidget(hero.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
),
Divider(),
for (var henchmenGroup in github.activeRoster.henchmenGroups)
ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 5),
child: Text(henchmenGroup.name),
),
Text(
'(' + henchmenGroup.type + ')',
style: TextStyle(fontSize: 10),
),
Spacer(),
Badge(
badgeColor: Colors.black12,
shape: BadgeShape.square,
borderRadius: 2,
badgeContent: Text(henchmenGroup.number.toString() + 'x',
style: TextStyle(color: Colors.white)),
),
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(henchmenGroup.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
subtitle: StatsWidget(henchmenGroup.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
),
Divider()
])),
);
}
TableRow metaTableRow(String name, dynamic value) {
return TableRow(children: [
Text(
name.toString().trim() + ':',
style: TextStyle(fontSize: 12),
textAlign: TextAlign.right,
),
Padding(
padding: const EdgeInsets.only(left: 10, bottom: 10),
child: Text(
value.toString().trim(),
style: TextStyle(fontWeight: FontWeight.bold),
),
)
]);
}
Drawer warbandDrawer(BuildContext context) {
return Drawer(
child: Column(children: <Widget>[
Expanded(child: SingleChildScrollView(child: WarbandDrawerWidget())),
Container(
color: Colors.brown,
padding: EdgeInsets.all(10),
child: Align(
alignment: Alignment.bottomLeft,
child: Timeago(
date: github(context).lastSync,
builder: (_, value) => Text(
'Last sync: ' + value,
style: TextStyle(color: Colors.white),
))))
]));
}
List<Widget> units(WarbandRoster roster) {
return [
for (var hero in roster.heros) HeroListTileWidget(hero),
Divider(),
for (var henchmenGroup in roster.henchmenGroups)
HenchmengroupListTileWidget(henchmenGroup),
Divider()
];
}
GitHubAdapter github(context) => Provider.of<GitHubAdapter>(context);
}

View file

@ -0,0 +1,56 @@
import 'package:badges/badges.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toolheim/widgets/stats_widget.dart';
class HenchmengroupListTileWidget extends StatelessWidget {
final henchmenGroup;
HenchmengroupListTileWidget(this.henchmenGroup);
@override
Widget build(BuildContext context) {
return ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 5),
child: Text(henchmenGroup.name),
),
Text(
'(' + henchmenGroup.type + ')',
style: TextStyle(fontSize: 10),
),
Spacer(),
Badge(
badgeColor: Colors.black12,
shape: BadgeShape.square,
borderRadius: 2,
badgeContent: Text(henchmenGroup.number.toString() + 'x',
style: TextStyle(color: Colors.white)),
),
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(henchmenGroup.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
subtitle: StatsWidget(henchmenGroup.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
);
}
}

View file

@ -0,0 +1,50 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toolheim/widgets/stats_widget.dart';
class HeroListTileWidget extends StatelessWidget {
final hero;
HeroListTileWidget(this.hero);
@override
Widget build(BuildContext context) {
return ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Row(children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 5),
child: Text(hero.name,
style: TextStyle(
fontWeight: hero.rules.contains('Leader')
? FontWeight.bold
: FontWeight.normal)),
),
Text(
'(' + hero.type + ')',
style: TextStyle(fontSize: 10),
)
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(hero.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: hero.hiredSword ? Colors.black : Colors.green,
foregroundColor: hero.hiredSword ? Colors.grey : Colors.greenAccent,
),
subtitle: StatsWidget(hero.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
});
}
}

View file

@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
class ValueChipWidget extends StatelessWidget {
final String name;
final String value;
ValueChipWidget(this.name, this.value);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Chip(
label: Row(children: <Widget>[
Text(name.toString() + ': '),
Text(
value.toString(),
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
)
])),
);
}
}