mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
changing ac bloc
This commit is contained in:
@ -3,68 +3,72 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/helper/ac_helper.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/control_list/ac_mode.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/control_list/ac_toggle.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/control_list/current_temp.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class AcDeviceControl extends StatelessWidget with ACHelper {
|
||||
class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
const AcDeviceControl({super.key, required this.device});
|
||||
|
||||
final AllDevicesModel device;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
AcBloc()..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
child: BlocListener<AcBloc, AcsState>(
|
||||
listener: (context, state) {
|
||||
|
||||
create: (context) => AcBloc()..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
child: BlocBuilder<AcBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
if (state is AcsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ACStatusLoaded) {
|
||||
return _buildStatusControls(state.status, isLarge, isMedium);
|
||||
} else {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<AcBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
if (state is AcsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ACStatusLoaded) {
|
||||
return _buildStatusControls(state.status.status);
|
||||
} else {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(List<Status> statuses) {
|
||||
return GridView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 40),
|
||||
Widget _buildStatusControls(
|
||||
AcStatusModel statuses, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: isLarge
|
||||
? 3
|
||||
: isMedium
|
||||
? 2
|
||||
: 1,
|
||||
mainAxisExtent: 133,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: statuses.length,
|
||||
itemBuilder: (context, index) {
|
||||
final status = statuses[index];
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: ColorsManager.greyColor.withOpacity(0.2),
|
||||
border: Border.all(color: ColorsManager.boxDivider),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ACHelperControlWidgets(
|
||||
value: status.value,
|
||||
code: status.code,
|
||||
deviceId: device.uuid!),
|
||||
);
|
||||
},
|
||||
children: [
|
||||
AcToggle(
|
||||
value: statuses.acSwitch,
|
||||
code: 'switch',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
AcMode(
|
||||
value: statuses.acMode,
|
||||
code: 'mode',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
CurrentTemp(
|
||||
currentTemp: statuses.currentTemp,
|
||||
tempSet: statuses.tempSet,
|
||||
code: 'temp_set',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user