139 lines
4.4 KiB
Dart
139 lines
4.4 KiB
Dart
import 'dart:collection';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:toolheim/github_reader.dart';
|
|
import 'package:toolheim/warband_roaster.dart';
|
|
import 'package:yaml/yaml.dart';
|
|
|
|
void main() => runApp(Toolheim());
|
|
|
|
class Toolheim extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Toolheim',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.brown,
|
|
accentColor: Colors.grey,
|
|
),
|
|
home: RoasterWidget(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class RoasterWidget extends StatefulWidget {
|
|
@override
|
|
_RoasterWidgetState createState() => _RoasterWidgetState();
|
|
}
|
|
|
|
class _RoasterWidgetState extends State<RoasterWidget> {
|
|
// TODO: Read this from SharedPreferences
|
|
String activePlayer = 'Aaron';
|
|
Future<List<WarbandRoaster>> roasters;
|
|
GitHubAdapter github = GitHubAdapter(
|
|
'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters');
|
|
|
|
Future initState() {
|
|
super.initState();
|
|
roasters = github.search();
|
|
}
|
|
|
|
List<Widget> playerList(List<WarbandRoaster> roasters) {
|
|
List<Widget> tiles = new List();
|
|
|
|
WarbandRoaster myWarband = roasters.first;
|
|
|
|
// Show some stats for the own warband
|
|
tiles.add(UserAccountsDrawerHeader(
|
|
accountName: Text(myWarband.name),
|
|
accountEmail: Text(myWarband.race),
|
|
currentAccountPicture: CircleAvatar(
|
|
child: Text('Aa'),
|
|
),
|
|
));
|
|
|
|
// TODO: Order Players on CP or rating
|
|
|
|
roasters.forEach((roaster) {
|
|
tiles.add(ListTile(
|
|
title: Text(roaster.name + ' (' + roaster.playerName + ')'),
|
|
subtitle: Text(roaster.currentVersion.message),
|
|
isThreeLine: true,
|
|
trailing: Chip(
|
|
label: Text(
|
|
'326 XP',
|
|
))));
|
|
});
|
|
|
|
tiles.add(Divider());
|
|
|
|
return tiles;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: github.search(),
|
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
|
switch (snapshot.connectionState) {
|
|
case ConnectionState.none:
|
|
case ConnectionState.waiting:
|
|
case ConnectionState.active:
|
|
return Center(child: CircularProgressIndicator());
|
|
case ConnectionState.done:
|
|
List<WarbandRoaster> roasters = snapshot.data;
|
|
|
|
if (roasters.length == 0) {
|
|
return Text('No warbands found');
|
|
}
|
|
|
|
// TODO: Replace with router
|
|
WarbandRoaster warband = roasters.first;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(warband.name),
|
|
),
|
|
drawer: Drawer(
|
|
child: Column(children: playerList(roasters)),
|
|
),
|
|
body: ListView.builder(
|
|
itemCount:
|
|
warband.heros.length + warband.henchmenGroups.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
// TODO: Sort by initiative
|
|
if (index < warband.heros.length) {
|
|
var hero = warband.heros[index];
|
|
|
|
return ListTile(
|
|
title: Text(hero.name),
|
|
leading: CircleAvatar(
|
|
child: Text(hero.experience.toString()),
|
|
backgroundColor: Colors.green,
|
|
foregroundColor: Colors.greenAccent,
|
|
),
|
|
subtitle: Text(hero.type),
|
|
);
|
|
} else {
|
|
var henchmenGroup = warband
|
|
.henchmenGroups[index - warband.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),
|
|
);
|
|
}
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
}
|