@@ -4,6 +4,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
44
55import '../gui_adapter/service_adapter.dart' ;
66import '../ui_blocks/app_bloc.dart' ;
7+ import '../ui_blocks/mqtt_bloc.dart' ;
8+ import '../utils.dart' ;
79//import '../ui_blocks/items_bloc.dart';
810
911class ControlPanel extends StatelessWidget {
@@ -34,9 +36,7 @@ class ControlPanel extends StatelessWidget {
3436 children: [
3537 ElevatedButton (
3638 onPressed: () {
37- //context.read<AppBloc>().add(ToggleRunningEvent());
3839 if (state.isRunning) {
39- //context.read<ItemsBloc>().add(ClearItemsEvent());
4040 context.read <AppBloc >().add (StopService ());
4141 ServiceAdapter .instance ()? .stopTimer ();
4242 ServiceAdapter .instance ()? .mqttUnsubscribe (); // via MqttBloc
@@ -49,22 +49,33 @@ class ControlPanel extends StatelessWidget {
4949 child: Text (state.isRunning ? 'Stop' : 'Start' ),
5050 ),
5151
52- Text ('# ${state .counter }' ),
5352
54- // Row(
55- // children: [
56- // Text(state.isServer ? 'Server' : 'Client'),
57- // const SizedBox(width: 8),
58- // Switch(
59- // value: state.isServer,
60- // onChanged: (value) {
61- // context.read<AppBloc>().add(ToggleModeEvent());
62- // },
63- // ),
64- // ],
65- // ),
53+ ElevatedButton (
54+ onPressed: () {
55+ if (state.isRunning) {
56+ if (context.read <MqttBloc >().state.isConnected
57+ && context.read <MqttBloc >().state.isSubscribed) {
58+ ServiceAdapter .instance ()? .stopEsp32 ();
59+ }
60+ else {
61+ showToast (context, "MQTT problems" );
62+ }
63+ // context.read<AppBloc>().add(StopService());
64+ // ServiceAdapter.instance()?.stopTimer();
65+ // ServiceAdapter.instance()?.mqttUnsubscribe(); // via MqttBloc
66+ // ServiceAdapter.instance()?.mqttDisconnect();
67+ }
68+ else {
69+ showToast (context, "Service isn't run" );
70+ // context.read<AppBloc>().add(StartService());
71+ }
72+ },
73+ child: Text ('Stop ESP32-S3' , ),
74+ ),
6675
6776
77+ Text ('# ${state .counter }' ),
78+
6879 ],
6980 ),
7081 ],
0 commit comments