Skip to content

Commit

Permalink
change colors
Browse files Browse the repository at this point in the history
  • Loading branch information
o-bagge committed Dec 12, 2023
1 parent 4ea79a1 commit 7d1a07e
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 184 deletions.
69 changes: 35 additions & 34 deletions open_earable/lib/apps/posture_tracker/view/posture_roll_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,45 @@ class PostureRollView extends StatelessWidget {
final String neckAssetPath;
final AlignmentGeometry headAlignment;

const PostureRollView({Key? key,
required this.roll,
this.angleThreshold = 0,
required this.headAssetPath,
required this.neckAssetPath,
this.headAlignment = Alignment.center}) : super(key: key);
const PostureRollView(
{Key? key,
required this.roll,
this.angleThreshold = 0,
required this.headAssetPath,
required this.neckAssetPath,
this.headAlignment = Alignment.center})
: super(key: key);

@override
Widget build(BuildContext context) {
return Column(children: [
Text(
"${(this.roll * 180 / 3.14).abs().toStringAsFixed(0)}°",
style: TextStyle(
// use proper color matching the background
color: Theme.of(context).colorScheme.onBackground,
fontSize: 30,
fontWeight: FontWeight.bold
)
),
Text("${(this.roll * 180 / 3.14).abs().toStringAsFixed(0)}°",
style: TextStyle(
// use proper color matching the background
color: Theme.of(context).colorScheme.onBackground,
fontSize: 30,
fontWeight: FontWeight.bold)),
CustomPaint(
painter: ArcPainter(angle: this.roll, angleThreshold: this.angleThreshold),
child: Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
color: roll.abs() > _MAX_ROLL ? Colors.red.withOpacity(0.5) : Colors.transparent,
child: Stack(children: [
Image.asset(this.neckAssetPath),
Transform.rotate(
angle: this.roll.isFinite ? roll.abs() < _MAX_ROLL ? this.roll : roll.sign * _MAX_ROLL : 0,
alignment: this.headAlignment,
child: Image.asset(this.headAssetPath)
),
])
)
)
)
),
painter:
ArcPainter(angle: this.roll, angleThreshold: this.angleThreshold),
child: Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
child: Container(
color: roll.abs() > _MAX_ROLL
? Colors.red.withOpacity(0.5)
: Colors.transparent,
child: Stack(children: [
Image.asset(this.neckAssetPath),
Transform.rotate(
angle: this.roll.isFinite
? roll.abs() < _MAX_ROLL
? this.roll
: roll.sign * _MAX_ROLL
: 0,
alignment: this.headAlignment,
child: Image.asset(this.headAssetPath)),
]))))),
]);
}
}
}
103 changes: 55 additions & 48 deletions open_earable/lib/apps/posture_tracker/view/posture_tracker_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:provider/provider.dart';

import 'package:open_earable_flutter/src/open_earable_flutter.dart';


class PostureTrackerView extends StatefulWidget {
final AttitudeTracker _tracker;
final OpenEarable _openEarable;
Expand All @@ -25,41 +24,41 @@ class _PostureTrackerViewState extends State<PostureTrackerView> {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<PostureTrackerViewModel>(
create: (context) => PostureTrackerViewModel(widget._tracker, BadPostureReminder(widget._openEarable, widget._tracker)),
create: (context) => PostureTrackerViewModel(widget._tracker,
BadPostureReminder(widget._openEarable, widget._tracker)),
builder: (context, child) => Consumer<PostureTrackerViewModel>(
builder: (context, postureTrackerViewModel, child) => Scaffold(
appBar: AppBar(
title: const Text("Posture Tracker"),
actions: [
IconButton(
onPressed: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) => SettingsView(postureTrackerViewModel))),
icon: Icon(Icons.settings)
),
],
),
body: Center(
child: this._buildContentView(postureTrackerViewModel),
),
)
)
);
builder: (context, postureTrackerViewModel, child) => Scaffold(
appBar: AppBar(
title: const Text("Posture Tracker"),
actions: [
IconButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
SettingsView(postureTrackerViewModel))),
icon: Icon(Icons.settings)),
],
),
body: Center(
child: this._buildContentView(postureTrackerViewModel),
),
backgroundColor: Theme.of(context).colorScheme.background,
)));
}

Widget _buildContentView(PostureTrackerViewModel postureTrackerViewModel) {
var headViews = this._createHeadViews(postureTrackerViewModel);
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
...headViews.map((e) => FractionallySizedBox(
widthFactor: .7,
child: e,
)),
this._buildTrackingButton(postureTrackerViewModel),
]
);
return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
...headViews.map((e) => FractionallySizedBox(
widthFactor: .7,
child: e,
)),
this._buildTrackingButton(postureTrackerViewModel),
]);
}

Widget _buildHeadView(String headAssetPath, String neckAssetPath, AlignmentGeometry headAlignment, double roll, double angleThreshold) {
Widget _buildHeadView(String headAssetPath, String neckAssetPath,
AlignmentGeometry headAlignment, double roll, double angleThreshold) {
return Padding(
padding: const EdgeInsets.all(5),
child: PostureRollView(
Expand All @@ -75,33 +74,41 @@ class _PostureTrackerViewState extends State<PostureTrackerView> {
List<Widget> _createHeadViews(postureTrackerViewModel) {
return [
this._buildHeadView(
"assets/posture_tracker/Head_Front.png",
"assets/posture_tracker/Neck_Front.png",
Alignment.center.add(Alignment(0, 0.3)),
postureTrackerViewModel.attitude.roll,
postureTrackerViewModel.badPostureSettings.rollAngleThreshold.toDouble()
),
"assets/posture_tracker/Head_Front.png",
"assets/posture_tracker/Neck_Front.png",
Alignment.center.add(Alignment(0, 0.3)),
postureTrackerViewModel.attitude.roll,
postureTrackerViewModel.badPostureSettings.rollAngleThreshold
.toDouble()),
this._buildHeadView(
"assets/posture_tracker/Head_Side.png",
"assets/posture_tracker/Neck_Side.png",
Alignment.center.add(Alignment(0, 0.3)),
-postureTrackerViewModel.attitude.pitch,
postureTrackerViewModel.badPostureSettings.pitchAngleThreshold.toDouble()
),
"assets/posture_tracker/Head_Side.png",
"assets/posture_tracker/Neck_Side.png",
Alignment.center.add(Alignment(0, 0.3)),
-postureTrackerViewModel.attitude.pitch,
postureTrackerViewModel.badPostureSettings.pitchAngleThreshold
.toDouble()),
];
}

Widget _buildTrackingButton(PostureTrackerViewModel postureTrackerViewModel) {
return Column(children: [
ElevatedButton(
onPressed: postureTrackerViewModel.isAvailable
? () { postureTrackerViewModel.isTracking ? postureTrackerViewModel.stopTracking() : postureTrackerViewModel.startTracking(); }
: null,
? () {
postureTrackerViewModel.isTracking
? postureTrackerViewModel.stopTracking()
: postureTrackerViewModel.startTracking();
}
: null,
style: ElevatedButton.styleFrom(
backgroundColor: !postureTrackerViewModel.isTracking ? Color(0xff77F2A1) : Color(0xfff27777),
foregroundColor: Colors.black,
),
child: postureTrackerViewModel.isTracking ? const Text("Stop Tracking") : const Text("Start Tracking"),
backgroundColor: !postureTrackerViewModel.isTracking
? Color(0xff77F2A1)
: Color(0xfff27777),
foregroundColor: Colors.black,
),
child: postureTrackerViewModel.isTracking
? const Text("Stop Tracking")
: const Text("Start Tracking"),
),
Visibility(
visible: !postureTrackerViewModel.isAvailable,
Expand Down
Loading

0 comments on commit 7d1a07e

Please sign in to comment.