More code cleanup

This commit is contained in:
Aaron Fischer 2019-07-10 22:28:51 +02:00
parent 9ef1b30516
commit 657ee00271
3 changed files with 53 additions and 47 deletions

View file

@ -14,7 +14,7 @@ class GitHubAdapter extends ChangeNotifier {
DateTime _lastSync;
List<WarbandRoaster> _roasters = [];
String _activePlayerName = 'Aaron';
String _activePlayerName;
String get repository => _repository;
String get path => _path;
@ -155,6 +155,12 @@ class GitHubAdapter extends ChangeNotifier {
}
}
// Sort by CP
_roasters.sort((a, b) => b.campaignPoints.compareTo(a.campaignPoints));
// Select first as active player if no active player is selected
_activePlayerName = _roasters.first.playerName;
_lastSync = DateTime.now();
notifyListeners();
}

View file

@ -12,57 +12,50 @@ class WarbandRoasterScreen extends StatelessWidget {
if (github.lastSync == null) {
return Scaffold(
appBar: AppBar(title: Text('Toolheim')),
body: Center(
child: IconButton(
icon: Icon(Icons.search),
color: Colors.black,
tooltip: 'Search for warbands',
onPressed: github.search,
),
));
appBar: AppBar(title: const Text('Toolheim')),
body: Center(child: const Text('Please select a Warband.')),
drawer: Drawer(
child: SingleChildScrollView(child: WarbandDrawerWidget())));
}
WarbandRoaster roaster = github.activeRoaster;
return Scaffold(
appBar: AppBar(
title: Text(roaster.name),
List<Widget> tiles = new List();
roaster.heros.forEach((hero) {
tiles.add(new ListTile(
title: Text(hero.name),
leading: CircleAvatar(
child: Text(hero.experience.toString()),
backgroundColor: Colors.green,
foregroundColor: Colors.greenAccent,
),
drawer:
Drawer(child: SingleChildScrollView(child: WarbandDrawerWidget())),
body: ListView.builder(
itemCount: roaster.heros.length + roaster.henchmenGroups.length,
itemBuilder: (BuildContext context, int index) {
// TODO: Sort by initiative
if (index < roaster.heros.length) {
var hero = roaster.heros[index];
subtitle: Text(hero.type),
));
});
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 =
roaster.henchmenGroups[index - roaster.heros.length];
tiles.add(Divider());
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),
);
}
}));
roaster.henchmenGroups.forEach((henchmenGroup) {
tiles.add(new 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),
));
});
return Scaffold(
appBar: AppBar(
title: Text(roaster.name),
),
drawer:
Drawer(child: SingleChildScrollView(child: WarbandDrawerWidget())),
body: SingleChildScrollView(child: Column(children: tiles)),
);
}
}

View file

@ -10,7 +10,14 @@ class WarbandDrawerWidget extends StatelessWidget {
if (github.lastSync == null) {
// Add search button
return Column(children: <Widget>[]);
return Column(children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 50),
child: RaisedButton(
onPressed: github.search,
child: const Text('Search for warbands')),
)
]);
}
WarbandRoaster activeRoaster = github.activeRoaster;