/
main.dart
89 lines (83 loc) · 2.08 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter/material.dart';
import 'tests.dart';
import 'echo_server.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void runTests() async {
await startTestServer();
tests.forEach((t) {
t.passed = null;
});
setState(() {});
for (var t in tests) {
await t.run();
setState(() {});
}
await stopTestServer();
}
void runTest(Test t) async {
await startTestServer();
t.passed = null;
setState(() {});
await t.run();
setState(() {});
await stopTestServer();
}
String get title {
int success = 0;
int fail = 0;
int stopped = 0;
tests.forEach((e) {
if (e.passed == true) success++;
if (e.passed == false) fail++;
if (e.passed == null) stopped++;
});
return "Success: $success, Fail: $fail, Stopped: $stopped";
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
appBar: AppBar(title: Text(title)),
body: ListView.builder(
itemCount: tests.length,
itemBuilder: (_, i) {
return ListTile(
onTap: () async {
runTest(tests[i]);
},
leading: {
null: Icon(Icons.more_horiz),
true: Icon(
Icons.check_circle_outline,
color: Colors.green,
),
false: Icon(
Icons.remove_circle,
color: Colors.red,
)
}[tests[i].passed],
title: Text(tests[i].title),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () => runTests(),
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}