mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Improve loading state handling and in FetchRoutineScenesAutomation
.
This commit is contained in:
@ -8,192 +8,182 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class FetchRoutineScenesAutomation extends StatefulWidget {
|
class FetchRoutineScenesAutomation extends StatelessWidget
|
||||||
const FetchRoutineScenesAutomation({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<FetchRoutineScenesAutomation> createState() => _FetchRoutineScenesState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|
||||||
with HelperResponsiveLayout {
|
with HelperResponsiveLayout {
|
||||||
|
const FetchRoutineScenesAutomation({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return state.isLoading
|
if (state.isLoading) const Center(child: CircularProgressIndicator());
|
||||||
? const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
)
|
|
||||||
: SingleChildScrollView(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"Scenes (Tab to Run)",
|
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Visibility(
|
|
||||||
visible: state.scenes.isNotEmpty,
|
|
||||||
replacement: Text(
|
|
||||||
"No scenes found",
|
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.scenes.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final scene = state.scenes[index];
|
|
||||||
final isLoading = state.loadingSceneId == scene.id;
|
|
||||||
|
|
||||||
return Padding(
|
return SingleChildScrollView(
|
||||||
padding: EdgeInsets.only(
|
child: Padding(
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
),
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
mainAxisSize: MainAxisSize.min,
|
||||||
RoutineViewCard(
|
children: [
|
||||||
isLoading: isLoading,
|
Text(
|
||||||
sceneOnTap: () {
|
"Scenes (Tab to Run)",
|
||||||
context.read<RoutineBloc>().add(
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
SceneTrigger(
|
color: ColorsManager.grayColor,
|
||||||
sceneId: scene.id,
|
fontWeight: FontWeight.bold,
|
||||||
name: scene.name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
status: state.scenes[index].status,
|
|
||||||
communityId: state.scenes[index].communityId,
|
|
||||||
spaceId: state.scenes[index].spaceId,
|
|
||||||
sceneId: state.scenes[index].sceneTuyaId!,
|
|
||||||
automationId: state.scenes[index].id,
|
|
||||||
cardType: 'scenes',
|
|
||||||
spaceName: state.scenes[index].spaceName,
|
|
||||||
onTap: () {
|
|
||||||
BlocProvider.of<RoutineBloc>(context).add(
|
|
||||||
const CreateNewRoutineViewEvent(
|
|
||||||
createRoutineView: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
GetSceneDetails(
|
|
||||||
sceneId: state.scenes[index].id,
|
|
||||||
isTabToRun: true,
|
|
||||||
isUpdate: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
textString: state.scenes[index].name,
|
|
||||||
icon: state.scenes[index].icon ??
|
|
||||||
Assets.logoHorizontal,
|
|
||||||
isFromScenes: true,
|
|
||||||
iconInBytes: state.scenes[index].iconInBytes,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
),
|
||||||
Text(
|
const SizedBox(height: 10),
|
||||||
"Automations",
|
Visibility(
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
visible: state.scenes.isNotEmpty,
|
||||||
color: ColorsManager.grayColor,
|
replacement: Text(
|
||||||
fontWeight: FontWeight.bold,
|
"No scenes found",
|
||||||
),
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
),
|
color: ColorsManager.grayColor,
|
||||||
const SizedBox(height: 3),
|
),
|
||||||
Visibility(
|
),
|
||||||
visible: state.automations.isNotEmpty,
|
child: SizedBox(
|
||||||
replacement: Text(
|
height: 200,
|
||||||
"No automations found",
|
child: ListView.builder(
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
scrollDirection: Axis.horizontal,
|
||||||
color: ColorsManager.grayColor,
|
itemCount: state.scenes.length,
|
||||||
),
|
itemBuilder: (context, index) {
|
||||||
),
|
final scene = state.scenes[index];
|
||||||
child: SizedBox(
|
final isLoading = state.loadingSceneId == scene.id;
|
||||||
height: 200,
|
|
||||||
child: ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.automations.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final isLoading = state.automations
|
|
||||||
.contains(state.automations[index].id);
|
|
||||||
|
|
||||||
return Column(
|
return Padding(
|
||||||
children: [
|
padding: EdgeInsets.only(
|
||||||
Padding(
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
padding: EdgeInsets.only(
|
),
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
child: Column(
|
||||||
),
|
children: [
|
||||||
child: RoutineViewCard(
|
RoutineViewCard(
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
onChanged: (v) {
|
sceneOnTap: () {
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
UpdateAutomationStatus(
|
SceneTrigger(
|
||||||
automationId:
|
sceneId: scene.id,
|
||||||
state.automations[index].id,
|
name: scene.name,
|
||||||
automationStatusUpdate:
|
|
||||||
AutomationStatusUpdate(
|
|
||||||
spaceUuid: state
|
|
||||||
.automations[index].spaceId,
|
|
||||||
isEnable: v,
|
|
||||||
),
|
|
||||||
communityId: state
|
|
||||||
.automations[index].communityId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
status: state.automations[index].status,
|
|
||||||
communityId: '',
|
|
||||||
spaceId: state.automations[index].spaceId,
|
|
||||||
sceneId: '',
|
|
||||||
automationId: state.automations[index].id,
|
|
||||||
cardType: 'automations',
|
|
||||||
spaceName: state.automations[index].spaceName,
|
|
||||||
onTap: () {
|
|
||||||
BlocProvider.of<RoutineBloc>(context).add(
|
|
||||||
const CreateNewRoutineViewEvent(
|
|
||||||
createRoutineView: true,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
context.read<RoutineBloc>().add(
|
},
|
||||||
GetAutomationDetails(
|
status: state.scenes[index].status,
|
||||||
automationId:
|
communityId: state.scenes[index].communityId,
|
||||||
state.automations[index].id,
|
spaceId: state.scenes[index].spaceId,
|
||||||
isAutomation: true,
|
sceneId: state.scenes[index].sceneTuyaId!,
|
||||||
isUpdate: true,
|
automationId: state.scenes[index].id,
|
||||||
),
|
cardType: 'scenes',
|
||||||
);
|
spaceName: state.scenes[index].spaceName,
|
||||||
},
|
onTap: () {
|
||||||
textString: state.automations[index].name,
|
BlocProvider.of<RoutineBloc>(context).add(
|
||||||
icon: state.automations[index].icon ??
|
const CreateNewRoutineViewEvent(
|
||||||
Assets.automation,
|
createRoutineView: true,
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
],
|
context.read<RoutineBloc>().add(
|
||||||
);
|
GetSceneDetails(
|
||||||
},
|
sceneId: state.scenes[index].id,
|
||||||
),
|
isTabToRun: true,
|
||||||
),
|
isUpdate: true,
|
||||||
)
|
),
|
||||||
],
|
);
|
||||||
|
},
|
||||||
|
textString: state.scenes[index].name,
|
||||||
|
icon: state.scenes[index].icon ??
|
||||||
|
Assets.logoHorizontal,
|
||||||
|
isFromScenes: true,
|
||||||
|
iconInBytes: state.scenes[index].iconInBytes,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
const SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
"Automations",
|
||||||
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 3),
|
||||||
|
Visibility(
|
||||||
|
visible: state.automations.isNotEmpty,
|
||||||
|
replacement: Text(
|
||||||
|
"No automations found",
|
||||||
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
height: 200,
|
||||||
|
child: ListView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: state.automations.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final isLoading =
|
||||||
|
state.automations.contains(state.automations[index].id);
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
|
),
|
||||||
|
child: RoutineViewCard(
|
||||||
|
isLoading: isLoading,
|
||||||
|
onChanged: (v) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
UpdateAutomationStatus(
|
||||||
|
automationId: state.automations[index].id,
|
||||||
|
automationStatusUpdate:
|
||||||
|
AutomationStatusUpdate(
|
||||||
|
spaceUuid:
|
||||||
|
state.automations[index].spaceId,
|
||||||
|
isEnable: v,
|
||||||
|
),
|
||||||
|
communityId:
|
||||||
|
state.automations[index].communityId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
status: state.automations[index].status,
|
||||||
|
communityId: '',
|
||||||
|
spaceId: state.automations[index].spaceId,
|
||||||
|
sceneId: '',
|
||||||
|
automationId: state.automations[index].id,
|
||||||
|
cardType: 'automations',
|
||||||
|
spaceName: state.automations[index].spaceName,
|
||||||
|
onTap: () {
|
||||||
|
BlocProvider.of<RoutineBloc>(context).add(
|
||||||
|
const CreateNewRoutineViewEvent(
|
||||||
|
createRoutineView: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
GetAutomationDetails(
|
||||||
|
automationId: state.automations[index].id,
|
||||||
|
isAutomation: true,
|
||||||
|
isUpdate: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
textString: state.automations[index].name,
|
||||||
|
icon: state.automations[index].icon ??
|
||||||
|
Assets.automation,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user