81 lines
2.5 KiB
Dart
81 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart' as prefix0;
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:toolheim/WarbandRoaster.dart';
|
|
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> {
|
|
Future<WarbandRoaster> roaster;
|
|
|
|
static Future<WarbandRoaster> fetchWarband() async {
|
|
final String urlPath = 'https://raw.githubusercontent.com/Labernator/Mordheim/master/Mordheim-BorderTownBurning/Warband%20Rosters/Aaron/aaron.mordheim.yml';
|
|
http.Response response = await http.get(urlPath);
|
|
YamlMap yamlObject = loadYaml(response.body);
|
|
return WarbandRoaster.fromJson(yamlObject);
|
|
}
|
|
|
|
void initState() {
|
|
super.initState();
|
|
roaster = fetchWarband();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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),
|
|
);
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
}
|