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'; import 'package:toolheim/screens/settings_screen.dart'; import 'package:url_launcher/url_launcher.dart'; class WarbandDrawerWidget extends StatelessWidget { @override Widget build(BuildContext context) { GitHubAdapter github = Provider.of(context); // No settings at all String settingsText = 'There is no repository set up. Please open the settings and provide a valid GitHub repository.'; // Never fetched any data if (github.activeRoster == null) { settingsText = 'The repository is set, but no warbands are found. Try to search for warbands on the settings screen.'; } if (github.repository == null || github.activeRoster == null) { return Padding( padding: const EdgeInsets.only(top: 100, left: 30, right: 30), child: Column(children: [ Text(settingsText), FlatButton( onPressed: () { Navigator.popAndPushNamed(context, '/settings'); }, child: Text( 'Open Settings', style: TextStyle(color: Colors.blue), ), ), Text( 'If you have no clue what this app is all about, open the help screen and read the introduction.'), FlatButton( onPressed: () async { const url = ''; if (await canLaunch(url)) { await launch(url); } }, child: Text( 'Help', style: TextStyle(color: Colors.blue), ), ), ]), ); } return buildRosterList(context); } Widget buildRosterList(BuildContext context) { GitHubAdapter github = Provider.of(context); WarbandRoster activeroster = github.activeRoster; List rosters = github.rosters; List tiles = []; // Show some stats for the own warband tiles.add(UserAccountsDrawerHeader( margin: const EdgeInsets.all(0), otherAccountsPictures: [ IconButton( icon: Icon(Icons.refresh), color: Colors.white, highlightColor: Colors.brown, tooltip: 'Refresh warbands', onPressed: () async { await github.update(); if (github.syncErrors.length > 0) { List errors = github.syncErrors.map((error) { return Text(error); }).toList(); showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text('We have some errors while updating.'), content: SettingsScreen.buildSyncErrors(context), actions: [ FlatButton(child: Text('Ok'), onPressed: () {}) ]); }); } }), IconButton( icon: Icon(Icons.settings), color: Colors.white, highlightColor: Colors.brown, onPressed: () { Navigator.popAndPushNamed(context, '/settings'); }, ), IconButton( icon: Icon(Icons.help), color: Colors.white, highlightColor: Colors.brown, onPressed: () { Navigator.popAndPushNamed(context, '/help'); }, ), ], accountName: Text(activeroster.name), accountEmail: Text(activeroster.race), )); tiles.add(Visibility( visible: github.isSyncInProgress, child: LinearProgressIndicator())); rosters.forEach((roster) { // We mark inactive warbands with a gray acent var textColor = Colors.black; if (!roster.active) { textColor = Colors.black45; } var fontWeight = FontWeight.normal; if (roster.unseen) { fontWeight = FontWeight.bold; } tiles.add(ListTile( onTap: () { roster.unseen = false; github.activeRoster = roster; Navigator.of(context).pop(); }, title: Text(roster.name + ' (' + roster.playerName + ')', style: TextStyle(color: textColor, fontWeight: fontWeight)), subtitle: Text(roster.version.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); } }