Refactor routine_view_card.dart to adjust the size o

This commit is contained in:
mohammad
2025-04-07 16:22:21 +03:00
parent d264409d29
commit 6bd9fb7e4e
2 changed files with 168 additions and 146 deletions

View File

@ -31,7 +31,8 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
? const Center( ? const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
) )
: Padding( : SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0), padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -46,20 +47,17 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
if (state.scenes.isEmpty) if (state.scenes.isEmpty)
Expanded( Text(
child: Text(
"No scenes found", "No scenes found",
style: context.textTheme.bodyMedium?.copyWith( style: context.textTheme.bodyMedium?.copyWith(
color: ColorsManager.grayColor, color: ColorsManager.grayColor,
), ),
), ),
),
if (state.scenes.isNotEmpty) if (state.scenes.isNotEmpty)
ConstrainedBox( SizedBox(
constraints: BoxConstraints( height: 200,
maxHeight: isSmallScreenSize(context) ? 190 : 200,
maxWidth: MediaQuery.sizeOf(context).width * 0.8),
child: ListView.builder( child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: state.scenes.length, itemCount: state.scenes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
@ -69,9 +67,12 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
return Padding( return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: isSmallScreenSize(context) ? 4.0 : 8.0, right:
isSmallScreenSize(context) ? 4.0 : 8.0,
), ),
child: RoutineViewCard( child: Column(
children: [
RoutineViewCard(
isLoading: isLoading, isLoading: isLoading,
sceneOnTap: () { sceneOnTap: () {
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
@ -81,20 +82,25 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
}, },
status: state.scenes[index].status, status: state.scenes[index].status,
communityId: communityId:
state.scenes[index].communityId ?? '', state.scenes[index].communityId ??
'',
spaceId: state.scenes[index].spaceId, spaceId: state.scenes[index].spaceId,
sceneId: state.scenes[index].sceneTuyaId!, sceneId:
state.scenes[index].sceneTuyaId!,
automationId: state.scenes[index].id, automationId: state.scenes[index].id,
cardType: 'scenes', cardType: 'scenes',
spaceName: state.scenes[index].spaceName, spaceName:
state.scenes[index].spaceName,
onTap: () { onTap: () {
BlocProvider.of<RoutineBloc>(context).add( BlocProvider.of<RoutineBloc>(context)
.add(
const CreateNewRoutineViewEvent( const CreateNewRoutineViewEvent(
createRoutineView: true), createRoutineView: true),
); );
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
GetSceneDetails( GetSceneDetails(
sceneId: state.scenes[index].id, sceneId:
state.scenes[index].id,
isTabToRun: true, isTabToRun: true,
isUpdate: true, isUpdate: true,
), ),
@ -104,7 +110,10 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
icon: state.scenes[index].icon ?? icon: state.scenes[index].icon ??
Assets.logoHorizontal, Assets.logoHorizontal,
isFromScenes: true, isFromScenes: true,
iconInBytes: state.scenes[index].iconInBytes, iconInBytes:
state.scenes[index].iconInBytes,
),
],
), ),
); );
}), }),
@ -119,78 +128,89 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
), ),
const SizedBox(height: 3), const SizedBox(height: 3),
if (state.automations.isEmpty) if (state.automations.isEmpty)
Expanded( Text(
child: Text(
"No automations found", "No automations found",
style: context.textTheme.bodyMedium?.copyWith( style: context.textTheme.bodyMedium?.copyWith(
color: ColorsManager.grayColor, color: ColorsManager.grayColor,
), ),
), ),
),
if (state.automations.isNotEmpty) if (state.automations.isNotEmpty)
ConstrainedBox( SizedBox(
constraints: BoxConstraints( height: 200,
maxHeight: isSmallScreenSize(context) ? 190 : 195,
),
child: ListView.builder( child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: state.automations.length, itemCount: state.automations.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final isLoading = state.automations! final isLoading = state.automations!
.contains(state.automations[index].id); .contains(state.automations[index].id);
return Padding( return Column(
children: [
Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: isSmallScreenSize(context) ? 4.0 : 8.0, right: isSmallScreenSize(context)
? 4.0
: 8.0,
), ),
child: RoutineViewCard( child: RoutineViewCard(
isLoading: isLoading, isLoading: isLoading,
onChanged: (v) { onChanged: (v) {
// BlocProvider.of<RoutineBloc>(context)
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
UpdateAutomationStatus( UpdateAutomationStatus(
automationId: automationId: state
state.automations[index].id, .automations[index].id,
automationStatusUpdate: automationStatusUpdate:
AutomationStatusUpdate( AutomationStatusUpdate(
spaceUuid: state spaceUuid: state
.automations[index] .automations[
index]
.spaceId, .spaceId,
isEnable: v), isEnable: v),
communityId: state communityId: state
.automations[index].communityId, .automations[index]
.communityId,
), ),
); );
}, },
status: state.automations[index].status, status: state.automations[index].status,
communityId: '', communityId: '',
spaceId: state.automations[index].spaceId, spaceId:
state.automations[index].spaceId,
sceneId: '', sceneId: '',
automationId: state.automations[index].id, automationId:
state.automations[index].id,
cardType: 'automations', cardType: 'automations',
spaceName: state.scenes[index].spaceName, spaceName:
state.scenes[index].spaceName,
onTap: () { onTap: () {
BlocProvider.of<RoutineBloc>(context).add( BlocProvider.of<RoutineBloc>(context)
.add(
const CreateNewRoutineViewEvent( const CreateNewRoutineViewEvent(
createRoutineView: true), createRoutineView: true),
); );
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
GetAutomationDetails( GetAutomationDetails(
automationId: automationId: state
state.automations[index].id, .automations[index].id,
isAutomation: true, isAutomation: true,
isUpdate: true), isUpdate: true),
); );
}, },
textString: state.automations[index].name, textString:
state.automations[index].name,
icon: state.automations[index].icon ?? icon: state.automations[index].icon ??
Assets.automation, Assets.automation,
), ),
),
],
); );
}), }),
), ),
], ],
), ),
),
); );
}, },
); );

View File

@ -177,6 +177,8 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
: (widget.icon is String && : (widget.icon is String &&
widget.icon.endsWith('.svg')) widget.icon.endsWith('.svg'))
? SvgPicture.asset( ? SvgPicture.asset(
height: iconSize,
width: iconSize,
widget.icon, widget.icon,
fit: BoxFit.contain, fit: BoxFit.contain,
) )