toolheim/mobile-app/lib/main.dart

81 lines
2.5 KiB
Dart
Raw Normal View History

2019-06-24 00:53:43 +02:00
import 'package:flutter/material.dart';
2019-06-25 00:53:45 +02:00
import 'package:flutter/material.dart' as prefix0;
2019-06-24 00:53:43 +02:00
import 'package:http/http.dart' as http;
2019-06-25 00:53:45 +02:00
import 'package:toolheim/WarbandRoaster.dart';
2019-06-24 00:53:43 +02:00
import 'package:yaml/yaml.dart';
void main() => runApp(Toolheim());
class Toolheim extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Toolheim',
theme: ThemeData(
primarySwatch: Colors.brown,
accentColor: Colors.grey,
),
home: RoasterWidget(),
);
}
}
class RoasterWidget extends StatefulWidget {
@override
_RoasterWidgetState createState() => _RoasterWidgetState();
}
class _RoasterWidgetState extends State<RoasterWidget> {
2019-06-25 00:53:45 +02:00
Future<WarbandRoaster> roaster;
2019-06-24 00:53:43 +02:00
2019-06-25 00:53:45 +02:00
static Future<WarbandRoaster> fetchWarband() async {
final String urlPath = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Aaron/aaron.mordheim.yml';
2019-06-24 00:53:43 +02:00
http.Response response = await http.get(urlPath);
YamlMap yamlObject = loadYaml(response.body);
2019-06-25 00:53:45 +02:00
return WarbandRoaster.fromJson(yamlObject);
2019-06-24 00:53:43 +02:00
}
void initState() {
super.initState();
2019-06-25 00:53:45 +02:00
roaster = fetchWarband();
2019-06-24 00:53:43 +02:00
}
@override
Widget build(BuildContext context) {
2019-06-25 00:53:45 +02:00
return FutureBuilder(
future: roaster,
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
case ConnectionState.active:
return Center(child: CircularProgressIndicator());
case ConnectionState.done:
WarbandRoaster roaster = snapshot.data;
return Scaffold(
appBar: AppBar(
title: Text(roaster.name),
),
body: ListView.builder(
itemCount: roaster.heros.length,
itemBuilder: (BuildContext context, int index) {
var hero = roaster.heros[index];
return ListTile(
title: Text(hero.name),
leading: CircleAvatar(
child: Text(hero.experience.toString()),
backgroundColor: Colors.green,
foregroundColor: Colors.greenAccent,
),
subtitle: Text(hero.type),
);
}
)
);
}
}
2019-06-24 00:53:43 +02:00
);
}
}