Skip to content

Commit

Permalink
Merge pull request #19 from UteSpiske/homepage
Browse files Browse the repository at this point in the history
Implementation of Homepage and change of ColorScheme
  • Loading branch information
andreped authored Feb 2, 2023
2 parents fb8262c + d152ec6 commit 03e49a3
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 54 deletions.
12 changes: 7 additions & 5 deletions sw_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import 'package:flutter/services.dart';
import 'package:wakelock/wakelock.dart';
import 'widgets/home.dart';


Future<void> main() async {
runApp(const MyApp());
}

class MyApp extends StatelessWidget{
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Expand All @@ -21,8 +20,11 @@ class MyApp extends StatelessWidget{
]);
// disable the phone from going into sleep mode while app is running
Wakelock.enable();
return const MaterialApp(
home: Home(),
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightGreenAccent),
),
home: HomePage(),
);
}
}
}
65 changes: 29 additions & 36 deletions sw_app/lib/widgets/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ import 'package:tflite_flutter/tflite_flutter.dart';
import '../utils/math_addons.dart';
import '../utils/constants.dart' as _constants;


class DataStream extends StatefulWidget{
class DataStream extends StatefulWidget {
const DataStream({Key? key}) : super(key: key);

@override
_DataStreamState createState() => _DataStreamState();
}

class _DataStreamState extends State<DataStream> {
double x = 0,
y = 0,
z = 0;
double x = 0, y = 0, z = 0;
int classPred = 0;
String direction = "none";
var input = List<double>.filled(150, 0).reshape([1, 50, 3]);
Expand Down Expand Up @@ -106,6 +103,10 @@ class _DataStreamState extends State<DataStream> {

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var style = theme.textTheme.displaySmall!
.copyWith(color: theme.colorScheme.onSecondary, fontSize: 30);

return Scaffold(
body: Center(
child: Padding(
Expand All @@ -120,48 +121,40 @@ class _DataStreamState extends State<DataStream> {
//alignment: Alignment.center,
//padding: const EdgeInsets.all(30),
width: 380,
//height: 250,
child: Column(
children: [
const Text("\nAccelerometer data:",
style: TextStyle(fontSize: 30, color: Colors.white),),
Text("x: " + x.toStringAsFixed(4),
style: const TextStyle(
fontSize: 30, color: Colors.white),),
Text("y: " + y.toStringAsFixed(4),
style: const TextStyle(
fontSize: 30, color: Colors.white),),
Text("z: " + z.toStringAsFixed(4) + "\n",
style: const TextStyle(
fontSize: 30, color: Colors.white),),
]
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blueGrey
),
color: Colors.blueGrey),
//height: 250,
child: Column(children: [
Text("\nAccelerometer data:", style: style),
Text("x: " + x.toStringAsFixed(4), style: style),
Text(
"y: " + y.toStringAsFixed(4),
style: style,
),
Text(
"z: " + z.toStringAsFixed(4) + "\n",
style: style,
),
]),
),
const SizedBox(
height: 20,
width: 20,
),
Container(
width: 380,
//height: 200,
child: Column(
children: [
Text("\nClass pred: " + classPred.toString(),
style: const TextStyle(
fontSize: 30, color: Colors.white),),
Text("\nFPS: " + fpsValue.toStringAsFixed(1) + "\n",
style: const TextStyle(
fontSize: 30, color: Colors.white),),
]
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.black38
), //BoxDecoration
color: Colors.black38),
//height: 200,
child: Column(children: [
Text("\nClass pred: " + classPred.toString(), style: style),
Text(
"\nFPS: " + fpsValue.toStringAsFixed(1) + "\n",
style: style,
),
]), //BoxDecoration
),
],
),
Expand Down
12 changes: 7 additions & 5 deletions sw_app/lib/widgets/datarecording.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_sensors/flutter_sensors.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:sqflite/sqflite.dart';
import 'dart:math';
import '../utils/datatypes.dart';
import '../utils/constants.dart' as _constants;


class DataRecordingPage extends StatefulWidget {
@override
State<DataRecordingPage> createState() => _DataRecordingPageState();
Expand Down Expand Up @@ -148,9 +148,10 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
makeLineChart(zPoints, _constants.zColor),
ElevatedButton(
onPressed: () {

this.isStarted = !this.isStarted;
this.isStarted ? stream_accelerometer_data() : reset_variables();
this.isStarted
? stream_accelerometer_data()
: reset_variables();

setState(() {});
},
Expand All @@ -159,8 +160,9 @@ class _DataRecordingPageState extends State<DataRecordingPage> {
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
textStyle:
TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
child:
this.isStarted ? Text('Stop recording') : Text('Start Recording'))
child: this.isStarted
? Text('Stop recording')
: Text('Start Recording'))
],
),
);
Expand Down
138 changes: 130 additions & 8 deletions sw_app/lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,152 @@ import 'data.dart';
import 'charts.dart';
import 'datarecording.dart';

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

class Home extends StatelessWidget {
const Home({key});
class HomePage extends StatefulWidget {
HomePage({key});

@override
_HomePageState createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
late TabController _tabController;

@override
void initState() {
super.initState();
_tabController = new TabController(vsync: this, length: 4);
}

@override
void dispose() {
_tabController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {

var style = TextStyle(fontSize: 35, color: Colors.white);

return MaterialApp(
home: DefaultTabController(
length: 3,
length: 4,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
tabs: [
bottom: TabBar(
controller: _tabController,
tabs: const [
Tab(icon: Icon(Icons.home)),
Tab(icon: Icon(Icons.sensors)),
Tab(icon: Icon(Icons.show_chart_rounded)),
Tab(icon: Icon(Icons.access_alarm)),
],
),
title: const Text('DSS: Demo app'),
backgroundColor: Colors.redAccent,
backgroundColor: Theme.of(context).colorScheme.secondary,
),
body: TabBarView(
body: TabBarView(
controller: _tabController,
children: [
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 150, //height of button
width: double.infinity,
child: ElevatedButton(
onPressed: () {
_tabController.animateTo(1);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
),
child: Container(
child: RichText(
text: TextSpan(
text: 'Show AI Model\n ',
style: style,
children: const <TextSpan>[
TextSpan(
text:
'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.',
style: TextStyle(
fontSize: 15, color: Colors.white)),
],
),
textAlign: TextAlign.center),
),
),
),
const SizedBox(
height: 20,
width: 20,
),
SizedBox(
height: 150, //height of button
width: double.infinity,
child: ElevatedButton(
onPressed: () {
_tabController.animateTo(2);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
),
child: Container(
child: RichText(
text: TextSpan(
text: 'Visualize Data\n ',
style: style,
children: const <TextSpan>[
TextSpan(
text:
'Here a real-time chart of the accelerometer values in x, y and z direction, as well as the FPS rate, can be found.',
style: TextStyle(
fontSize: 15, color: Colors.white)),
],
),
textAlign: TextAlign.center),
),
),
),
const SizedBox(
height: 20,
width: 20,
),
SizedBox(
height: 150, //height of button
width: double.infinity,
child: ElevatedButton(
onPressed: () {
_tabController.animateTo(3);
},
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
),
child: Container(
child: RichText(
text: TextSpan(
text: 'Record Data\n ',
style: style,
children: const <TextSpan>[
TextSpan(
text:
'Here the accelerometer data can be recorded and afterward sent to a server. ',
style: TextStyle(
fontSize: 15, color: Colors.white)),
],
),
textAlign: TextAlign.center),
),
),
),
],
)),
const DataStream(),
const Charts(),
DataRecordingPage(),
Expand All @@ -36,4 +159,3 @@ class Home extends StatelessWidget {
);
}
}

6 changes: 6 additions & 0 deletions sw_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ dev_dependencies:
flutter_lints: ^2.0.0
provider: ^6.0.0

#data base storage
sqflite: ^2.0.0+3

#format Date/Time
intl: ^0.17.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down

0 comments on commit 03e49a3

Please sign in to comment.