mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
separating folder
This commit is contained in:
@ -1,202 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/counter_widget.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/add_device_model_bloc.dart';
|
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
|
||||||
|
|
||||||
class AddDeviceTypeModelWidget extends StatelessWidget {
|
|
||||||
final List<ProductModel>? products;
|
|
||||||
final ValueChanged<List<SelectedProduct>>? onProductsSelected;
|
|
||||||
final List<SelectedProduct>? initialSelectedProducts;
|
|
||||||
|
|
||||||
const AddDeviceTypeModelWidget({
|
|
||||||
super.key,
|
|
||||||
this.products,
|
|
||||||
this.initialSelectedProducts,
|
|
||||||
this.onProductsSelected,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final size = MediaQuery.of(context).size;
|
|
||||||
final crossAxisCount = size.width > 1200
|
|
||||||
? 8
|
|
||||||
: size.width > 800
|
|
||||||
? 5
|
|
||||||
: 3;
|
|
||||||
|
|
||||||
return BlocProvider(
|
|
||||||
create: (_) => AddDeviceTypeModelBloc(
|
|
||||||
initialSelectedProducts ?? []), // Initialize with initial products
|
|
||||||
child: AlertDialog(
|
|
||||||
title: const Text('Add Devices'),
|
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
|
||||||
content: SingleChildScrollView(
|
|
||||||
child: Container(
|
|
||||||
width: size.width * 0.9,
|
|
||||||
height: size.height * 0.65,
|
|
||||||
color: ColorsManager.textFieldGreyColor,
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
||||||
child: Scrollbar(
|
|
||||||
thumbVisibility: false,
|
|
||||||
child: BlocBuilder<AddDeviceTypeModelBloc, List<SelectedProduct>>(
|
|
||||||
builder: (context, productCounts) {
|
|
||||||
return GridView.builder(
|
|
||||||
shrinkWrap: true,
|
|
||||||
gridDelegate:
|
|
||||||
SliverGridDelegateWithFixedCrossAxisCount(
|
|
||||||
crossAxisCount: crossAxisCount,
|
|
||||||
mainAxisSpacing: 6,
|
|
||||||
crossAxisSpacing: 4,
|
|
||||||
childAspectRatio: .8,
|
|
||||||
),
|
|
||||||
itemCount: products?.length ?? 0,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final product = products![index];
|
|
||||||
return _buildDeviceTypeTile(
|
|
||||||
context, product, size, productCounts);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
_buildActionButton(
|
|
||||||
'Cancel',
|
|
||||||
ColorsManager.boxColor,
|
|
||||||
ColorsManager.blackColor,
|
|
||||||
() => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
_buildActionButton(
|
|
||||||
'Continue',
|
|
||||||
ColorsManager.secondaryColor,
|
|
||||||
ColorsManager.whiteColors,
|
|
||||||
() {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if (onProductsSelected != null) {
|
|
||||||
final selectedProducts =
|
|
||||||
context.read<AddDeviceTypeModelBloc>().state;
|
|
||||||
onProductsSelected!(selectedProducts);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildDeviceTypeTile(BuildContext context, ProductModel product,
|
|
||||||
Size size, List<SelectedProduct> productCounts) {
|
|
||||||
final selectedProduct = productCounts.firstWhere(
|
|
||||||
(p) => p.productId == product.uuid,
|
|
||||||
orElse: () => SelectedProduct(productId: product.uuid, count: 0),
|
|
||||||
);
|
|
||||||
|
|
||||||
return SizedBox(
|
|
||||||
width: size.width * 0.12,
|
|
||||||
height: size.height * 0.15,
|
|
||||||
child: Card(
|
|
||||||
elevation: 2,
|
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
_buildDeviceIcon(product, size),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
_buildDeviceName(context,product, size),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
CounterWidget(
|
|
||||||
initialCount: selectedProduct.count,
|
|
||||||
onCountChanged: (newCount) {
|
|
||||||
context
|
|
||||||
.read<AddDeviceTypeModelBloc>()
|
|
||||||
.updateProductCount(product.uuid, newCount);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildDeviceIcon(ProductModel product, Size size) {
|
|
||||||
return Container(
|
|
||||||
height: size.width > 800 ? 50 : 40,
|
|
||||||
width: size.width > 800 ? 50 : 40,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: ColorsManager.textFieldGreyColor,
|
|
||||||
border: Border.all(
|
|
||||||
color: ColorsManager.neutralGray,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: SvgPicture.asset(
|
|
||||||
product.icon ?? Assets.sensors,
|
|
||||||
width: size.width > 800 ? 30 : 20,
|
|
||||||
height: size.width > 800 ? 30 : 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildDeviceName(BuildContext context, product, Size size) {
|
|
||||||
return SizedBox(
|
|
||||||
height: size.width > 800 ? 35 : 25,
|
|
||||||
child: Text(
|
|
||||||
product.name ?? '',
|
|
||||||
style: Theme.of(context).textTheme.bodySmall
|
|
||||||
?.copyWith(color: ColorsManager.blackColor),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildActionButton(
|
|
||||||
String label,
|
|
||||||
Color backgroundColor,
|
|
||||||
Color foregroundColor,
|
|
||||||
VoidCallback onPressed,
|
|
||||||
) {
|
|
||||||
return SizedBox(
|
|
||||||
width: 120,
|
|
||||||
child: DefaultButton(
|
|
||||||
onPressed: onPressed,
|
|
||||||
backgroundColor: backgroundColor,
|
|
||||||
foregroundColor: foregroundColor,
|
|
||||||
child: Text(label),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac
|
|||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/add_device_type_model_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart';
|
||||||
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/action_button_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/scrollable_grid_view_widget.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class AddDeviceTypeModelWidget extends StatelessWidget {
|
||||||
|
final List<ProductModel>? products;
|
||||||
|
final ValueChanged<List<SelectedProduct>>? onProductsSelected;
|
||||||
|
final List<SelectedProduct>? initialSelectedProducts;
|
||||||
|
|
||||||
|
const AddDeviceTypeModelWidget({
|
||||||
|
super.key,
|
||||||
|
this.products,
|
||||||
|
this.initialSelectedProducts,
|
||||||
|
this.onProductsSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final size = MediaQuery.of(context).size;
|
||||||
|
final crossAxisCount = size.width > 1200
|
||||||
|
? 8
|
||||||
|
: size.width > 800
|
||||||
|
? 5
|
||||||
|
: 3;
|
||||||
|
|
||||||
|
return BlocProvider(
|
||||||
|
create: (_) => AddDeviceTypeModelBloc(initialSelectedProducts ?? []),
|
||||||
|
child: AlertDialog(
|
||||||
|
title: const Text('Add Devices'),
|
||||||
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: Container(
|
||||||
|
width: size.width * 0.9,
|
||||||
|
height: size.height * 0.65,
|
||||||
|
color: ColorsManager.textFieldGreyColor,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||||
|
child: ScrollableGridViewWidget(
|
||||||
|
products: products,
|
||||||
|
crossAxisCount: crossAxisCount,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ActionButton(
|
||||||
|
label: 'Cancel',
|
||||||
|
backgroundColor: ColorsManager.boxColor,
|
||||||
|
foregroundColor: ColorsManager.blackColor,
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
),
|
||||||
|
ActionButton(
|
||||||
|
label: 'Continue',
|
||||||
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (onProductsSelected != null) {
|
||||||
|
final selectedProducts =
|
||||||
|
context.read<AddDeviceTypeModelBloc>().state;
|
||||||
|
onProductsSelected!(selectedProducts);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
|
|
||||||
|
class ActionButton extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final Color backgroundColor;
|
||||||
|
final Color foregroundColor;
|
||||||
|
final VoidCallback onPressed;
|
||||||
|
|
||||||
|
const ActionButton({
|
||||||
|
super.key,
|
||||||
|
required this.label,
|
||||||
|
required this.backgroundColor,
|
||||||
|
required this.foregroundColor,
|
||||||
|
required this.onPressed,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: DefaultButton(
|
||||||
|
onPressed: onPressed,
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
foregroundColor: foregroundColor,
|
||||||
|
child: Text(label),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
class DeviceIconWidget extends StatelessWidget {
|
||||||
|
final String? icon;
|
||||||
|
|
||||||
|
const DeviceIconWidget({
|
||||||
|
super.key,
|
||||||
|
required this.icon,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
height: 50,
|
||||||
|
width: 50,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: ColorsManager.textFieldGreyColor,
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.neutralGray,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
icon ?? Assets.sensors,
|
||||||
|
width: 30,
|
||||||
|
height: 30,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DeviceNameWidget extends StatelessWidget {
|
||||||
|
final String? name;
|
||||||
|
|
||||||
|
const DeviceNameWidget({
|
||||||
|
super.key,
|
||||||
|
required this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
height: 35,
|
||||||
|
child: Text(
|
||||||
|
name ?? '',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.blackColor),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/counter_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_icon_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_name_widget.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
class DeviceTypeTileWidget extends StatelessWidget {
|
||||||
|
final ProductModel product;
|
||||||
|
final List<SelectedProduct> productCounts;
|
||||||
|
|
||||||
|
const DeviceTypeTileWidget({
|
||||||
|
super.key,
|
||||||
|
required this.product,
|
||||||
|
required this.productCounts,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final selectedProduct = productCounts.firstWhere(
|
||||||
|
(p) => p.productId == product.uuid,
|
||||||
|
orElse: () => SelectedProduct(productId: product.uuid, count: 0),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Card(
|
||||||
|
elevation: 2,
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
DeviceIconWidget(icon: product.icon ?? Assets.doorSensor),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
DeviceNameWidget(name: product.name),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
CounterWidget(
|
||||||
|
initialCount: selectedProduct.count,
|
||||||
|
onCountChanged: (newCount) {
|
||||||
|
context
|
||||||
|
.read<AddDeviceTypeModelBloc>()
|
||||||
|
.updateProductCount(product.uuid, newCount);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/device_type_tile_widget.dart';
|
||||||
|
|
||||||
|
class ScrollableGridViewWidget extends StatelessWidget {
|
||||||
|
final List<ProductModel>? products;
|
||||||
|
final int crossAxisCount;
|
||||||
|
|
||||||
|
const ScrollableGridViewWidget({
|
||||||
|
super.key,
|
||||||
|
required this.products,
|
||||||
|
required this.crossAxisCount,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final scrollController = ScrollController();
|
||||||
|
|
||||||
|
return Scrollbar(
|
||||||
|
controller: scrollController,
|
||||||
|
thumbVisibility: true,
|
||||||
|
child: BlocBuilder<AddDeviceTypeModelBloc, List<SelectedProduct>>(
|
||||||
|
builder: (context, productCounts) {
|
||||||
|
return GridView.builder(
|
||||||
|
controller: scrollController,
|
||||||
|
shrinkWrap: true,
|
||||||
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: crossAxisCount,
|
||||||
|
mainAxisSpacing: 6,
|
||||||
|
crossAxisSpacing: 4,
|
||||||
|
childAspectRatio: .8,
|
||||||
|
),
|
||||||
|
itemCount: products?.length ?? 0,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final product = products![index];
|
||||||
|
return DeviceTypeTileWidget(
|
||||||
|
product: product,
|
||||||
|
productCounts: productCounts,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user