-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
130 lines (115 loc) · 3.61 KB
/
main.dart
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:guitar_tuner/services/frequency_recorder.dart';
import 'package:guitar_tuner/services/note_tuner.dart';
import 'gui/frequency_deviation_scale/freqeuncy_deviation_scale.dart';
import 'gui/guitar/guitar.dart';
void main() {
// I don't know why but scale in release apk doesn't work
// copied from: https://stackoverflow.com/questions/64552637/how-can-i-solve-flutter-problem-in-release-mode
ErrorWidget.builder = (FlutterErrorDetails details) {
bool inDebug = false;
assert(() {
inDebug = true;
return true;
}());
// In debug mode, use the normal error widget which shows
// the error message:
if (inDebug) return ErrorWidget(details.exception);
// In release builds, show a yellow-on-blue message instead:
return Container(
alignment: Alignment.center,
child: Text(
'Error! ${details.exception}',
style: TextStyle(color: Colors.yellow),
textDirection: TextDirection.ltr,
),
);
};
// Here we would normally runApp() the root widget, but to demonstrate
// the error handling we artificially fail:
runApp(Application());
}
class Application extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MaterialApp(
title: "Guitar Tuner",
debugShowCheckedModeBanner: false,
home: TuneRoute(),
);
}
}
class TuneRoute extends StatefulWidget {
@override
TuneRouteState createState() => TuneRouteState();
}
class TuneRouteState extends State<TuneRoute> {
double _deviationInHz = 0.0;
double _deviationInPercent = 0.0;
String _deviationInText = 'Unknown';
Note _tunningNote = Note.e1;
NoteTuner _noteTuner = NoteTuner();
FrequencyRecorder _frequencyRecorder = FrequencyRecorder();
Function(Note peg) _noteChangedListener;
@override
void initState() {
_noteTuner.frequency = 0.0;
_noteTuner.note = _tunningNote;
_setupDeviation();
_frequencyRecorder.recordPeriod = Duration(milliseconds: 300);
_frequencyRecorder.frequencyChangedListener = (frequency) => setState(() {
_noteTuner.frequency = frequency;
_setupDeviation();
});
_noteChangedListener = (note) => setState(() {
_noteTuner.note = note;
_setupDeviation();
});
super.initState();
}
void _setupDeviation() {
_deviationInHz = _noteTuner.deviationInHz;
_deviationInPercent = _noteTuner.deviationInPercent;
_deviationInText = _noteTuner.deviationIntext;
}
@override
Widget build(BuildContext context) {
const scaleMargin = 37.0;
var statusBarHeight = MediaQuery.of(context).padding.top;
return Scaffold(
body: Container(
color: const Color(0xFFDDDDDDD),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
margin: EdgeInsets.only(
left: scaleMargin,
top: scaleMargin + statusBarHeight,
right: scaleMargin,
),
child: FrequencyDeviationScale(
_deviationInHz,
_deviationInPercent,
_deviationInText,
),
),
Guitar(_noteChangedListener),
],
),
),
);
}
@override
void dispose() {
_frequencyRecorder.dispose();
super.dispose();
}
}