stats.dart 8.09 KB
Newer Older
1
2
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
3
4
import 'package:logair_application/logic/data_packet.dart';
import 'package:logair_application/logic/handlers/database_handler.dart';
5
import 'package:logair_application/ui/animation/forward_animation.dart';
6
import 'package:logair_application/ui/base/header.dart';
7
import 'package:logair_application/ui/routes/general_settings.dart';
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
import 'package:logair_application/logic/handlers/bluetooth_le_handler.dart';
import 'package:logair_application/logic/handlers/bluetooth_wake_handler.dart';
import 'package:logair_application/logic/handlers/data_handler.dart';
import 'package:logair_application/logic/handlers/network_handler.dart';

import 'package:logair_application/ui/base_widget.dart';

class StatsView extends StatelessWidget {
  StatsView({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseWidget(
      builder: (context, sizingInfo) => SafeArea(
        child: Scaffold(
          body: Center(
            child: Column(
              children: <Widget>[
                // Carousel
                Expanded(
                  flex: 9,
                  child: BaseWidget(
                    builder: (context, sizingInfo) => Container(
                      width: double.infinity,
                      height: double.infinity,
                      child: Column(
                        children: [
35
                          /// DEBUG START
36
                          RaisedButton(
37
                            onPressed: () => 
Nicolas Richard Walter Boeckh's avatar
Nicolas Richard Walter Boeckh committed
38
                              DatabaseHandler().insertData(DataPacket.fromData(1594212101606, 46.1665322, 5.9047703, 562, 0.0170595515519381, 208, 24.7, 95948.8, 40.6, null, 12, null, 14, ""), 'logair1234'),
39
40
41
                            child: Text('Add to DB'),
                          ),
                          RaisedButton(
42
                            onPressed: () => DatabaseHandler().data.then((value) => print(value.join("\n"))),
43
44
45
                            child: Text('Print DB'),
                          ),
                          RaisedButton(
Nicolas Richard Walter Boeckh's avatar
Nicolas Richard Walter Boeckh committed
46
                            onPressed: () => DatabaseHandler().recreateDB(),
47
                            child: Text('Delete DB'),
48
                          ),
49
50
51
52
                          RaisedButton(
                            onPressed: () => DatabaseHandler().getUnsent(20).then((value) => value.forEach(print)),
                            child: Text('Print unsent'),
                          ),
53
54
55
56
57
58
59
60
61
62
63
64
65
                          RaisedButton(
                            onPressed: () => BTWakeHandler().switchState(),
                            child: Text('Toggle BTLE Service'),
                          ),
                          Spacer( flex: 1, ),
                          RaisedButton(
                            onPressed: () => DataHandler().printLatest(),
                            child: Text('Print Data Set'),
                          ),
                          RaisedButton(
                            onPressed: () => DataHandler().clearData(),
                            child: Text('Clear Data'),
                          ),
66
                          /// DEBUG END
67
                          Spacer( flex: 1, ),
68
                          /// Access the app settings
69
70
71
72
73
74
                          Container(
                            padding: EdgeInsets.all(3),
                            width: 50,
                            height: 50,
                            child: FloatingActionButton(
                              heroTag: "buttonSettings",
75
                              onPressed: () => Navigator.push(context, PopForwardRoute(page: SettingsView())),
76
77
78
79
80
81
                              backgroundColor: Colors.grey[400],
                              child: Icon(
                                Icons.settings
                              )
                            )
                          ),
82
83
84

                          /// Display whether or not the device is connected
                          /// TODO Replace with blinking light
85
86
87
88
89
90
91
92
93
94
95
                          StreamBuilder(
                            stream: BTLEHandler().isDeviceConnected(),
                            initialData: false,
                            builder: (context, snapshot) {
                              final bool value = snapshot.data;
                              if (value)
                                return Text("Connected");
                              else
                                return Text("Not connected");
                            },
                          ),
96
                          Spacer(flex: 1),
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
                          // Display generic database info
                          Container(
                            height: 50,
                            alignment: Alignment.center,
                            width: sizingInfo.localWidgetSize.width,
                            color: Colors.grey[200],
                            child: StreamBuilder(
                              stream: DatabaseHandler().getDBSize() ,
                              initialData: 0,
                              builder: (BuildContext context, AsyncSnapshot snapshot){
                                return Text('Stored ${snapshot.data} packets in DB');
                              },
                            )
                          ),
                          // Display Server connection info (//TODO blinking lights + text)
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
                          Container(
                            height: 50,
                            alignment: Alignment.center,
                            width: sizingInfo.localWidgetSize.width,
                            color: Colors.grey[200],
                            child: Row(
                              children: [
                                Expanded(
                                  flex: 2,
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                        'Last server connection was '
                                      ),
                                      StreamBuilder<DateTime>(
                                        initialData: null,
                                        stream: NetworkHandler().getLastServerConnection(),
                                        builder: (context, snapshot) {
                                          DateTime data = snapshot.data;
                                          return Text('${(data != null) ? DateFormat('kk:mm:ss').format(data) : null}');
                                        },
                                      )
                                    ]
                                  )
                                ),
                                Expanded(
                                  flex: 1,
                                  child: StreamBuilder<int>(
141
                                    stream: DatabaseHandler().getUnsentPacketsLength(),
142
143
144
145
146
147
148
149
150
151
152
153
154
155
                                    initialData: 0,
                                    builder: (context, snapshot) => Text(
                                      'Unsent: ${snapshot.data}'
                                    ),
                                  ),
                                )
                              ],
                            )
                          ),
                        ],
                      )
                    ),
                  ),
                ),
156
                /// Header Widget with battery status
157
158
159
160
161
162
163
164
165
                Expanded(
                  flex: 1,
                  child: Listener(
                    behavior: HitTestBehavior.opaque,
                    onPointerDown: (_) => null,
                    child: GestureDetector(
                      onLongPress: () {
                        Navigator.of(context).pop();
                      },
166
                      child: HeaderWidget()
167
168
169
170
171
172
173
174
175
176
177
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}