mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
111 lines
3.6 KiB
Dart
111 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
|
|
class AllDevices extends StatefulWidget {
|
|
const AllDevices({super.key, required this.allDevices});
|
|
|
|
final List<DeviceModel> allDevices;
|
|
|
|
@override
|
|
_AllDevicesState createState() => _AllDevicesState();
|
|
}
|
|
|
|
class _AllDevicesState extends State<AllDevices> {
|
|
final TextEditingController _searchController = TextEditingController();
|
|
List<DeviceModel> _filteredDevices = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_filteredDevices = widget.allDevices ?? [];
|
|
_searchController.addListener(_filterDevices);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_searchController.removeListener(_filterDevices);
|
|
_searchController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _filterDevices() {
|
|
final query = _searchController.text.toLowerCase();
|
|
setState(() {
|
|
_filteredDevices = widget.allDevices!
|
|
.where((device) => device.name!.toLowerCase().contains(query))
|
|
.toList();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
if (widget.allDevices.isNotEmpty)
|
|
TextFormField(
|
|
controller: _searchController,
|
|
decoration: InputDecoration(
|
|
hintText: 'Search',
|
|
hintStyle: const TextStyle(
|
|
color: ColorsManager.textGray,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w400),
|
|
prefixIcon: Container(
|
|
padding: const EdgeInsets.all(5.0),
|
|
margin: const EdgeInsets.all(10.0),
|
|
child: SvgPicture.asset(
|
|
Assets.searchIcon,
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8.0),
|
|
),
|
|
),
|
|
),
|
|
_filteredDevices.isNotEmpty
|
|
? Expanded(
|
|
child: GridView.builder(
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
crossAxisSpacing: 10,
|
|
mainAxisSpacing: 10,
|
|
childAspectRatio: 1.5,
|
|
),
|
|
padding: const EdgeInsets.only(top: 10),
|
|
itemCount: _filteredDevices.length,
|
|
itemBuilder: (context, index) {
|
|
return RoomPageSwitch(
|
|
allDevices: _filteredDevices,
|
|
isAllDevices: true,
|
|
device: _filteredDevices[index]);
|
|
},
|
|
),
|
|
)
|
|
: widget.allDevices.isNotEmpty
|
|
? const Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Center(
|
|
child: Text(
|
|
'No Results Found',
|
|
style: TextStyle(
|
|
color: ColorsManager.grayColor,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400),
|
|
)),
|
|
],
|
|
),
|
|
)
|
|
: const SizedBox(),
|
|
],
|
|
);
|
|
}
|
|
}
|