Fixed the three gang performance issue

This commit is contained in:
Abdullah Alassaf
2024-07-14 02:01:36 +03:00
parent ce2f419828
commit a67fd44f32
3 changed files with 206 additions and 128 deletions
@@ -4,7 +4,6 @@ import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_blo
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
import 'package:syncrow_app/features/devices/model/group_three_gang_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
@@ -18,78 +17,71 @@ class ThreeGangList extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<ThreeGangBloc, ThreeGangState>(
builder: (context, state) {
return state is LoadingNewSate
? const Center(
child: DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
)
: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 10),
const BodySmall(text: 'All Lights'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: allSwitches,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOnEvent());
},
secondAction: () {
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOffEvent());
},
),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: threeGangList.length,
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} beside light'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].firstSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(
ChangeFirstSwitchStatusEvent(
value: threeGangList[index].firstSwitch,
deviceId: threeGangList[index].deviceId));
},
),
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} ceiling light'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].secondSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(
ChangeSecondSwitchStatusEvent(
value: threeGangList[index].secondSwitch,
deviceId: threeGangList[index].deviceId));
},
),
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} spotlight'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].thirdSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(
ChangeThirdSwitchStatusEvent(
value: threeGangList[index].thirdSwitch,
deviceId: threeGangList[index].deviceId));
},
),
],
);
},
),
],
),
);
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 10),
const BodySmall(text: 'All Lights'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: allSwitches,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOnEvent());
},
secondAction: () {
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOffEvent());
},
),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: threeGangList.length,
itemBuilder: (context, index) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} beside light'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].firstSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(ChangeFirstSwitchStatusEvent(
value: threeGangList[index].firstSwitch,
deviceId: threeGangList[index].deviceId));
},
),
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} ceiling light'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].secondSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(ChangeSecondSwitchStatusEvent(
value: threeGangList[index].secondSwitch,
deviceId: threeGangList[index].deviceId));
},
),
const SizedBox(height: 10),
BodySmall(text: '${threeGangList[index].deviceName} spotlight'),
const SizedBox(height: 5),
DevicesDefaultSwitch(
switchValue: threeGangList[index].thirdSwitch,
action: () {
BlocProvider.of<ThreeGangBloc>(context).add(ChangeThirdSwitchStatusEvent(
value: threeGangList[index].thirdSwitch,
deviceId: threeGangList[index].deviceId));
},
),
],
);
},
),
],
),
);
},
);
}