Add some buttons and make the app more sobust
This commit is contained in:
parent
7cf3237ccb
commit
df61398054
4 changed files with 47 additions and 17 deletions
|
@ -1,4 +1,3 @@
|
||||||
import 'dart:collection';
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
@ -54,7 +53,7 @@ class GitHubAdapter {
|
||||||
try {
|
try {
|
||||||
searchResults = jsonDecode(response.body);
|
searchResults = jsonDecode(response.body);
|
||||||
} on FormatException catch (e) {
|
} on FormatException catch (e) {
|
||||||
syncErrors.add('Could not parse GitHub response.');
|
syncErrors.add('Could not parse GitHub response.' + e.toString());
|
||||||
yield {};
|
yield {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +90,7 @@ class GitHubAdapter {
|
||||||
try {
|
try {
|
||||||
commits = jsonDecode(response.body);
|
commits = jsonDecode(response.body);
|
||||||
} on FormatException catch (e) {
|
} on FormatException catch (e) {
|
||||||
syncErrors.add('Could not parse GitHub response.');
|
syncErrors.add('Could not parse GitHub response.' + e.toString());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:toolheim/github_reader.dart';
|
import 'package:toolheim/github_reader.dart';
|
||||||
import 'package:toolheim/warband_roaster.dart';
|
import 'package:toolheim/warband_roaster.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
|
||||||
|
|
||||||
void main() => runApp(Toolheim());
|
void main() => runApp(Toolheim());
|
||||||
|
|
||||||
|
@ -29,22 +26,40 @@ class RoasterWidget extends StatefulWidget {
|
||||||
class _RoasterWidgetState extends State<RoasterWidget> {
|
class _RoasterWidgetState extends State<RoasterWidget> {
|
||||||
// TODO: Read this from SharedPreferences
|
// TODO: Read this from SharedPreferences
|
||||||
String activePlayer = 'Aaron';
|
String activePlayer = 'Aaron';
|
||||||
Future<List<WarbandRoaster>> roasters;
|
|
||||||
GitHubAdapter github = GitHubAdapter(
|
GitHubAdapter github = GitHubAdapter(
|
||||||
'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters');
|
'Labernator/Mordheim', 'Mordheim-BorderTownBurning/Warband Rosters');
|
||||||
|
|
||||||
Future initState() {
|
|
||||||
super.initState();
|
|
||||||
roasters = github.search();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> playerList(List<WarbandRoaster> roasters) {
|
List<Widget> playerList(List<WarbandRoaster> roasters) {
|
||||||
List<Widget> tiles = new List();
|
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
|
// Show some stats for the own warband
|
||||||
tiles.add(UserAccountsDrawerHeader(
|
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),
|
accountName: Text(myWarband.name),
|
||||||
accountEmail: Text(myWarband.race),
|
accountEmail: Text(myWarband.race),
|
||||||
currentAccountPicture: CircleAvatar(
|
currentAccountPicture: CircleAvatar(
|
||||||
|
@ -55,8 +70,15 @@ class _RoasterWidgetState extends State<RoasterWidget> {
|
||||||
// TODO: Order Players on CP or rating
|
// TODO: Order Players on CP or rating
|
||||||
|
|
||||||
roasters.forEach((roaster) {
|
roasters.forEach((roaster) {
|
||||||
|
// We mark inactive warbands with a gray acent
|
||||||
|
var textColor = Colors.black;
|
||||||
|
if (!roaster.active) {
|
||||||
|
textColor = Colors.black45;
|
||||||
|
}
|
||||||
|
|
||||||
tiles.add(ListTile(
|
tiles.add(ListTile(
|
||||||
title: Text(roaster.name + ' (' + roaster.playerName + ')'),
|
title: Text(roaster.name + ' (' + roaster.playerName + ')',
|
||||||
|
style: TextStyle(color: textColor)),
|
||||||
subtitle: Text(roaster.currentVersion.message),
|
subtitle: Text(roaster.currentVersion.message),
|
||||||
isThreeLine: true,
|
isThreeLine: true,
|
||||||
trailing: Chip(
|
trailing: Chip(
|
||||||
|
@ -88,14 +110,17 @@ class _RoasterWidgetState extends State<RoasterWidget> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Replace with router
|
// TODO: Replace with router
|
||||||
WarbandRoaster warband = roasters.first;
|
WarbandRoaster warband = roasters.firstWhere((roaster) {
|
||||||
|
return roaster.playerName == this.activePlayer;
|
||||||
|
});
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(warband.name),
|
title: Text(warband.name),
|
||||||
),
|
),
|
||||||
drawer: Drawer(
|
drawer: Drawer(
|
||||||
child: Column(children: playerList(roasters)),
|
child: SingleChildScrollView(
|
||||||
|
child: Column(children: playerList(roasters))),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemCount:
|
itemCount:
|
||||||
|
|
|
@ -174,6 +174,8 @@ class WarbandRoaster {
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
String race;
|
String race;
|
||||||
|
|
||||||
|
bool active;
|
||||||
|
|
||||||
@JsonKey(name: 'campaign')
|
@JsonKey(name: 'campaign')
|
||||||
final int campaignPoints;
|
final int campaignPoints;
|
||||||
|
|
||||||
|
@ -190,9 +192,13 @@ class WarbandRoaster {
|
||||||
|
|
||||||
/// The players name is not defined in the yml file. This will be added later
|
/// The players name is not defined in the yml file. This will be added later
|
||||||
/// from the GitHubAdapter.
|
/// from the GitHubAdapter.
|
||||||
|
@JsonKey(ignore: true)
|
||||||
String playerName = 'Lonely Recluse';
|
String playerName = 'Lonely Recluse';
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
Version lastSyncVersion;
|
Version lastSyncVersion;
|
||||||
|
|
||||||
|
@JsonKey(ignore: true)
|
||||||
Version currentVersion;
|
Version currentVersion;
|
||||||
|
|
||||||
WarbandRoaster(
|
WarbandRoaster(
|
||||||
|
|
|
@ -41,5 +41,5 @@ WarbandRoaster _$WarbandRoasterFromJson(Map json) {
|
||||||
(json['henchmen'] as List)
|
(json['henchmen'] as List)
|
||||||
?.map((e) => e == null ? null : HenchmenGroup.fromJson(e))
|
?.map((e) => e == null ? null : HenchmenGroup.fromJson(e))
|
||||||
?.toList())
|
?.toList())
|
||||||
..playerName = json['playerName'] as String;
|
..active = json['active'] as bool;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue