11import 'package:flutter/material.dart' ;
22import 'package:provider/provider.dart' ;
3+ import 'package:pslab/communication/science_lab.dart' ;
34import 'package:pslab/l10n/app_localizations.dart' ;
45import 'package:pslab/providers/locator.dart' ;
56import 'package:pslab/providers/wave_generator_state_provider.dart' ;
@@ -14,6 +15,8 @@ import 'package:pslab/view/widgets/wave_generator_main_controls.dart';
1415class 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