mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
add device type comes from products
This commit is contained in:
@ -1,30 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_type_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/counter_widget.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 AddDeviceWidget extends StatefulWidget {
|
||||
const AddDeviceWidget({super.key});
|
||||
final List<ProductModel>? products;
|
||||
final ValueChanged<Map<String, int>>? onProductsSelected;
|
||||
|
||||
const AddDeviceWidget({super.key, this.products, this.onProductsSelected});
|
||||
|
||||
@override
|
||||
_AddDeviceWidgetState createState() => _AddDeviceWidgetState();
|
||||
}
|
||||
|
||||
// Create a static list of DeviceTypeModel
|
||||
final List<DeviceTypeModel> staticDeviceTypes = [
|
||||
DeviceTypeModel(name: 'Smart Light', icon: Assets.smartLightIcon),
|
||||
DeviceTypeModel(name: 'Presence Sensor', icon: Assets.presenceSensor),
|
||||
DeviceTypeModel(name: '3 Gang Smart switch', icon: Assets.Gang3SwitchIcon),
|
||||
DeviceTypeModel(name: '2 Gang Smart switch', icon: Assets.Gang2SwitchIcon),
|
||||
DeviceTypeModel(name: '1 Gang Smart switch', icon: Assets.Gang1SwitchIcon),
|
||||
DeviceTypeModel(name: 'Smart Door Lock', icon: Assets.DoorLockIcon),
|
||||
DeviceTypeModel(name: 'Smart Gateway', icon: Assets.SmartGatewayIcon)
|
||||
];
|
||||
|
||||
class _AddDeviceWidgetState extends State<AddDeviceWidget> {
|
||||
late ScrollController _scrollController;
|
||||
Map<String, int> productCounts = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollController = ScrollController();
|
||||
|
||||
if (widget.products != null) {
|
||||
for (var product in widget.products!) {
|
||||
productCounts[product.uuid] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Size size = MediaQuery.of(context).size;
|
||||
@ -33,38 +47,41 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
|
||||
title: const Text('Add Devices'),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: Container(
|
||||
width: size.width * 0.65, // Set width for the dialog
|
||||
height: size.height * 0.57, // Set height for the dialog
|
||||
width: size.width * 0.65,
|
||||
height: size.height * 0.57, // Set width for the dialog
|
||||
color: ColorsManager.textFieldGreyColor,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16.0),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20.0), // Add horizontal padding
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 6, // Display 6 items in a row
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 0.7, // Adjust the aspect ratio
|
||||
),
|
||||
itemCount: staticDeviceTypes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final deviceType = staticDeviceTypes[index];
|
||||
return _buildDeviceTypeTile(deviceType);
|
||||
},
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0), // Add horizontal padding
|
||||
child: Scrollbar(
|
||||
controller: _scrollController,
|
||||
thumbVisibility: false,
|
||||
child: GridView.builder(
|
||||
controller: _scrollController,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 6, // Display 6 items in a row
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 0.7, // Adjust the aspect ratio
|
||||
),
|
||||
itemCount: widget.products?.length ?? 0,
|
||||
itemBuilder: (context, index) {
|
||||
final deviceType = widget.products![index];
|
||||
return _buildDeviceTypeTile(deviceType);
|
||||
},
|
||||
),
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment
|
||||
.spaceBetween, // Align cancel to the left and continue to the right
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween, // Align cancel to the left and continue to the right
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 200, // Define a specific width for the button
|
||||
@ -94,42 +111,48 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDeviceTypeTile(DeviceTypeModel deviceType) {
|
||||
Widget _buildDeviceTypeTile(ProductModel? deviceType) {
|
||||
return SizedBox(
|
||||
width: 90,
|
||||
height: 150, // Increase height if needed
|
||||
width: 75,
|
||||
height: 90, // Increase height if needed
|
||||
child: Card(
|
||||
elevation: 2,
|
||||
color: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Fixed height container for the icon
|
||||
Container(
|
||||
height: 70, // Fixed height for the icon
|
||||
height: 80,
|
||||
width: 80,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle, // Make it circular
|
||||
color: ColorsManager.textFieldGreyColor, // Background color of the circle
|
||||
border: Border.all(
|
||||
color: ColorsManager.neutralGray, // Border color
|
||||
width: 2, // Border width
|
||||
),
|
||||
), // Fixed height for the icon
|
||||
child: Center(
|
||||
child: SvgPicture.asset(
|
||||
deviceType.icon,
|
||||
width: 40,
|
||||
height: 40,
|
||||
deviceType?.icon ?? Assets.sensors,
|
||||
width: 45,
|
||||
height: 45,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Fixed height container for the name
|
||||
Container(
|
||||
SizedBox(
|
||||
height: 35, // Fixed height for the text (adjust as needed)
|
||||
child: Text(
|
||||
deviceType.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
deviceType?.name ?? '',
|
||||
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2, // Allow up to 2 lines for long names
|
||||
overflow: TextOverflow.ellipsis, // Handle overflow
|
||||
@ -137,7 +160,21 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// The custom counter widget aligned at the bottom
|
||||
CounterWidget(),
|
||||
CounterWidget(
|
||||
initialCount: 0,
|
||||
onCountChanged: (newCount) {
|
||||
setState(() {
|
||||
if (newCount > 0) {
|
||||
productCounts[deviceType!.uuid] = newCount;
|
||||
} else {
|
||||
productCounts.remove(deviceType!.uuid);
|
||||
}
|
||||
if (widget.onProductsSelected != null) {
|
||||
widget.onProductsSelected!(productCounts);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/add_space_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_space_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/curved_line_painter.dart';
|
||||
@ -15,6 +16,7 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
class CommunityStructureArea extends StatefulWidget {
|
||||
final CommunityModel? selectedCommunity;
|
||||
final SpaceModel? selectedSpace;
|
||||
final List<ProductModel>? products;
|
||||
|
||||
final List<SpaceModel> spaces;
|
||||
final List<Connection> connections;
|
||||
@ -22,6 +24,7 @@ class CommunityStructureArea extends StatefulWidget {
|
||||
CommunityStructureArea({
|
||||
this.selectedCommunity,
|
||||
this.selectedSpace,
|
||||
this.products,
|
||||
required this.spaces,
|
||||
required this.connections,
|
||||
});
|
||||
@ -236,6 +239,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
onCreateSpace: (String name, String icon) {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
|
@ -2,20 +2,34 @@ import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CounterWidget extends StatefulWidget {
|
||||
final int initialCount;
|
||||
final ValueChanged<int> onCountChanged;
|
||||
|
||||
const CounterWidget({
|
||||
Key? key,
|
||||
this.initialCount = 0,
|
||||
required this.onCountChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CounterWidgetState createState() => _CounterWidgetState();
|
||||
}
|
||||
|
||||
class _CounterWidgetState extends State<CounterWidget> {
|
||||
int _counter = 0;
|
||||
late int _counter = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_counter = widget.initialCount;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager
|
||||
.counterBackgroundColor, // Background color for the counter
|
||||
color: ColorsManager.counterBackgroundColor, // Background color for the counter
|
||||
borderRadius: BorderRadius.circular(20), // Rounded corners
|
||||
),
|
||||
child: Row(
|
||||
@ -28,10 +42,11 @@ class _CounterWidgetState extends State<CounterWidget> {
|
||||
setState(() {
|
||||
if (_counter > 0) {
|
||||
_counter--;
|
||||
widget.onCountChanged(_counter);
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Icon(
|
||||
child: const Icon(
|
||||
Icons.remove,
|
||||
color: ColorsManager.spaceColor, // Blue color
|
||||
size: 18, // Icon size
|
||||
@ -52,6 +67,7 @@ class _CounterWidgetState extends State<CounterWidget> {
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_counter++;
|
||||
widget.onCountChanged(_counter);
|
||||
});
|
||||
},
|
||||
child: const Icon(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_structure_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/gradient_canvas_border_widget.dart';
|
||||
@ -11,6 +12,7 @@ class LoadedSpaceView extends StatefulWidget {
|
||||
final SpaceModel? selectedSpace;
|
||||
final ValueChanged<CommunityModel> onCommunitySelected;
|
||||
final ValueChanged<SpaceModel> onSpaceSelected;
|
||||
final List<ProductModel>? products;
|
||||
|
||||
const LoadedSpaceView({
|
||||
Key? key,
|
||||
@ -19,6 +21,7 @@ class LoadedSpaceView extends StatefulWidget {
|
||||
this.selectedSpace,
|
||||
required this.onCommunitySelected,
|
||||
required this.onSpaceSelected,
|
||||
this.products,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -43,6 +46,7 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
||||
selectedSpace: widget.selectedSpace,
|
||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||
connections: [],
|
||||
products: widget.products,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -220,7 +220,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
_selectedCommunityUuid = community.uuid; // Update selected community
|
||||
});
|
||||
print(_selectedSpaceUuid);
|
||||
if (widget.onSpaceSelected != null) {
|
||||
widget.onSpaceSelected!(space);
|
||||
}
|
||||
|
Reference in New Issue
Block a user