156 lines
4.5 KiB
Dart
156 lines
4.5 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:badges/badges.dart';
|
|
import 'package:toolheim/data/github_adapter.dart';
|
|
import 'package:toolheim/data/warband_roster.dart';
|
|
|
|
class WarbandDrawerWidget extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
|
|
|
|
// No settings at all
|
|
if (github.repository == null) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 100, left: 30, right: 30),
|
|
child: Column(children: <Widget>[
|
|
Text(
|
|
'There is no repository set up. Please open the settings and provide a valid GitHub repository.'),
|
|
FlatButton(
|
|
onPressed: () {
|
|
Navigator.popAndPushNamed(context, '/settings');
|
|
},
|
|
child: Text(
|
|
'Open Settings',
|
|
style: TextStyle(color: Colors.blue),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
// Never fetched any data
|
|
if (github.activeRoster() == null) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 100, left: 30, right: 30),
|
|
child: Column(children: <Widget>[
|
|
Text(
|
|
'The repository is set. You can now search for warbands. This can take a while.'),
|
|
FlatButton(
|
|
onPressed: () {
|
|
github.search();
|
|
},
|
|
child: Text(
|
|
'Search for warbands',
|
|
style: TextStyle(color: Colors.blue),
|
|
),
|
|
),
|
|
FlatButton(
|
|
onPressed: () {
|
|
Navigator.popAndPushNamed(context, '/settings');
|
|
},
|
|
child: Text(
|
|
'Change settings',
|
|
style: TextStyle(color: Colors.blue),
|
|
),
|
|
),
|
|
Visibility(
|
|
visible: github.isSyncInProgress,
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
Visibility(
|
|
visible: github.syncErrors.length > 0,
|
|
child: buildSyncErrors(context),
|
|
)
|
|
]),
|
|
);
|
|
}
|
|
|
|
return buildRosterList(context);
|
|
}
|
|
|
|
Widget buildSyncErrors(BuildContext context) {
|
|
List<Widget> syncErrors = new List();
|
|
|
|
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
|
|
// TODO: Make it pretty
|
|
github.syncErrors.forEach((error) {
|
|
syncErrors.add(Text(error, style: TextStyle(color: Colors.red)));
|
|
});
|
|
|
|
return Column(children: syncErrors);
|
|
}
|
|
|
|
Widget buildRosterList(BuildContext context) {
|
|
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
|
|
WarbandRoster activeroster = github.activeRoster();
|
|
List<WarbandRoster> rosters = github.rosters;
|
|
|
|
List<Widget> tiles = new List();
|
|
|
|
tiles.add(Visibility(
|
|
visible: github.isSyncInProgress, child: LinearProgressIndicator()));
|
|
|
|
// Show some stats for the own warband
|
|
tiles.add(UserAccountsDrawerHeader(
|
|
otherAccountsPictures: <Widget>[
|
|
IconButton(
|
|
icon: Icon(Icons.refresh),
|
|
color: Colors.white,
|
|
highlightColor: Colors.brown,
|
|
tooltip: 'Refresh warbands',
|
|
onPressed: github.update,
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.search),
|
|
color: Colors.white,
|
|
tooltip: 'Read warbands',
|
|
onPressed: github.search,
|
|
),
|
|
IconButton(
|
|
icon: Icon(Icons.settings),
|
|
color: Colors.white,
|
|
highlightColor: Colors.brown,
|
|
onPressed: () {
|
|
Navigator.popAndPushNamed(context, '/settings');
|
|
},
|
|
),
|
|
],
|
|
accountName: Text(activeroster.name),
|
|
accountEmail: Text(activeroster.race),
|
|
));
|
|
|
|
rosters.forEach((roster) {
|
|
// We mark inactive warbands with a gray acent
|
|
var textColor = Colors.black;
|
|
if (!roster.active) {
|
|
textColor = Colors.black45;
|
|
}
|
|
|
|
tiles.add(ListTile(
|
|
onTap: () {
|
|
github.changeActiveRoster(roster.playerName);
|
|
Navigator.of(context).pop();
|
|
},
|
|
title: Text(roster.name + ' (' + roster.playerName + ')',
|
|
style: TextStyle(color: textColor)),
|
|
subtitle: Text(roster.currentVersion.message),
|
|
isThreeLine: true,
|
|
trailing: Badge(
|
|
badgeColor: Colors.black12,
|
|
shape: BadgeShape.square,
|
|
borderRadius: 2,
|
|
badgeContent: Text(roster.campaignPoints.toString() + ' CP',
|
|
style: TextStyle(color: Colors.white)),
|
|
),
|
|
));
|
|
});
|
|
|
|
tiles.add(Divider());
|
|
|
|
return Column(children: tiles);
|
|
}
|
|
}
|