push functions static data

This commit is contained in:
ashrafzarkanisala
2024-06-26 02:18:15 +03:00
parent 6413d2b876
commit 3ddd4ed197
34 changed files with 1044 additions and 120 deletions

View File

@ -1,82 +1,124 @@
import 'package:flutter/material.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/scene/helper/scene_helper.dart';
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
import 'package:syncrow_app/features/scene/widgets/alert_dialog_functions_body.dart';
import 'package:syncrow_app/features/scene/widgets/alert_dialog_temperature_body.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
import 'package:syncrow_app/features/shared_widgets/light_divider.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';
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
class DeviceFunctionsView extends StatelessWidget with SceneHelper {
const DeviceFunctionsView({super.key});
@override
Widget build(BuildContext context) {
/// this whole widget i need to revamp it later
///
/// static functions based on type
final device = ModalRoute.of(context)?.settings.arguments as DeviceModel;
// var functions = [];
// if (device.functions.isNotEmpty) {
// functions = getFunctionsWithIcons(
// type: device.productType, functions: device.functions);
// }
/// static custom functions based on type
/// used for now until later backend fixes
List<SceneStaticFunction> functions = [];
if (device.functions.isNotEmpty) {
functions = getFunctionsWithIcons(
type: device.productType, functions: device.functions);
}
return DefaultScaffold(
title: '${device.name} ${StringsManager.functions}',
actions: [
TextButton(
onPressed: () {},
title: getTitle(type: device.productType),
actions: [
TextButton(
onPressed: () {},
child: BodyMedium(
text: 'Save',
fontWeight: FontWeight.normal,
fontColor: ColorsManager.secondaryColor.withOpacity(0.6),
),
),
],
leading: TextButton(
onPressed: () => Navigator.pop(context),
child: BodyMedium(
text: 'Save',
text: 'Cancel',
fontWeight: FontWeight.normal,
fontColor: ColorsManager.secondaryColor.withOpacity(0.6),
fontColor: ColorsManager.textPrimaryColor.withOpacity(0.6),
),
),
],
leading: TextButton(
onPressed: () => Navigator.pop(context),
child: BodyMedium(
text: 'Cancel',
fontWeight: FontWeight.normal,
fontColor: ColorsManager.textPrimaryColor.withOpacity(0.6),
),
),
leadingWidth: 80,
padding: EdgeInsets.zero,
child: DefaultContainer(
margin: const EdgeInsets.only(top: 24),
child: ListView.builder(
shrinkWrap: true,
itemCount: device.functions.length,
itemBuilder: (context, index) {
final function = device.functions[index];
return SceneListTile(
assetPath: null,
minLeadingWidth: 40,
leadingWidget: Image.asset(
Assets.assetsIconsLogo,
width: 20,
),
titleWidget: BodyMedium(
text: function.code ?? '',
style: context.titleSmall.copyWith(
color: ColorsManager.secondaryTextColor,
fontWeight: FontWeight.w400,
fontSize: 15,
leadingWidth: 80,
padding: EdgeInsets.zero,
child: Padding(
padding: const EdgeInsets.only(top: 24.0),
child: ListView.builder(
shrinkWrap: true,
itemCount: functions.length,
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
return DefaultContainer(
padding: index == 0
? const EdgeInsets.only(top: 8)
: index == functions.length - 1
? const EdgeInsets.only(bottom: 8)
: EdgeInsets.zero,
margin: EdgeInsets.zero,
borderRadius: index == 0
? const BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20))
: index == functions.length - 1
? const BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20))
: BorderRadius.zero,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SceneListTile(
iconsSize: 32,
minLeadingWidth: 20,
assetPath: functions[index].icon,
titleString: functions[index].name,
trailingWidget: const Row(
mainAxisSize: MainAxisSize.min,
children: [
/// selected value or the default value
// BodyMedium(text: ),
Icon(
Icons.arrow_forward_ios_rounded,
color: ColorsManager.greyColor,
size: 16,
),
],
),
onPressed: () {
context.customAlertDialog(
alertBody: functions[index].code == 'temp_set'
? AlertDialogTemperatureBody(
index: index, functions: functions)
: AlertDialogFunctionsOperationsBody(
index: index, functions: functions),
title: functions[index].name,
onConfirm: () {},
);
},
),
index != functions.length - 1
? SizedBox(
width: context.width * 0.8,
child: const LightDivider())
: const SizedBox(),
],
),
),
trailingWidget: const Icon(
Icons.arrow_forward_ios_rounded,
color: ColorsManager.greyColor,
size: 16,
),
onPressed: () {},
);
},
),
),
);
);
},
),
));
}
}