Add some buttons and make the app more sobust

This commit is contained in:
Aaron Fischer 2019-07-09 23:43:57 +02:00
parent 7cf3237ccb
commit df61398054
4 changed files with 47 additions and 17 deletions

View file

@ -1,4 +1,3 @@
import 'dart:collection';
import 'dart:convert';
import 'package:http/http.dart' as http;
@ -54,7 +53,7 @@ class GitHubAdapter {
try {
searchResults = jsonDecode(response.body);
} on FormatException catch (e) {
syncErrors.add('Could not parse GitHub response.');
syncErrors.add('Could not parse GitHub response.' + e.toString());
yield {};
return;
}
@ -91,7 +90,7 @@ class GitHubAdapter {
try {
commits = jsonDecode(response.body);
} on FormatException catch (e) {
syncErrors.add('Could not parse GitHub response.');
syncErrors.add('Could not parse GitHub response.' + e.toString());
continue;
}

View file

@ -1,9 +1,6 @@
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());
@ -29,22 +26,40 @@ class RoasterWidget extends StatefulWidget {
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;
WarbandRoaster myWarband = roasters.firstWhere((roaster) {
return roaster.playerName == activePlayer;
});
// Show some stats for the own warband
tiles.add(UserAccountsDrawerHeader(
otherAccountsPictures: <Widget>[
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(
@ -55,8 +70,15 @@ class _RoasterWidgetState extends State<RoasterWidget> {
// 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 + ')'),
title: Text(roaster.name + ' (' + roaster.playerName + ')',
style: TextStyle(color: textColor)),
subtitle: Text(roaster.currentVersion.message),
isThreeLine: true,
trailing: Chip(
@ -88,14 +110,17 @@ class _RoasterWidgetState extends State<RoasterWidget> {
}
// TODO: Replace with router
WarbandRoaster warband = roasters.first;
WarbandRoaster warband = roasters.firstWhere((roaster) {
return roaster.playerName == this.activePlayer;
});
return Scaffold(
appBar: AppBar(
title: Text(warband.name),
),
drawer: Drawer(
child: Column(children: playerList(roasters)),
child: SingleChildScrollView(
child: Column(children: playerList(roasters))),
),
body: ListView.builder(
itemCount:

View file

@ -174,6 +174,8 @@ class WarbandRoaster {
@JsonKey(ignore: true)
String race;
bool active;
@JsonKey(name: 'campaign')
final int campaignPoints;
@ -190,9 +192,13 @@ class WarbandRoaster {
/// The players name is not defined in the yml file. This will be added later
/// from the GitHubAdapter.
@JsonKey(ignore: true)
String playerName = 'Lonely Recluse';
@JsonKey(ignore: true)
Version lastSyncVersion;
@JsonKey(ignore: true)
Version currentVersion;
WarbandRoaster(

View file

@ -41,5 +41,5 @@ WarbandRoaster _$WarbandRoasterFromJson(Map json) {
(json['henchmen'] as List)
?.map((e) => e == null ? null : HenchmenGroup.fromJson(e))
?.toList())
..playerName = json['playerName'] as String;
..active = json['active'] as bool;
}