working on functions view

This commit is contained in:
ashrafzarkanisala
2024-06-25 10:38:39 +03:00
parent d0ac4a650f
commit 6413d2b876
19 changed files with 405 additions and 196 deletions
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
@@ -6,8 +8,6 @@ part 'create_scene_state.dart';
class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState> {
CreateSceneBloc() : super(CreateSceneInitial()) {
on<CreateSceneEvent>((event, emit) {
// TODO: implement event handler
});
on<CreateSceneEvent>((event, emit) => null as FutureOr<void>);
}
}
@@ -6,3 +6,5 @@ sealed class CreateSceneEvent extends Equatable {
@override
List<Object> get props => [];
}
@@ -8,3 +8,7 @@ sealed class CreateSceneState extends Equatable {
}
final class CreateSceneInitial extends CreateSceneState {}
class CreateSceneLoading extends CreateSceneState {}
@@ -0,0 +1,50 @@
import 'package:syncrow_app/features/devices/model/function_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
mixin SceneHelper {
get lightBulbFunctions => null;
get wallSensorFunctions => null;
get acFunctions => null;
get doorLockFunctions => null;
get curtainFunctions => null;
get threeGangFunctions => null;
get gatewayFunctions => null;
getFunctionsWithIcons(
{DeviceType? type, required List<FunctionModel> functions}) {
switch (type) {
case DeviceType.LightBulb:
return lightBulbFunctions;
case DeviceType.CeilingSensor:
return ceilingSensorFunctions(functions);
case DeviceType.WallSensor:
return wallSensorFunctions;
case DeviceType.AC:
return acFunctions;
case DeviceType.DoorLock:
return doorLockFunctions;
case DeviceType.Curtain:
return curtainFunctions;
case DeviceType.ThreeGang:
return threeGangFunctions;
case DeviceType.Gateway:
return gatewayFunctions;
default:
return lightBulbFunctions;
}
}
ceilingSensorFunctions(List<FunctionModel> functions) {
List<FunctionModel> temp = [];
for (var item in functions) {
}
return temp;
}
}
@@ -0,0 +1,82 @@
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/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/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) {
final device = ModalRoute.of(context)?.settings.arguments as DeviceModel;
// var functions = [];
// if (device.functions.isNotEmpty) {
// functions = getFunctionsWithIcons(
// type: device.productType, functions: device.functions);
// }
return DefaultScaffold(
title: '${device.name} ${StringsManager.functions}',
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: '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,
),
),
trailingWidget: const Icon(
Icons.arrow_forward_ios_rounded,
color: ColorsManager.greyColor,
size: 16,
),
onPressed: () {},
);
},
),
),
);
}
}
+23 -18
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.dart';
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
@@ -34,24 +36,27 @@ class SceneAddTasksView extends StatelessWidget {
],
child: Stack(
children: [
const SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 24,
),
// IF
IFDefaultContainer(),
SizedBox(
height: 8,
),
// THEN
ThenDefaultContainer(),
SizedBox(
height: 100,
),
],
SingleChildScrollView(
child: BlocProvider(
create: (context) => CreateSceneBloc(),
child: const Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(
height: 24,
),
// IF
IFDefaultContainer(),
SizedBox(
height: 8,
),
// THEN
ThenDefaultContainer(),
SizedBox(
height: 100,
),
],
),
),
),
Positioned(
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
import 'package:syncrow_app/features/scene/widgets/bottom_sheet_widget.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
@@ -44,12 +46,16 @@ class ThenDefaultContainer extends StatelessWidget {
padding: EdgeInsets.zero,
),
const LightDivider(),
SceneListTile(
titleString: '+ Add Task',
textAlign: TextAlign.center,
onPressed: () => context.customBottomSheet(
child: const CustomBottomSheetWidget(),
),
BlocBuilder<CreateSceneBloc, CreateSceneState>(
builder: (context, state) {
return SceneListTile(
titleString: '+ Add Task',
textAlign: TextAlign.center,
onPressed: () => context.customBottomSheet(
child: const CustomBottomSheetWidget(),
),
);
},
)
],
),
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart';
import 'package:syncrow_app/features/devices/model/room_model.dart';
@@ -9,7 +10,7 @@ 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/text_widgets/body_large.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
@@ -18,7 +19,7 @@ class SceneDevicesBody extends StatelessWidget {
super.key,
required TabController tabController,
required this.rooms,
}) : _tabController = tabController;
}) : _tabController = tabController;
final TabController _tabController;
final List<RoomModel>? rooms;
@@ -66,23 +67,17 @@ class SceneDevicesBody extends StatelessWidget {
Widget _buildRoomTab(RoomModel room, BuildContext context) {
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
builder: (context, state) {
if (state is GetDevicesLoading) {
if (state.loading && state.devices == null) {
return const Center(child: CircularProgressIndicator());
} else if (state is GetDevicesSuccess) {
} else if (state.devices != null && state.devices!.isNotEmpty) {
return ListView.builder(
itemCount: state.devices?.length ?? 0,
itemCount: state.devices!.length,
itemBuilder: (context, index) {
final device = state.devices![index];
return DefaultContainer(
child: SceneListTile(
minLeadingWidth: 40,
leadingWidget: Image.network(
device.icon ?? '',
errorBuilder: (context, error, stackTrace) => Image.asset(
Assets.assetsIconsLogo,
width: 20,
),
),
leadingWidget: SvgPicture.asset(device.icon ?? ''),
titleWidget: BodyMedium(
text: device.name ?? '',
style: context.titleSmall.copyWith(
@@ -93,20 +88,25 @@ class SceneDevicesBody extends StatelessWidget {
),
trailingWidget: const Icon(
Icons.arrow_forward_ios_rounded,
color: ColorsManager.greyColor,
size: 16,
weight: 0.2,
),
onPressed: () {
Navigator.pushNamed(
context,
Routes.deviceFunctionsRoute,
arguments: device,
);
},
),
);
},
);
} else if (state is GetDevicesError) {
return Center(child: Text(state.error));
} else if (state.error != null) {
return Center(child: Text(state.error!));
} else {
return const SizedBox();
}
return const SizedBox();
},
);
}