toolheim/mobile-app/lib/main.dart

135 lines
4.3 KiB
Dart
Raw Normal View History

2019-06-27 00:16:58 +02:00
import 'dart:collection';
2019-06-24 00:53:43 +02:00
import 'package:flutter/material.dart';
2019-07-06 00:44:20 +02:00
import 'package:toolheim/github_reader.dart';
import 'package:toolheim/warband_roaster.dart';
2019-06-24 00:53:43 +02:00
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> {
2019-07-06 00:44:20 +02:00
// TODO: Read this from SharedPreferences
String activePlayer = 'Aaron';
Future<List<WarbandRoaster>> roasters;
GitHubAdapter github = GitHubAdapter(
'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters');
2019-06-24 00:53:43 +02:00
2019-07-06 00:44:20 +02:00
Future initState() {
2019-06-24 00:53:43 +02:00
super.initState();
2019-07-06 00:44:20 +02:00
roasters = github.search();
2019-06-27 00:16:58 +02:00
}
2019-07-06 00:44:20 +02:00
List<Widget> playerList(List<WarbandRoaster> roasters) {
2019-06-27 00:16:58 +02:00
List<Widget> tiles = new List();
2019-07-06 00:44:20 +02:00
WarbandRoaster myWarband = roasters.first;
2019-06-27 00:16:58 +02:00
// Show some stats for the own warband
tiles.add(UserAccountsDrawerHeader(
2019-07-06 00:44:20 +02:00
accountName: Text(myWarband.name),
accountEmail: Text(myWarband.race),
2019-06-27 00:16:58 +02:00
currentAccountPicture: CircleAvatar(
child: Text('Aa'),
),
));
// TODO: Order Players on CP or rating
2019-07-06 00:44:20 +02:00
roasters.forEach((roaster) {
2019-06-27 00:16:58 +02:00
tiles.add(ListTile(
2019-07-06 00:44:20 +02:00
title: Text(roaster.name + '(' + roaster.playerName + ')'),
subtitle: Text(roaster.commitMessage),
isThreeLine: true,
trailing: Chip(
label: Text(
'326 XP',
))));
2019-06-27 00:16:58 +02:00
});
tiles.add(Divider());
return tiles;
2019-06-24 00:53:43 +02:00
}
@override
Widget build(BuildContext context) {
2019-06-25 00:53:45 +02:00
return FutureBuilder(
2019-07-06 00:44:20 +02:00
future: github.search(),
2019-06-25 00:53:45 +02:00
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
case ConnectionState.active:
return Center(child: CircularProgressIndicator());
case ConnectionState.done:
2019-07-06 00:44:20 +02:00
List<WarbandRoaster> roasters = snapshot.data;
// TODO: Replace with router
WarbandRoaster warband = roasters.first;
2019-06-25 00:53:45 +02:00
return Scaffold(
2019-07-06 00:44:20 +02:00
appBar: AppBar(
title: Text(warband.name),
2019-06-27 00:16:58 +02:00
),
2019-07-06 00:44:20 +02:00
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),
);
}
}));
2019-06-25 00:53:45 +02:00
}
2019-07-06 00:44:20 +02:00
});
2019-06-24 00:53:43 +02:00
}
}