Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Stress_detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Himali Aryal
Stress_detection
Commits
a881e5c6
Commit
a881e5c6
authored
Apr 9, 2021
by
Daniel Schwietert
Browse files
Options
Downloads
Plain Diff
Merge branch 'diary_entry'
# Conflicts: # lib/main.dart
parents
bbd8fe53
7ef8045d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/main.dart
+15
-23
15 additions, 23 deletions
lib/main.dart
lib/ui/entries/sensor_input.dart
+58
-9
58 additions, 9 deletions
lib/ui/entries/sensor_input.dart
pubspec.lock
+7
-0
7 additions, 0 deletions
pubspec.lock
pubspec.yaml
+1
-0
1 addition, 0 deletions
pubspec.yaml
with
81 additions
and
32 deletions
lib/main.dart
+
15
−
23
View file @
a881e5c6
...
...
@@ -3,12 +3,20 @@ import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:flutter_app/ui/entries/select_page.dart'
;
import
'package:flutter_app/ui/common/slide_up_route.dart'
;
import
'package:workmanager/workmanager.dart'
;
// void callbackDispatcher() {
// Workmanager.executeTask((task, inputData) {
// print("Native called background task: $task");
// return Future.value(true);
// });
// }
void
main
()
=
>
runApp
(
MaterialApp
(
void
main
()
{
runApp
(
MaterialApp
(
home:
Home
(),
));
}
class
Home
extends
StatefulWidget
{
static
const
routeName
=
'home'
;
...
...
@@ -27,8 +35,7 @@ class _HomeState extends State<Home> {
appBar:
AppBar
(
title:
Text
(
'WELCOME TO DIARY ENTRY 😊'
),
centerTitle:
true
,
backgroundColor:
Color
(
0xFF3C4858
)
),
backgroundColor:
Color
(
0xFF3C4858
)),
body:
IndexedStack
(
index:
_currentIndex
,
children:
<
Widget
>[
...
...
@@ -78,21 +85,6 @@ class _HomeState extends State<Home> {
}
}
Future
<
void
>
_startAccelerometer
()
async
{
if
(
_accelSubscription
!=
null
)
return
;
if
(
_accelAvailable
)
{
final
stream
=
await
SensorManager
()
.
sensorUpdates
(
sensorId:
Sensors
.
ACCELEROMETER
,
interval:
Sensors
.
SENSOR_DELAY_FASTEST
,
);
_accelSubscription
=
stream
.
listen
((
sensorEvent
)
{
setState
(()
{
_accelData
=
sensorEvent
.
data
;
});
});
}
}
// import 'package:flutter_app/managers/app_manager.dart';
// import 'package:flutter_app/services/api_service.dart';
// import 'package:flutter_app/view_model/entry.dart';
...
...
This diff is collapsed.
Click to expand it.
lib/ui/entries/sensor_input.dart
+
58
−
9
View file @
a881e5c6
...
...
@@ -4,8 +4,15 @@ import 'package:flutter/material.dart';
import
'package:flutter_sensors/flutter_sensors.dart'
;
import
'package:app_usage/app_usage.dart'
;
import
'package:flutter_spinkit/flutter_spinkit.dart'
;
import
'package:workmanager/workmanager.dart'
;
import
'package:firebase_core/firebase_core.dart'
;
import
'package:firebase_database/firebase_database.dart'
;
class
SensorInput
extends
StatefulWidget
{
SensorInput
({
this
.
app
});
final
FirebaseApp
app
;
static
const
routeName
=
'add-entry'
;
@override
_SensorInputState
createState
()
=
>
_SensorInputState
();
}
...
...
@@ -15,8 +22,8 @@ class _Sensor {
String
unit
;
int
type
;
bool
available
=
false
;
StreamSubscription
stream
=
null
;
List
<
double
>
data
=
null
;
StreamSubscription
stream
;
List
<
double
>
data
;
_Sensor
(
name
,
unit
,
type
)
{
this
.
name
=
name
;
...
...
@@ -43,9 +50,47 @@ class _SensorInputState extends State<SensorInput> {
bool
_measuring
=
false
;
DatabaseReference
_database
;
Timer
timer
;
void
pushData
()
{
for
(
var
sensor
in
_sensors
)
{
if
(
sensor
.
available
)
{
Map
<
String
,
String
>
data
=
{
'sensor'
:
sensor
.
name
,
'value'
:
sensor
.
data
.
toString
()
};
print
(
"Push data: "
+
data
.
toString
());
_database
.
push
()
.
set
(
data
);
}
}
}
@override
void
initState
()
{
_checkSensors
();
_database
=
FirebaseDatabase
.
instance
.
reference
()
.
child
(
'sensor'
);
// Workmanager.initialize(
// pushData, // The top level function, aka callbackDispatcher
// isInDebugMode:
// true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks
// );
// Workmanager.registerPeriodicTask("1", "sensorReadingTask",
// // Minimum frequency is 15 min. Android will automatically change your frequency to 15 min if you have configured a lower frequency.
// frequency: Duration(minutes: 15),
// constraints: Constraints(
// networkType: NetworkType.connected,
// requiresBatteryNotLow: true,
// requiresCharging: false,
// requiresDeviceIdle: false,
// requiresStorageNotLow: false));
super
.
initState
();
}
...
...
@@ -68,23 +113,27 @@ class _SensorInputState extends State<SensorInput> {
interval:
Sensors
.
SENSOR_DELAY_FASTEST
,
);
sensor
.
stream
=
stream
.
listen
((
sensorEvent
)
{
if
(
_measuring
)
setState
(()
{
sensor
.
data
=
sensorEvent
.
data
;
});
});
}
}
timer
=
new
Timer
.
periodic
(
Duration
(
seconds:
10
),
(
Timer
t
)
=
>
pushData
());
}
void
_stopSensors
()
async
{
Future
<
Null
>
_stopSensors
()
async
{
_measuring
=
false
;
await
timer
.
cancel
();
for
(
var
sensor
in
_sensors
)
{
if
(
sensor
.
stream
==
null
)
re
turn
;
sensor
.
stream
.
cancel
();
if
(
sensor
.
stream
==
null
)
b
re
ak
;
await
sensor
.
stream
.
cancel
();
sensor
.
stream
=
null
;
}
;
}
void
_checkSensors
()
async
{
...
...
This diff is collapsed.
Click to expand it.
pubspec.lock
+
7
−
0
View file @
a881e5c6
...
...
@@ -560,6 +560,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.4+1"
workmanager:
dependency: "direct main"
description:
name: workmanager
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.3"
xdg_directories:
dependency: transitive
description:
...
...
This diff is collapsed.
Click to expand it.
pubspec.yaml
+
1
−
0
View file @
a881e5c6
...
...
@@ -44,6 +44,7 @@ dependencies:
flutter_sensors
:
^0.1.6
app_usage
:
^1.2.0
flutter_spinkit
:
"
^4.1.2"
workmanager
:
^0.2.0
dev_dependencies
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment