push dialog changes in values

This commit is contained in:
ashrafzarkanisala
2024-07-28 05:04:57 +03:00
parent 0bda828161
commit 50b455b4ae
18 changed files with 645 additions and 33 deletions
@@ -67,7 +67,9 @@ class CustomBottomSheetWidget extends StatelessWidget {
size: 16,
color: ColorsManager.greyColor,
),
onPressed: () {},
onPressed: () {
Navigator.pushNamed(context, Routes.smartAutomationSelectRoute);
},
),
SceneListTile(
assetPath: Assets.delay,
@@ -0,0 +1,260 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class SmartSceneSelectAutomationList extends StatefulWidget {
const SmartSceneSelectAutomationList({
super.key,
required this.automationList,
});
final List<ScenesModel> automationList;
@override
State<SmartSceneSelectAutomationList> createState() =>
_SmartSceneSelectAutomationListState();
}
class _SmartSceneSelectAutomationListState
extends State<SmartSceneSelectAutomationList> {
final List<Color> colorList = _generateDarkColors(100);
static List<Color> _generateDarkColors(int count) {
final random = Random();
final colors = <Color>[];
while (colors.length < count) {
final color =
Color((random.nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
if (_isDark(color)) {
colors.add(color);
}
}
return colors;
}
static bool _isDark(Color color) {
final brightness =
((color.red * 299) + (color.green * 587) + (color.blue * 114)) / 1000;
return brightness < 128;
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: BodyMedium(
text: 'Automation',
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
const Divider(
color: ColorsManager.dividerColor,
),
Expanded(
child: BlocBuilder<SmartSceneSelectBloc, SmartSceneSelectState>(
builder: (context, state) {
final smartSceneEnable = ((state is SmartSceneSelected))
? state.smartSceneEnable
: context.read<SmartSceneSelectBloc>().smartSceneEnable;
return ListView.builder(
shrinkWrap: true,
itemCount: widget.automationList.length,
itemBuilder: (context, index) {
final automation = widget.automationList[index];
final isSelected =
smartSceneEnable?.entityId == automation.id;
final descriptionSelected = isSelected
? (smartSceneEnable?.actionExecutor == 'rule_enable'
? 'Enable'
: 'Disable')
: automation.status == 'enable'
? 'Enable'
: 'Disable';
return SceneListTile(
padding: const EdgeInsets.symmetric(horizontal: 10),
leadingWidget: CircleAvatar(
backgroundColor: colorList[index % colorList.length],
radius: 15,
child: Text(
index.toString(),
style: context.bodyMedium.copyWith(color: Colors.white),
),
),
titleString: automation.name,
trailingWidget: TextButton.icon(
iconAlignment: IconAlignment.end,
onPressed: () {
context.customAlertDialog(
alertBody: EnableDisableAutomationDialog(
automationId: automation.id,
descriptionSelected: descriptionSelected,
),
title: automation.name,
onConfirm: () {
Navigator.pop(context);
},
onDismiss: () {
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
Navigator.pop(context);
},
);
},
label: BodyMedium(
text: _capitalizeFirst(descriptionSelected),
style: context.bodyMedium
.copyWith(color: ColorsManager.greyColor),
),
icon: const Icon(
Icons.arrow_forward_ios_rounded,
color: ColorsManager.greyColor,
size: 14,
),
style: const ButtonStyle(
padding: WidgetStatePropertyAll(EdgeInsets.zero),
),
),
onPressed: () {
context.customAlertDialog(
alertBody: EnableDisableAutomationDialog(
automationId: automation.id,
descriptionSelected: descriptionSelected,
),
title: automation.name,
onConfirm: () {
Navigator.pop(context);
},
onDismiss: () {
context
.read<SmartSceneSelectBloc>()
.add(const SmartSceneClearEvent());
Navigator.pop(context);
},
);
},
);
},
);
},
),
),
],
);
}
String _capitalizeFirst(String description) {
if (description.isEmpty) return description;
return '${description[0].toUpperCase()}${description.substring(1)}';
}
}
class EnableDisableAutomationDialog extends StatefulWidget {
const EnableDisableAutomationDialog({
super.key,
required this.automationId,
required this.descriptionSelected,
});
final String automationId;
final String descriptionSelected;
@override
State<EnableDisableAutomationDialog> createState() =>
_EnableDisableAutomationDialogState();
}
class _EnableDisableAutomationDialogState
extends State<EnableDisableAutomationDialog> {
String? groupValue;
final List<SceneOperationalValue> values = [
SceneOperationalValue(
icon: Assets.assetsAcPower,
description: 'Enable',
value: 'rule_enable',
),
SceneOperationalValue(
icon: Assets.assetsAcPowerOFF,
description: 'Disable',
value: 'rule_disable',
),
];
@override
void initState() {
super.initState();
groupValue =
widget.descriptionSelected == 'Enable' ? 'rule_enable' : 'rule_disable';
}
@override
Widget build(BuildContext context) {
return BlocBuilder<SmartSceneSelectBloc, SmartSceneSelectState>(
builder: (context, state) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
...values.map(
(operation) => SceneListTile(
iconsSize: 25,
minLeadingWidth: 15,
padding: const EdgeInsets.symmetric(horizontal: 16),
assetPath: operation.icon,
assetHeaderValue: operation.iconValue,
titleString: operation.description.toString(),
textAlign: TextAlign.start,
trailingWidget: Radio(
value: operation.value,
groupValue: groupValue,
onChanged: (value) {
setState(() {
groupValue = value;
});
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: value!,
),
));
},
),
onPressed: () {
setState(() {
groupValue = operation.value;
});
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(
SmartSceneEnable(
entityId: widget.automationId,
actionExecutor: operation.value,
),
));
},
),
),
],
);
},
);
}
}
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_automation_list.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/context_extension.dart';
class SmartEnableAutomation extends StatelessWidget {
const SmartEnableAutomation({super.key});
@override
Widget build(BuildContext context) {
return DefaultContainer(
height: context.height * 0.5,
width: double.infinity,
child: BlocBuilder<SceneBloc, SceneState>(
bloc: context.read<SceneBloc>()
..add(
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
builder: (context, state) {
if (state is SceneLoading) {
return const Align(
alignment: Alignment.topCenter,
child: LinearProgressIndicator());
}
if (state is SceneLoaded) {
return SmartSceneSelectAutomationList(
automationList: state.automationList);
}
return const SizedBox.shrink();
},
),
);
}
}
@@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_tab_run_list.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/context_extension.dart';
class SmartEnableTabRun extends StatelessWidget {
const SmartEnableTabRun({super.key});
@override
Widget build(BuildContext context) {
return DefaultContainer(
height: context.height * 0.5,
width: double.infinity,
child: BlocBuilder<SceneBloc, SceneState>(
bloc: context.read<SceneBloc>()
..add(LoadScenes(HomeCubit.getInstance().selectedSpace?.id ?? '')),
builder: (context, state) {
if (state is SceneLoading) {
return const Align(
alignment: Alignment.topCenter,
child: LinearProgressIndicator());
}
if (state is SceneLoaded) {
return SmartSceneSelectTabToRunList(scenes: state.scenes);
}
return const SizedBox.shrink();
},
),
);
}
}
@@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class SmartSceneSelectTabToRunList extends StatefulWidget {
const SmartSceneSelectTabToRunList({
super.key,
required this.scenes,
});
final List<ScenesModel> scenes;
@override
State<SmartSceneSelectTabToRunList> createState() =>
_SmartSceneSelectTabToRunListState();
}
class _SmartSceneSelectTabToRunListState
extends State<SmartSceneSelectTabToRunList> {
String groupValue = '';
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: BodyMedium(
text: 'Tab To Run',
style: context.bodyMedium.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold),
),
),
const Divider(
color: ColorsManager.dividerColor,
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: widget.scenes.length,
itemBuilder: (context, index) {
final scene = widget.scenes[index];
return SceneListTile(
padding: const EdgeInsets.symmetric(horizontal: 10),
leadingWidget: Image.asset(
height: 32,
width: 32,
Assets.assetsIconsLogo,
fit: BoxFit.fill,
),
titleString: scene.name,
trailingWidget: Radio(
value: scene.id,
groupValue: groupValue,
onChanged: (String? value) {
if (value != null) {
setState(() {
groupValue = value;
});
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(SmartSceneEnable(
entityId: scene.id,
actionExecutor: 'rule_enable',
)));
}
}),
onPressed: () {
setState(() {
groupValue = scene.id;
});
context
.read<SmartSceneSelectBloc>()
.add(SmartSceneEnableEvent(SmartSceneEnable(
entityId: scene.id,
actionExecutor: 'rule_enable',
)));
},
);
}),
),
],
);
}
}