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; DateTime _lastSync;
List<WarbandRoaster> _roasters = []; List<WarbandRoaster> _roasters = [];
String _activePlayerName = 'Aaron'; String _activePlayerName;
String get repository => _repository; String get repository => _repository;
String get path => _path; 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(); _lastSync = DateTime.now();
notifyListeners(); notifyListeners();
} }

View file

@ -12,57 +12,50 @@ class WarbandRoasterScreen extends StatelessWidget {
if (github.lastSync == null) { if (github.lastSync == null) {
return Scaffold( return Scaffold(
appBar: AppBar(title: Text('Toolheim')), appBar: AppBar(title: const Text('Toolheim')),
body: Center( body: Center(child: const Text('Please select a Warband.')),
child: IconButton( drawer: Drawer(
icon: Icon(Icons.search), child: SingleChildScrollView(child: WarbandDrawerWidget())));
color: Colors.black,
tooltip: 'Search for warbands',
onPressed: github.search,
),
));
} }
WarbandRoaster roaster = github.activeRoaster; WarbandRoaster roaster = github.activeRoaster;
return Scaffold( List<Widget> tiles = new List();
appBar: AppBar(
title: Text(roaster.name), 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: subtitle: Text(hero.type),
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];
return ListTile( tiles.add(Divider());
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];
return ListTile( roaster.henchmenGroups.forEach((henchmenGroup) {
title: Text(henchmenGroup.name), tiles.add(new ListTile(
trailing: title: Text(henchmenGroup.name),
Chip(label: Text(henchmenGroup.number.toString() + 'x')), trailing: Chip(label: Text(henchmenGroup.number.toString() + 'x')),
leading: CircleAvatar( leading: CircleAvatar(
child: Text(henchmenGroup.experience.toString()), child: Text(henchmenGroup.experience.toString()),
backgroundColor: Colors.orange, backgroundColor: Colors.orange,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), ),
subtitle: Text(henchmenGroup.type), 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) { if (github.lastSync == null) {
// Add search button // 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; WarbandRoaster activeRoaster = github.activeRoaster;