2019-07-10 14:16:13 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2019-07-12 00:30:57 +02:00
|
|
|
import 'package:badges/badges.dart';
|
2019-07-10 14:16:13 +02:00
|
|
|
import 'package:toolheim/data/github_adapter.dart';
|
2019-08-01 00:05:42 +02:00
|
|
|
import 'package:toolheim/screens/settings_screen.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-07-10 14:16:13 +02:00
|
|
|
|
|
|
|
class WarbandDrawerWidget extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
|
|
|
|
|
2019-08-01 00:05:42 +02:00
|
|
|
if (github.repository == null || github.activeRoster == null) {
|
2019-07-12 00:30:57 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 100, left: 30, right: 30),
|
|
|
|
child: Column(children: <Widget>[
|
2019-08-02 00:21:41 +02:00
|
|
|
if (github.activeRoster == null)
|
|
|
|
Text(
|
|
|
|
'The repository is set, but no warbands are found. Try to search for warbands on the settings screen.')
|
|
|
|
else
|
|
|
|
Text(
|
|
|
|
'There is no repository set up. Please open the settings and provide a valid GitHub repository.'),
|
2019-07-12 00:30:57 +02:00
|
|
|
FlatButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.popAndPushNamed(context, '/settings');
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'Open Settings',
|
|
|
|
style: TextStyle(color: Colors.blue),
|
|
|
|
),
|
|
|
|
),
|
2019-07-16 23:37:18 +02:00
|
|
|
Text(
|
2019-08-01 00:05:42 +02:00
|
|
|
'If you have no clue what this app is all about, open the help screen and read the introduction.'),
|
2019-07-16 23:37:18 +02:00
|
|
|
FlatButton(
|
2019-08-02 00:21:41 +02:00
|
|
|
onPressed: openHelpWebsite,
|
2019-07-16 23:37:18 +02:00
|
|
|
child: Text(
|
2019-08-01 00:05:42 +02:00
|
|
|
'Help',
|
2019-07-16 23:37:18 +02:00
|
|
|
style: TextStyle(color: Colors.blue),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-02 00:21:41 +02:00
|
|
|
return Column(children: <Widget>[
|
|
|
|
UserAccountsDrawerHeader(
|
2019-08-11 22:36:56 +02:00
|
|
|
currentAccountPicture: CircleAvatar(
|
|
|
|
child: Text(github.activeRoster.campaignPoints.toString() + ' CP'),
|
|
|
|
),
|
2019-08-02 00:21:41 +02:00
|
|
|
margin: const EdgeInsets.all(0),
|
|
|
|
otherAccountsPictures: <Widget>[
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.refresh),
|
|
|
|
color: Colors.white,
|
|
|
|
highlightColor: Colors.brown,
|
|
|
|
tooltip: 'Refresh warbands',
|
|
|
|
onPressed: () async {
|
|
|
|
await github.update();
|
|
|
|
if (github.syncErrors.length > 0) {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text('We have some errors while updating.'),
|
|
|
|
content: SettingsScreen.buildSyncErrors(context),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(child: Text('Ok'), onPressed: () {})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.settings),
|
2019-08-01 00:05:42 +02:00
|
|
|
color: Colors.white,
|
|
|
|
highlightColor: Colors.brown,
|
2019-08-02 00:21:41 +02:00
|
|
|
onPressed: () {
|
|
|
|
Navigator.popAndPushNamed(context, '/settings');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.help),
|
|
|
|
color: Colors.white,
|
|
|
|
highlightColor: Colors.brown,
|
|
|
|
onPressed: openHelpWebsite),
|
|
|
|
],
|
|
|
|
accountName: Text(github.activeRoster.name),
|
|
|
|
accountEmail: Text(github.activeRoster.race),
|
|
|
|
),
|
|
|
|
if (github.isSyncInProgress) LinearProgressIndicator(),
|
|
|
|
for (var roster in github.rosters)
|
|
|
|
ListTile(
|
|
|
|
onTap: () {
|
|
|
|
roster.unseen = false;
|
|
|
|
github.activeRoster = roster;
|
2019-08-08 20:15:06 +02:00
|
|
|
github.save();
|
2019-08-02 00:21:41 +02:00
|
|
|
Navigator.of(context).pop();
|
2019-07-12 00:30:57 +02:00
|
|
|
},
|
2019-08-02 00:21:41 +02:00
|
|
|
title: Text(roster.name + ' (' + roster.playerName + ')',
|
|
|
|
style: TextStyle(
|
|
|
|
color: !roster.active ? Colors.black45 : Colors.black,
|
|
|
|
fontWeight: roster.unseen ? FontWeight.bold : FontWeight.normal,
|
|
|
|
)),
|
|
|
|
subtitle: Text(roster.version.message),
|
|
|
|
isThreeLine: true,
|
|
|
|
trailing: Badge(
|
|
|
|
badgeColor: Colors.black12,
|
|
|
|
shape: BadgeShape.square,
|
|
|
|
borderRadius: 2,
|
2019-08-11 23:37:12 +02:00
|
|
|
badgeContent: Text(roster.rating().toString(),
|
2019-08-02 00:21:41 +02:00
|
|
|
style: TextStyle(color: Colors.white)),
|
|
|
|
),
|
2019-07-12 00:30:57 +02:00
|
|
|
),
|
2019-08-02 00:21:41 +02:00
|
|
|
]);
|
|
|
|
}
|
2019-07-10 14:16:13 +02:00
|
|
|
|
2019-08-02 00:21:41 +02:00
|
|
|
void openHelpWebsite() async {
|
2019-09-10 23:17:34 +02:00
|
|
|
const url = 'https://aaron-fischer.net/apw';
|
2019-08-02 00:21:41 +02:00
|
|
|
if (await canLaunch(url)) {
|
|
|
|
await launch(url);
|
|
|
|
}
|
2019-07-10 14:16:13 +02:00
|
|
|
}
|
|
|
|
}
|