toolheim/mobile-app/lib/screens/warband_roster_screen.dart
2019-08-11 22:36:56 +02:00

147 lines
5 KiB
Dart

import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:timeago_flutter/timeago_flutter.dart';
import 'package:toolheim/data/github_adapter.dart';
import 'package:toolheim/widgets/stats_widget.dart';
import 'package:toolheim/widgets/warband_drawer_widget.dart';
class WarbandRosterScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
GitHubAdapter github = Provider.of<GitHubAdapter>(context);
if (github.activeRoster == null) {
return Scaffold(
appBar: AppBar(title: const Text('Toolheim')),
body: Builder(builder: (BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset(
'assets/images/heads.png',
width: 250,
),
FlatButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: Text(
'Select a warband',
style: TextStyle(color: Colors.blue),
),
),
]),
);
}),
drawer: Drawer(
child: SingleChildScrollView(child: WarbandDrawerWidget())));
}
return Scaffold(
appBar: AppBar(
title: Text(github.activeRoster.name),
),
drawer: Drawer(
child: Column(children: <Widget>[
Expanded(child: SingleChildScrollView(child: WarbandDrawerWidget())),
Container(
color: Colors.brown,
padding: EdgeInsets.all(10),
child: Align(
alignment: Alignment.bottomLeft,
child: Timeago(
date: github.lastSync,
builder: (_, value) => Text(
'Last sync: ' + value,
style: TextStyle(color: Colors.white),
))))
])),
body: SingleChildScrollView(
child: Column(children: [
for (var hero in github.activeRoster.heros)
ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Row(children: <Widget>[
Text(hero.name,
style: TextStyle(
fontWeight: hero.rules.contains('Leader')
? FontWeight.bold
: FontWeight.normal)),
Text(
'(' + hero.type + ')',
style: TextStyle(fontSize: 10),
)
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(hero.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: hero.hiredSword ? Colors.black : Colors.green,
foregroundColor:
hero.hiredSword ? Colors.grey : Colors.greenAccent,
),
subtitle: StatsWidget(hero.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
),
Divider(),
for (var henchmenGroup in github.activeRoster.henchmenGroups)
ListTile(
title: Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Row(children: <Widget>[
Text(henchmenGroup.name),
Text(
'(' + henchmenGroup.type + ')',
style: TextStyle(fontSize: 10),
),
Spacer(),
Badge(
badgeColor: Colors.black12,
shape: BadgeShape.square,
borderRadius: 2,
badgeContent: Text(henchmenGroup.number.toString() + 'x',
style: TextStyle(color: Colors.white)),
),
]),
),
leading: CircleAvatar(
child: Row(children: <Widget>[
Spacer(),
Text(henchmenGroup.experience.toString(),
style: TextStyle(color: Colors.white)),
Text(
'xp',
style: TextStyle(fontSize: 8),
),
Spacer()
]),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
subtitle: StatsWidget(henchmenGroup.stats),
isThreeLine: true,
onTap: () {
//Navigator.pushNamed(context, '/unit', arguments: hero);
},
),
Divider()
])),
);
}
}