Skip to content

Commit 7df4c24

Browse files
AsCressmarcnause
authored andcommitted
feat: added remaining Wave Generator functionality
1 parent 86e4f12 commit 7df4c24

File tree

5 files changed

+151
-66
lines changed

5 files changed

+151
-66
lines changed
9.38 KB
Loading
11 KB
Loading

lib/l10n/app_localizations.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,18 @@ abstract class AppLocalizations {
22062206
/// **'Select axes parallel to ground'**
22072207
String get parallelToGround;
22082208

2209+
/// No description provided for @sharingMessage.
2210+
///
2211+
/// In en, this message translates to:
2212+
/// **'Sharing PSLab Data'**
2213+
String get sharingMessage;
2214+
2215+
/// No description provided for @delete.
2216+
///
2217+
/// In en, this message translates to:
2218+
/// **'Delete'**
2219+
String get delete;
2220+
22092221
/// No description provided for @thermometerTitle.
22102222
///
22112223
/// In en, this message translates to:
@@ -2242,18 +2254,6 @@ abstract class AppLocalizations {
22422254
/// **'Ambient temperature sensor is not available on this device'**
22432255
String get temperatureSensorUnavailableMessage;
22442256

2245-
/// No description provided for @sharingMessage.
2246-
///
2247-
/// In en, this message translates to:
2248-
/// **'Sharing PSLab Data'**
2249-
String get sharingMessage;
2250-
2251-
/// No description provided for @delete.
2252-
///
2253-
/// In en, this message translates to:
2254-
/// **'Delete'**
2255-
String get delete;
2256-
22572257
/// No description provided for @deleteHint.
22582258
///
22592259
/// In en, this message translates to:

lib/l10n/app_localizations_en.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,13 @@ class AppLocalizationsEn extends AppLocalizations {
11351135
@override
11361136
String get parallelToGround => 'Select axes parallel to ground';
11371137

1138+
@override
1139+
String get sharingMessage => 'Sharing PSLab Data';
1140+
1141+
@override
1142+
String get delete => 'Delete';
1143+
1144+
@override
11381145
String get thermometerTitle => 'Thermometer';
11391146

11401147
@override
@@ -1155,12 +1162,6 @@ class AppLocalizationsEn extends AppLocalizations {
11551162
String get temperatureSensorUnavailableMessage =>
11561163
'Ambient temperature sensor is not available on this device';
11571164

1158-
@override
1159-
String get sharingMessage => 'Sharing PSLab Data';
1160-
1161-
@override
1162-
String get delete => 'Delete';
1163-
11641165
@override
11651166
String get deleteHint => 'Are you sure you want to delete this file?';
11661167

lib/view/wave_generator_screen.dart

Lines changed: 132 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
3+
import 'package:pslab/communication/science_lab.dart';
34
import 'package:pslab/l10n/app_localizations.dart';
45
import 'package:pslab/providers/locator.dart';
56
import 'package:pslab/providers/wave_generator_state_provider.dart';
@@ -14,6 +15,8 @@ import 'package:pslab/view/widgets/wave_generator_main_controls.dart';
1415
class WaveGeneratorScreen extends StatefulWidget {
1516
final String sineWaveCircuit = 'assets/images/sin_wave_circuit.png';
1617
final String squareWaveCircuit = 'assets/images/square_wave_circuit.png';
18+
final String oscilloscopeIcon = 'assets/icons/icon_oscilloscope_white.png';
19+
final String logicAnalyzerIcon = 'assets/icons/icon_logic_analyzer_white.png';
1720
const WaveGeneratorScreen({super.key});
1821

1922
@override
@@ -66,20 +69,20 @@ class _WaveGeneratorScreenState extends State<WaveGeneratorScreen> {
6669

6770
@override
6871
Widget build(BuildContext context) {
69-
return SafeArea(
70-
child: MultiProvider(
71-
providers: [
72-
ChangeNotifierProvider<WaveGeneratorStateProvider>(
73-
create: (_) => WaveGeneratorStateProvider(),
74-
),
75-
],
76-
child: Consumer<WaveGeneratorStateProvider>(
77-
builder: (context, provider, _) {
78-
return Stack(
79-
children: [
80-
CommonScaffold(
81-
title: appLocalizations.waveGenerator,
82-
body: Container(
72+
return MultiProvider(
73+
providers: [
74+
ChangeNotifierProvider<WaveGeneratorStateProvider>(
75+
create: (_) => WaveGeneratorStateProvider(),
76+
),
77+
],
78+
child: Consumer<WaveGeneratorStateProvider>(
79+
builder: (context, provider, _) {
80+
return Stack(
81+
children: [
82+
CommonScaffold(
83+
title: appLocalizations.waveGenerator,
84+
body: SafeArea(
85+
child: Container(
8386
margin:
8487
const EdgeInsets.only(left: 8.0, top: 8.0, right: 8.0),
8588
child: Column(
@@ -203,43 +206,124 @@ class _WaveGeneratorScreenState extends State<WaveGeneratorScreen> {
203206
],
204207
),
205208
),
206-
actions: [
207-
IconButton(
208-
icon: Icon(Icons.play_arrow, color: Colors.white),
209-
onPressed: () {},
210-
),
211-
IconButton(
212-
icon: Icon(Icons.save, color: Colors.white),
213-
onPressed: () {},
214-
),
215-
PopupMenuButton<String>(
216-
icon: const Icon(Icons.more_vert, color: Colors.white),
217-
onSelected: (value) {
218-
if (value == appLocalizations.showGuide) {
219-
setState(() {
220-
_showGuide = !_showGuide;
221-
});
209+
),
210+
actions: [
211+
PopupMenuButton<String>(
212+
color: primaryRed,
213+
icon: const Icon(Icons.play_arrow, color: Colors.white),
214+
onSelected: (value) {
215+
if (value == appLocalizations.oscilloscope) {
216+
if (getIt.get<ScienceLab>().isConnected()) {
217+
if (Navigator.canPop(context) &&
218+
ModalRoute.of(context)?.settings.name ==
219+
'/oscilloscope') {
220+
Navigator.popUntil(
221+
context, ModalRoute.withName('/oscilloscope'));
222+
} else {
223+
Navigator.pushNamedAndRemoveUntil(
224+
context,
225+
'/oscilloscope',
226+
(route) => route.isFirst,
227+
);
228+
}
229+
} else {
230+
ScaffoldMessenger.of(context).showSnackBar(
231+
SnackBar(
232+
content: Text(
233+
appLocalizations.notConnected,
234+
),
235+
),
236+
);
222237
}
223-
},
224-
itemBuilder: (BuildContext context) => [
225-
PopupMenuItem<String>(
226-
value: appLocalizations.showGuide,
227-
child: Text(appLocalizations.showGuide),
238+
} else {
239+
if (getIt.get<ScienceLab>().isConnected()) {
240+
if (Navigator.canPop(context) &&
241+
ModalRoute.of(context)?.settings.name ==
242+
'/logicAnalyzer') {
243+
Navigator.popUntil(
244+
context, ModalRoute.withName('/logicAnalyzer'));
245+
} else {
246+
Navigator.pushNamedAndRemoveUntil(
247+
context,
248+
'/logicAnalyzer',
249+
(route) => route.isFirst,
250+
);
251+
}
252+
} else {
253+
ScaffoldMessenger.of(context).showSnackBar(
254+
SnackBar(
255+
content: Text(
256+
appLocalizations.notConnected,
257+
),
258+
),
259+
);
260+
}
261+
}
262+
},
263+
itemBuilder: (BuildContext context) => [
264+
PopupMenuItem<String>(
265+
value: appLocalizations.oscilloscope,
266+
child: ListTile(
267+
dense: true,
268+
leading: Image.asset(
269+
widget.oscilloscopeIcon,
270+
),
271+
title: Text(
272+
appLocalizations.oscilloscope,
273+
style: TextStyle(
274+
color: Colors.white,
275+
),
276+
),
228277
),
229-
],
230-
)
231-
],
232-
),
233-
if (_showGuide)
234-
InstrumentOverviewDrawer(
235-
instrumentName: appLocalizations.waveGenerator,
236-
content: _getWaveGeneratorContent(),
237-
onHide: _hideInstrumentGuide,
278+
),
279+
PopupMenuItem<String>(
280+
value: appLocalizations.logicAnalyzer,
281+
child: ListTile(
282+
dense: true,
283+
leading: Image.asset(
284+
widget.logicAnalyzerIcon,
285+
),
286+
title: Text(
287+
appLocalizations.logicAnalyzer,
288+
style: TextStyle(
289+
color: Colors.white,
290+
),
291+
),
292+
),
293+
),
294+
],
238295
),
239-
],
240-
);
241-
},
242-
),
296+
IconButton(
297+
icon: Icon(Icons.save, color: Colors.white),
298+
onPressed: () {},
299+
),
300+
PopupMenuButton<String>(
301+
icon: const Icon(Icons.more_vert, color: Colors.white),
302+
onSelected: (value) {
303+
if (value == appLocalizations.showGuide) {
304+
setState(() {
305+
_showGuide = !_showGuide;
306+
});
307+
}
308+
},
309+
itemBuilder: (BuildContext context) => [
310+
PopupMenuItem<String>(
311+
value: appLocalizations.showGuide,
312+
child: Text(appLocalizations.showGuide),
313+
),
314+
],
315+
)
316+
],
317+
),
318+
if (_showGuide)
319+
InstrumentOverviewDrawer(
320+
instrumentName: appLocalizations.waveGenerator,
321+
content: _getWaveGeneratorContent(),
322+
onHide: _hideInstrumentGuide,
323+
),
324+
],
325+
);
326+
},
243327
),
244328
);
245329
}

0 commit comments

Comments
 (0)