import 'package:flutter/material.dart'; import 'package:toolheim/github_reader.dart'; import 'package:toolheim/warband_roaster.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 { // TODO: Read this from SharedPreferences String activePlayer = 'Aaron'; GitHubAdapter github = GitHubAdapter( 'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters'); List playerList(List roasters) { List tiles = new List(); WarbandRoaster myWarband = roasters.firstWhere((roaster) { return roaster.playerName == activePlayer; }); // Show some stats for the own warband tiles.add(UserAccountsDrawerHeader( otherAccountsPictures: [ IconButton( icon: Icon(Icons.refresh), color: Colors.white, tooltip: 'Refresh warbands', onPressed: () { setState(() { //roasters = await github.update(); }); }, ), IconButton( icon: Icon(Icons.search), color: Colors.white, tooltip: 'Read warbands', onPressed: () { setState(() { //roasters = await github.search() }); }, ) ], accountName: Text(myWarband.name), accountEmail: Text(myWarband.race), currentAccountPicture: CircleAvatar( child: Text('Aa'), ), )); // TODO: Order Players on CP or rating roasters.forEach((roaster) { // We mark inactive warbands with a gray acent var textColor = Colors.black; if (!roaster.active) { textColor = Colors.black45; } tiles.add(ListTile( title: Text(roaster.name + ' (' + roaster.playerName + ')', style: TextStyle(color: textColor)), 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 roasters = snapshot.data; if (roasters.length == 0) { return Text('No warbands found'); } // TODO: Replace with router WarbandRoaster warband = roasters.firstWhere((roaster) { return roaster.playerName == this.activePlayer; }); return Scaffold( appBar: AppBar( title: Text(warband.name), ), drawer: Drawer( child: SingleChildScrollView( 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), ); } })); } }); } }