Built Curtains List view

Modified Category Model(default value of devices status is now null)
Added a category getter in each devices cubit ( AcCubit, LightsCubit ...)
This commit is contained in:
Mohammad Salameh
2024-03-05 12:36:57 +03:00
parent a9fdb2fc76
commit 5a9c96b0a8
9 changed files with 240 additions and 32 deletions
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_temp_widget.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_temp.dart';
@@ -18,7 +18,6 @@ class ACsList extends StatelessWidget {
@override
Widget build(BuildContext context) {
DevicesCategoryModel category = DevicesCubit.categories[0];
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return SingleChildScrollView(
@@ -30,7 +29,7 @@ class ACsList extends StatelessWidget {
const BodySmall(text: "All ACs"),
const SizedBox(height: 5),
UniversalSwitch(
category: category,
category: AcCubit.category,
),
const SizedBox(height: 10),
const UniversalACTemp(),
@@ -41,9 +40,9 @@ class ACsList extends StatelessWidget {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: category.devices.length,
itemCount: AcCubit.category.devices.length,
itemBuilder: (context, index) {
ACModel ac = category.devices[index] as ACModel;
ACModel ac = AcCubit.category.devices[index] as ACModel;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -51,7 +50,8 @@ class ACsList extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
BodySmall(text: category.devices[index].name ?? ""),
BodySmall(
text: AcCubit.category.devices[index].name ?? ""),
IconButton(
onPressed: () {
DevicesCubit.get(context).selectDevice(ac);
@@ -70,7 +70,7 @@ class ACsList extends StatelessWidget {
],
),
const SizedBox(height: 5),
if (category.devices[index] is ACModel)
if (AcCubit.category.devices[index] is ACModel)
DevicesDefaultSwitch(
model: ac,
),
@@ -79,7 +79,7 @@ class ACsList extends StatelessWidget {
ac,
),
const SizedBox(height: 10),
if (category.devices[index] is ACModel)
if (AcCubit.category.devices[index] is ACModel)
ACModeControlUnit(
model: ac,
),
@@ -0,0 +1,84 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/curtains/curtains_cubit.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/curtain_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/universal_switch.dart';
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
class CurtainList extends StatelessWidget {
const CurtainList({
super.key,
});
@override
Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// universal AC controller
const SizedBox(height: 10),
//TODO: move to strings manager
const BodySmall(text: "All Curtains"),
const SizedBox(height: 5),
UniversalSwitch(
category: CurtainsCubit.category,
),
// other ACs controls
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0),
itemCount: CurtainsCubit.category.devices.length,
itemBuilder: (context, index) {
CurtainModel ac =
CurtainsCubit.category.devices[index] as CurtainModel;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
BodySmall(
text:
CurtainsCubit.category.devices[index].name ??
""),
IconButton(
onPressed: () {
DevicesCubit.get(context).selectDevice(ac);
},
icon: const Icon(
Icons.arrow_forward_ios,
),
style: ButtonStyle(
padding: MaterialStateProperty.all(
const EdgeInsets.all(0),
),
iconSize: MaterialStateProperty.all(15),
alignment: Alignment.bottomRight,
),
),
],
),
const SizedBox(height: 5),
if (CurtainsCubit.category.devices[index] is CurtainModel)
DevicesDefaultSwitch(
model: ac,
),
],
);
},
),
],
),
);
},
);
}
}
@@ -1,10 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
import 'package:syncrow_app/features/devices/bloc/curtains/curtains_cubit.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_list.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class CurtainView extends StatelessWidget {
const CurtainView({super.key});
@override
Widget build(BuildContext context) {
return const Placeholder();
return BlocProvider(
create: (context) => CurtainsCubit(),
child: BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
return BlocBuilder<CurtainsCubit, CurtainsState>(
builder: (context, state) {
return AnnotatedRegion(
value: SystemUiOverlayStyle(
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light,
),
child: SafeArea(
child: Scaffold(
backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true,
extendBody: true,
appBar: DefaultAppBar(context),
body: Container(
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
Assets.imagesBackground,
),
fit: BoxFit.cover,
opacity: 0.4,
),
),
child: Padding(
padding: EdgeInsets.only(
top: Constants.appBarHeight,
left: Constants.defaultPadding,
right: Constants.defaultPadding,
),
child: const CurtainList(),
),
),
),
),
);
},
);
},
),
);
}
}