mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
181 lines
8.5 KiB
Dart
181 lines
8.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
|
import 'package:syncrow_web/utils/color_manager.dart';
|
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
|
|
class SaveRoutineHelper {
|
|
static Future<void> showSaveRoutineDialog(BuildContext context) async {
|
|
return showDialog<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
|
builder: (context, state) {
|
|
return AlertDialog(
|
|
contentPadding: EdgeInsets.zero,
|
|
content: Container(
|
|
width: 600,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
DialogHeader('Create a scene: ${state.routineName ?? ""}'),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Left side - IF
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'IF:',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
if (state.isTabToRun)
|
|
ListTile(
|
|
leading: SvgPicture.asset(
|
|
Assets.tabToRun,
|
|
width: 24,
|
|
height: 24,
|
|
),
|
|
title: const Text('Tab to run'),
|
|
),
|
|
if (state.isAutomation)
|
|
...state.ifItems.map((item) {
|
|
final functions =
|
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
|
return ListTile(
|
|
leading: SvgPicture.asset(
|
|
item['imagePath'],
|
|
width: 22,
|
|
height: 22,
|
|
),
|
|
title:
|
|
Text(item['title'], style: const TextStyle(fontSize: 14)),
|
|
subtitle: Wrap(
|
|
children: functions
|
|
.map((f) => Text(
|
|
'${f.operationName}: ${f.value}, ',
|
|
style: const TextStyle(
|
|
color: ColorsManager.grayColor, fontSize: 8),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 3,
|
|
))
|
|
.toList(),
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
// Right side - THEN items
|
|
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'THEN:',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
...state.thenItems.map((item) {
|
|
final functions =
|
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
|
return ListTile(
|
|
leading: item['type'] == 'tap_to_run'
|
|
? Image.memory(
|
|
base64Decode(item['icon']),
|
|
width: 22,
|
|
height: 22,
|
|
)
|
|
: SvgPicture.asset(
|
|
item['imagePath'],
|
|
width: 22,
|
|
height: 22,
|
|
),
|
|
title: Text(
|
|
item['title'],
|
|
style: context.textTheme.bodySmall?.copyWith(
|
|
fontSize: 14,
|
|
color: ColorsManager.grayColor,
|
|
),
|
|
),
|
|
subtitle: Wrap(
|
|
children: functions
|
|
.map((f) => Text(
|
|
'${f.operationName}: ${f.value}, ',
|
|
style: context.textTheme.bodySmall?.copyWith(
|
|
color: ColorsManager.grayColor, fontSize: 8),
|
|
overflow: TextOverflow.ellipsis,
|
|
maxLines: 3,
|
|
))
|
|
.toList(),
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// if (state.errorMessage != null || state.errorMessage!.isNotEmpty)
|
|
// Padding(
|
|
// padding: const EdgeInsets.all(8.0),
|
|
// child: Text(
|
|
// state.errorMessage!,
|
|
// style: const TextStyle(color: Colors.red),
|
|
// ),
|
|
// ),
|
|
DialogFooter(
|
|
onCancel: () => Navigator.pop(context),
|
|
onConfirm: () async {
|
|
if (state.isAutomation) {
|
|
if (state.automationId != null) {
|
|
context.read<RoutineBloc>().add(const UpdateAutomation());
|
|
} else {
|
|
context.read<RoutineBloc>().add(const CreateAutomationEvent());
|
|
}
|
|
} else {
|
|
if (state.sceneId != null) {
|
|
context.read<RoutineBloc>().add(const UpdateScene());
|
|
} else {
|
|
context.read<RoutineBloc>().add(const CreateSceneEvent());
|
|
}
|
|
}
|
|
// if (state.errorMessage == null || state.errorMessage!.isEmpty) {
|
|
Navigator.pop(context);
|
|
// }
|
|
},
|
|
isConfirmEnabled: true,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|