Skip to content

Commit 03e49a3

Browse files
authored
Merge pull request #19 from UteSpiske/homepage
Implementation of Homepage and change of ColorScheme
2 parents fb8262c + d152ec6 commit 03e49a3

File tree

5 files changed

+179
-54
lines changed

5 files changed

+179
-54
lines changed

sw_app/lib/main.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import 'package:flutter/services.dart';
44
import 'package:wakelock/wakelock.dart';
55
import 'widgets/home.dart';
66

7-
87
Future<void> main() async {
98
runApp(const MyApp());
109
}
1110

12-
class MyApp extends StatelessWidget{
11+
class MyApp extends StatelessWidget {
1312
const MyApp({Key? key}) : super(key: key);
1413

1514
@override
@@ -21,8 +20,11 @@ class MyApp extends StatelessWidget{
2120
]);
2221
// disable the phone from going into sleep mode while app is running
2322
Wakelock.enable();
24-
return const MaterialApp(
25-
home: Home(),
23+
return MaterialApp(
24+
theme: ThemeData(
25+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightGreenAccent),
26+
),
27+
home: HomePage(),
2628
);
2729
}
28-
}
30+
}

sw_app/lib/widgets/data.dart

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ import 'package:tflite_flutter/tflite_flutter.dart';
55
import '../utils/math_addons.dart';
66
import '../utils/constants.dart' as _constants;
77

8-
9-
class DataStream extends StatefulWidget{
8+
class DataStream extends StatefulWidget {
109
const DataStream({Key? key}) : super(key: key);
1110

1211
@override
1312
_DataStreamState createState() => _DataStreamState();
1413
}
1514

1615
class _DataStreamState extends State<DataStream> {
17-
double x = 0,
18-
y = 0,
19-
z = 0;
16+
double x = 0, y = 0, z = 0;
2017
int classPred = 0;
2118
String direction = "none";
2219
var input = List<double>.filled(150, 0).reshape([1, 50, 3]);
@@ -106,6 +103,10 @@ class _DataStreamState extends State<DataStream> {
106103

107104
@override
108105
Widget build(BuildContext context) {
106+
var theme = Theme.of(context);
107+
var style = theme.textTheme.displaySmall!
108+
.copyWith(color: theme.colorScheme.onSecondary, fontSize: 30);
109+
109110
return Scaffold(
110111
body: Center(
111112
child: Padding(
@@ -120,48 +121,40 @@ class _DataStreamState extends State<DataStream> {
120121
//alignment: Alignment.center,
121122
//padding: const EdgeInsets.all(30),
122123
width: 380,
123-
//height: 250,
124-
child: Column(
125-
children: [
126-
const Text("\nAccelerometer data:",
127-
style: TextStyle(fontSize: 30, color: Colors.white),),
128-
Text("x: " + x.toStringAsFixed(4),
129-
style: const TextStyle(
130-
fontSize: 30, color: Colors.white),),
131-
Text("y: " + y.toStringAsFixed(4),
132-
style: const TextStyle(
133-
fontSize: 30, color: Colors.white),),
134-
Text("z: " + z.toStringAsFixed(4) + "\n",
135-
style: const TextStyle(
136-
fontSize: 30, color: Colors.white),),
137-
]
138-
),
139124
decoration: BoxDecoration(
140125
borderRadius: BorderRadius.circular(10),
141-
color: Colors.blueGrey
142-
),
126+
color: Colors.blueGrey),
127+
//height: 250,
128+
child: Column(children: [
129+
Text("\nAccelerometer data:", style: style),
130+
Text("x: " + x.toStringAsFixed(4), style: style),
131+
Text(
132+
"y: " + y.toStringAsFixed(4),
133+
style: style,
134+
),
135+
Text(
136+
"z: " + z.toStringAsFixed(4) + "\n",
137+
style: style,
138+
),
139+
]),
143140
),
144141
const SizedBox(
145142
height: 20,
146143
width: 20,
147144
),
148145
Container(
149146
width: 380,
150-
//height: 200,
151-
child: Column(
152-
children: [
153-
Text("\nClass pred: " + classPred.toString(),
154-
style: const TextStyle(
155-
fontSize: 30, color: Colors.white),),
156-
Text("\nFPS: " + fpsValue.toStringAsFixed(1) + "\n",
157-
style: const TextStyle(
158-
fontSize: 30, color: Colors.white),),
159-
]
160-
),
161147
decoration: BoxDecoration(
162148
borderRadius: BorderRadius.circular(10),
163-
color: Colors.black38
164-
), //BoxDecoration
149+
color: Colors.black38),
150+
//height: 200,
151+
child: Column(children: [
152+
Text("\nClass pred: " + classPred.toString(), style: style),
153+
Text(
154+
"\nFPS: " + fpsValue.toStringAsFixed(1) + "\n",
155+
style: style,
156+
),
157+
]), //BoxDecoration
165158
),
166159
],
167160
),

sw_app/lib/widgets/datarecording.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_sensors/flutter_sensors.dart';
33
import 'package:fl_chart/fl_chart.dart';
4+
import 'package:sqflite/sqflite.dart';
45
import 'dart:math';
56
import '../utils/datatypes.dart';
67
import '../utils/constants.dart' as _constants;
78

8-
99
class DataRecordingPage extends StatefulWidget {
1010
@override
1111
State<DataRecordingPage> createState() => _DataRecordingPageState();
@@ -148,9 +148,10 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
148148
makeLineChart(zPoints, _constants.zColor),
149149
ElevatedButton(
150150
onPressed: () {
151-
152151
this.isStarted = !this.isStarted;
153-
this.isStarted ? stream_accelerometer_data() : reset_variables();
152+
this.isStarted
153+
? stream_accelerometer_data()
154+
: reset_variables();
154155

155156
setState(() {});
156157
},
@@ -159,8 +160,9 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
159160
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
160161
textStyle:
161162
TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
162-
child:
163-
this.isStarted ? Text('Stop recording') : Text('Start Recording'))
163+
child: this.isStarted
164+
? Text('Stop recording')
165+
: Text('Start Recording'))
164166
],
165167
),
166168
);

sw_app/lib/widgets/home.dart

Lines changed: 130 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,152 @@ import 'data.dart';
33
import 'charts.dart';
44
import 'datarecording.dart';
55

6+
//https://stackoverflow.com/questions/50887790/flutter-changing-the-current-tab-in-tab-bar-view-using-a-button
67

7-
class Home extends StatelessWidget {
8-
const Home({key});
8+
class HomePage extends StatefulWidget {
9+
HomePage({key});
10+
11+
@override
12+
_HomePageState createState() => new _HomePageState();
13+
}
14+
15+
class _HomePageState extends State<HomePage>
16+
with SingleTickerProviderStateMixin {
17+
late TabController _tabController;
18+
19+
@override
20+
void initState() {
21+
super.initState();
22+
_tabController = new TabController(vsync: this, length: 4);
23+
}
24+
25+
@override
26+
void dispose() {
27+
_tabController.dispose();
28+
super.dispose();
29+
}
930

1031
@override
1132
Widget build(BuildContext context) {
33+
34+
var style = TextStyle(fontSize: 35, color: Colors.white);
35+
1236
return MaterialApp(
1337
home: DefaultTabController(
14-
length: 3,
38+
length: 4,
1539
child: Scaffold(
1640
appBar: AppBar(
17-
bottom: const TabBar(
18-
tabs: [
41+
bottom: TabBar(
42+
controller: _tabController,
43+
tabs: const [
44+
Tab(icon: Icon(Icons.home)),
1945
Tab(icon: Icon(Icons.sensors)),
2046
Tab(icon: Icon(Icons.show_chart_rounded)),
2147
Tab(icon: Icon(Icons.access_alarm)),
2248
],
2349
),
2450
title: const Text('DSS: Demo app'),
25-
backgroundColor: Colors.redAccent,
51+
backgroundColor: Theme.of(context).colorScheme.secondary,
2652
),
27-
body: TabBarView(
53+
body: TabBarView(
54+
controller: _tabController,
2855
children: [
56+
Container(
57+
child: Column(
58+
mainAxisAlignment: MainAxisAlignment.center,
59+
crossAxisAlignment: CrossAxisAlignment.center,
60+
children: [
61+
SizedBox(
62+
height: 150, //height of button
63+
width: double.infinity,
64+
child: ElevatedButton(
65+
onPressed: () {
66+
_tabController.animateTo(1);
67+
},
68+
style: ElevatedButton.styleFrom(
69+
backgroundColor: Theme.of(context).colorScheme.primary,
70+
),
71+
child: Container(
72+
child: RichText(
73+
text: TextSpan(
74+
text: 'Show AI Model\n ',
75+
style: style,
76+
children: const <TextSpan>[
77+
TextSpan(
78+
text:
79+
'Here the absolute values of the accelerometer in x, y and z direction can be found, as well as the predicted class und FPS rate.',
80+
style: TextStyle(
81+
fontSize: 15, color: Colors.white)),
82+
],
83+
),
84+
textAlign: TextAlign.center),
85+
),
86+
),
87+
),
88+
const SizedBox(
89+
height: 20,
90+
width: 20,
91+
),
92+
SizedBox(
93+
height: 150, //height of button
94+
width: double.infinity,
95+
child: ElevatedButton(
96+
onPressed: () {
97+
_tabController.animateTo(2);
98+
},
99+
style: ElevatedButton.styleFrom(
100+
backgroundColor: Theme.of(context).colorScheme.primary,
101+
),
102+
child: Container(
103+
child: RichText(
104+
text: TextSpan(
105+
text: 'Visualize Data\n ',
106+
style: style,
107+
children: const <TextSpan>[
108+
TextSpan(
109+
text:
110+
'Here a real-time chart of the accelerometer values in x, y and z direction, as well as the FPS rate, can be found.',
111+
style: TextStyle(
112+
fontSize: 15, color: Colors.white)),
113+
],
114+
),
115+
textAlign: TextAlign.center),
116+
),
117+
),
118+
),
119+
const SizedBox(
120+
height: 20,
121+
width: 20,
122+
),
123+
SizedBox(
124+
height: 150, //height of button
125+
width: double.infinity,
126+
child: ElevatedButton(
127+
onPressed: () {
128+
_tabController.animateTo(3);
129+
},
130+
style: ElevatedButton.styleFrom(
131+
backgroundColor: Theme.of(context).colorScheme.primary,
132+
),
133+
child: Container(
134+
child: RichText(
135+
text: TextSpan(
136+
text: 'Record Data\n ',
137+
style: style,
138+
children: const <TextSpan>[
139+
TextSpan(
140+
text:
141+
'Here the accelerometer data can be recorded and afterward sent to a server. ',
142+
style: TextStyle(
143+
fontSize: 15, color: Colors.white)),
144+
],
145+
),
146+
textAlign: TextAlign.center),
147+
),
148+
),
149+
),
150+
],
151+
)),
29152
const DataStream(),
30153
const Charts(),
31154
DataRecordingPage(),
@@ -36,4 +159,3 @@ class Home extends StatelessWidget {
36159
);
37160
}
38161
}
39-

sw_app/pubspec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ dev_dependencies:
5252
flutter_lints: ^2.0.0
5353
provider: ^6.0.0
5454

55+
#data base storage
56+
sqflite: ^2.0.0+3
57+
58+
#format Date/Time
59+
intl: ^0.17.0
60+
5561
# For information on the generic Dart part of this file, see the
5662
# following page: https://dart.dev/tools/pub/pubspec
5763

0 commit comments

Comments
 (0)