mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 11:57:54 +00:00
Stabilized UI elements across multiple devices
Synchronized ACs Status functionality
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:syncrow_app/features/dashboard/view/widgets/carbon_emission.dart';
|
||||
import 'package:syncrow_app/features/dashboard/view/widgets/consumption.dart';
|
||||
@@ -13,31 +15,33 @@ class DashboardView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Column(
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TitleMedium(
|
||||
const TitleMedium(
|
||||
text: StringsManager.dashboard,
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
LiveMonitorTab(),
|
||||
Gap(10),
|
||||
EnergyUsage(),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Consumption(),
|
||||
Gap(20),
|
||||
CarbonEmission(),
|
||||
],
|
||||
),
|
||||
const LiveMonitorTab(),
|
||||
const Gap(10),
|
||||
const EnergyUsage(),
|
||||
Container(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 220,
|
||||
maxHeight: 240,
|
||||
),
|
||||
child: const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Consumption(),
|
||||
Gap(20),
|
||||
CarbonEmission(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -15,11 +15,15 @@ class CarbonEmission extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
padding: const EdgeInsets.only(right: 20, left: 20, top: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
maxHeight: 100,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -14,7 +14,7 @@ class CardTitle extends StatelessWidget {
|
||||
return BodySmall(
|
||||
text: title,
|
||||
fontColor: Colors.grey,
|
||||
fontSize: 12,
|
||||
fontSize: MediaQuery.sizeOf(context).height.ceil() > 680 ? 12 : 8,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,41 +14,48 @@ class Consumption extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
padding: const EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: 80,
|
||||
maxHeight: 100,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CardTitle(
|
||||
const CardTitle(
|
||||
title: StringsManager.ACConsumption,
|
||||
),
|
||||
Gap(10),
|
||||
const Spacer(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
UnitedText(
|
||||
value: "2",
|
||||
valueSize: 35,
|
||||
valueSize: MediaQuery.sizeOf(context).height.ceil() > 680
|
||||
? 35
|
||||
: 24,
|
||||
valueWeight: FontWeight.normal,
|
||||
unit: "Units",
|
||||
),
|
||||
Gap(30),
|
||||
const Gap(30),
|
||||
UnitedText(
|
||||
value: "720",
|
||||
valueSize: 35,
|
||||
value: "${MediaQuery.sizeOf(context).height.ceil()}",
|
||||
valueSize: MediaQuery.sizeOf(context).height.ceil() > 680
|
||||
? 35
|
||||
: 24,
|
||||
valueWeight: FontWeight.normal,
|
||||
unit: "kWh",
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
//TODO: Replace with actual pie chart
|
||||
|
||||
@@ -1,21 +1,46 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
|
||||
part 'ac_state.dart';
|
||||
|
||||
class AcCubit extends Cubit<AcState> {
|
||||
AcCubit() : super(AcInitial());
|
||||
AcCubit() : super(AcInitial()) {
|
||||
averageTempForAll();
|
||||
updateACsStatus();
|
||||
}
|
||||
|
||||
static AcCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
bool areAllACsOff() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
if (ac.status) {
|
||||
return false;
|
||||
void turnACOn(ACModel model) {
|
||||
if (!model.status) {
|
||||
model.status = true;
|
||||
updateACsStatus();
|
||||
emit(ACTurnedOn());
|
||||
}
|
||||
}
|
||||
|
||||
void turnACOff(ACModel model) {
|
||||
if (model.status) {
|
||||
model.status = false;
|
||||
updateACsStatus();
|
||||
emit(ACTurnedOff());
|
||||
}
|
||||
}
|
||||
|
||||
void updateACsStatus() {
|
||||
bool tempStatus = DevicesCubit.categories[0].devices[0].status;
|
||||
for (var AC in DevicesCubit.categories[0].devices) {
|
||||
//check if there any AC have a different status than the initial ==> turn off the universal switch
|
||||
if (AC.status != tempStatus) {
|
||||
DevicesCubit.categories[0].devicesStatus = false;
|
||||
emit(ACsStatusChanged());
|
||||
return;
|
||||
}
|
||||
DevicesCubit.categories[0].devicesStatus = tempStatus;
|
||||
emit(ACsStatusChanged());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void turnAllACsOff() {
|
||||
@@ -36,21 +61,45 @@ class AcCubit extends Cubit<AcState> {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.temperature = temperature;
|
||||
}
|
||||
emit(ACsTempChanged());
|
||||
averageTempForAll();
|
||||
emit(ACsTempChanged(temperature));
|
||||
}
|
||||
|
||||
double averageTempForAll() {
|
||||
double allTemp = 0;
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
allTemp += ac.temperature;
|
||||
}
|
||||
emit(ACsTempChanged());
|
||||
// void setACTemp(int index, double temperature) {
|
||||
// DevicesCubit.categories[0].devices[index].temperature = temperature;
|
||||
// averageTempForAll();
|
||||
// emit(ACsTempChanged(temperature));
|
||||
// }
|
||||
|
||||
double averageTemp = allTemp / DevicesCubit.categories[0].devices.length;
|
||||
void increaseACTemp(int index) {
|
||||
DevicesCubit.categories[0].devices[index].temperature += .5;
|
||||
averageTempForAll();
|
||||
emit(ACsTempChanged(DevicesCubit.categories[0].devices[index].temperature));
|
||||
}
|
||||
|
||||
void decreaseACTemp(int index) {
|
||||
DevicesCubit.categories[0].devices[index].temperature -= .5;
|
||||
averageTempForAll();
|
||||
emit(ACsTempChanged(DevicesCubit.categories[0].devices[index].temperature));
|
||||
}
|
||||
|
||||
double getTemp(int index) {
|
||||
return DevicesCubit.categories[0].devices[index].temperature;
|
||||
}
|
||||
|
||||
static double averageTemp = 0;
|
||||
|
||||
void averageTempForAll() {
|
||||
double tempSum = 0;
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
tempSum += ac.temperature;
|
||||
}
|
||||
|
||||
averageTemp = tempSum / DevicesCubit.categories[0].devices.length;
|
||||
|
||||
averageTemp = (averageTemp * 2).round() / 2;
|
||||
|
||||
return averageTemp;
|
||||
emit(ACsAverageTemp());
|
||||
}
|
||||
|
||||
/// implement the fan speed and temp mode change
|
||||
|
||||
@@ -5,12 +5,24 @@ abstract class AcState {}
|
||||
|
||||
class AcInitial extends AcState {}
|
||||
|
||||
class ACsStatusChanged extends AcState {}
|
||||
|
||||
class SwitchACsOff extends AcState {}
|
||||
|
||||
class SwitchACsOn extends AcState {}
|
||||
|
||||
class ACsTempChanged extends AcState {}
|
||||
class ACsTempChanged extends AcState {
|
||||
final double temperature;
|
||||
|
||||
ACsTempChanged(this.temperature);
|
||||
}
|
||||
|
||||
class ACsAverageTemp extends AcState {}
|
||||
|
||||
class ACsFanSpeedChanged extends AcState {}
|
||||
|
||||
class ACsTempModeChanged extends AcState {}
|
||||
|
||||
class ACTurnedOn extends AcState {}
|
||||
|
||||
class ACTurnedOff extends AcState {}
|
||||
|
||||
@@ -18,18 +18,13 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
// getCategories();
|
||||
}
|
||||
|
||||
/// separate the cubit into different cubits based on devices type
|
||||
static bool ACSwitchValue = false;
|
||||
static bool lightsSwitchValue = false;
|
||||
static bool doorSwitchValue = false;
|
||||
static bool curtainSwitchValue = false;
|
||||
static bool screensSwitchValue = false;
|
||||
static bool gatewaySwitchValue = false;
|
||||
|
||||
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
||||
category.switchValue = !category.switchValue;
|
||||
category.devicesStatus = !category.devicesStatus;
|
||||
for (var device in category.devices) {
|
||||
device.status = category.devicesStatus;
|
||||
}
|
||||
emit(CategorySwitchChanged());
|
||||
print('${category.name} switch value: ${category.switchValue} ');
|
||||
print('${category.name} switch value: ${category.devicesStatus} ');
|
||||
}
|
||||
|
||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||
@@ -56,7 +51,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
],
|
||||
icon: Assets.iconsAC,
|
||||
name: 'ACs',
|
||||
switchValue: ACSwitchValue,
|
||||
type: DeviceType.AC,
|
||||
page: const ACView(),
|
||||
),
|
||||
@@ -64,7 +58,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
devices: [],
|
||||
icon: Assets.iconsLight,
|
||||
name: 'Lights',
|
||||
switchValue: lightsSwitchValue,
|
||||
type: DeviceType.Lights,
|
||||
page: const LightsView(),
|
||||
),
|
||||
@@ -72,7 +65,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
devices: [],
|
||||
icon: Assets.iconsDoorLock,
|
||||
name: 'Doors',
|
||||
switchValue: doorSwitchValue,
|
||||
type: DeviceType.Door,
|
||||
page: const DoorView(),
|
||||
),
|
||||
@@ -80,7 +72,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
devices: [],
|
||||
icon: Assets.iconsCurtain,
|
||||
name: 'Curtains',
|
||||
switchValue: curtainSwitchValue,
|
||||
type: DeviceType.Curtain,
|
||||
page: const CurtainView(),
|
||||
),
|
||||
@@ -88,7 +79,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
devices: [],
|
||||
icon: Assets.iconsScreen,
|
||||
name: 'Screens',
|
||||
switchValue: screensSwitchValue,
|
||||
type: DeviceType.Screens,
|
||||
page: const ScreensView(),
|
||||
),
|
||||
@@ -96,13 +86,12 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
devices: [],
|
||||
icon: Assets.iconsGateway,
|
||||
name: 'Gateway',
|
||||
switchValue: gatewaySwitchValue,
|
||||
type: DeviceType.Gateway,
|
||||
page: const GateWayView(),
|
||||
),
|
||||
];
|
||||
|
||||
Widget? get chosenCategory {
|
||||
Widget? get chosenCategoryView {
|
||||
for (var category in categories) {
|
||||
if (category.isSelected) {
|
||||
return category.page;
|
||||
@@ -111,7 +100,17 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
void updateCategory(int index) {
|
||||
void areAllDevicesOff(DevicesCategoryModel category) {
|
||||
for (var device in category.devices) {
|
||||
if (device.status) {
|
||||
category.devicesStatus = false;
|
||||
emit(CategorySwitchChanged());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void selectCategory(int index) {
|
||||
for (var i = 0; i < categories.length; i++) {
|
||||
if (i == index) {
|
||||
categories[i].isSelected = true;
|
||||
|
||||
@@ -8,7 +8,7 @@ class DevicesCategoryModel {
|
||||
|
||||
final Widget page;
|
||||
|
||||
bool switchValue;
|
||||
bool devicesStatus = false;
|
||||
final List<ACModel> devices;
|
||||
|
||||
final DeviceType type;
|
||||
@@ -20,8 +20,21 @@ class DevicesCategoryModel {
|
||||
required this.type,
|
||||
required this.name,
|
||||
required this.icon,
|
||||
required this.switchValue,
|
||||
required this.devices});
|
||||
required this.devices}) {
|
||||
//sets the initial status of the devices
|
||||
if (devices.isNotEmpty) {
|
||||
bool tempStatus = devices.first.status;
|
||||
for (var device in devices) {
|
||||
if (device.status != tempStatus) {
|
||||
devicesStatus = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
devicesStatus = tempStatus;
|
||||
} else {
|
||||
devicesStatus = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum DeviceType {
|
||||
|
||||
@@ -51,7 +51,7 @@ class ACView extends StatelessWidget {
|
||||
),
|
||||
const Gap(10),
|
||||
DevicesTempWidget(
|
||||
model: DevicesCubit.categories[0].devices[index],
|
||||
index,
|
||||
),
|
||||
const Gap(10),
|
||||
ACControlUnit(
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
|
||||
import '../../../../../utils/resource_manager/color_manager.dart';
|
||||
import '../../../../shared_widgets/text_widgets/body_medium.dart';
|
||||
@@ -11,60 +13,70 @@ class UniversalACSwitch extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool acsStatus = AcCubit.get(context).areAllACsOff();
|
||||
|
||||
//TODO: Move these to String Manager "ON" and "OFF"
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnAllACsOn();
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: acsStatus ? ColorsManager.primaryColor : Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: acsStatus ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnAllACsOn();
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: DevicesCubit.categories[0].devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: DevicesCubit.categories[0].devicesStatus
|
||||
? Colors.white
|
||||
: null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnAllACsOff();
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: acsStatus ? Colors.white : ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: acsStatus ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnAllACsOff();
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: DevicesCubit.categories[0].devicesStatus
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: DevicesCubit.categories[0].devicesStatus
|
||||
? null
|
||||
: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/ac_cubit.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
@@ -15,45 +16,48 @@ class UniversalACTemp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double averageTemp = AcCubit.get(context).averageTempForAll();
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
SizedBox.square(
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).setTempToAll(averageTemp + .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
SizedBox.square(
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).setTempToAll(AcCubit.averageTemp + .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${AcCubit.get(context).averageTempForAll()}° C",
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).setTempToAll(averageTemp + .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
height: 24,
|
||||
width: 24,
|
||||
BodyLarge(
|
||||
text: "${AcCubit.averageTemp}° C",
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).setTempToAll(AcCubit.averageTemp + .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
height: 24,
|
||||
width: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,17 +31,19 @@ class CategoriesView extends StatelessWidget {
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TitleMedium(
|
||||
text: StringsManager.wizard,
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TitleMedium(
|
||||
text: StringsManager.wizard,
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
Switches(),
|
||||
],
|
||||
Switches(),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/ac_cubit.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/utils/context_extension.dart';
|
||||
@@ -8,21 +8,15 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../../generated/assets.dart';
|
||||
|
||||
class DevicesTempWidget extends StatefulWidget {
|
||||
const DevicesTempWidget({
|
||||
class DevicesTempWidget extends StatelessWidget {
|
||||
const DevicesTempWidget(
|
||||
this.index, {
|
||||
super.key,
|
||||
required this.model,
|
||||
});
|
||||
|
||||
final ACModel model;
|
||||
final int index;
|
||||
|
||||
@override
|
||||
State<DevicesTempWidget> createState() => _DevicesTempWidgetState();
|
||||
}
|
||||
|
||||
class _DevicesTempWidgetState extends State<DevicesTempWidget> {
|
||||
// double temp = widget.model.temperature;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultContainer(
|
||||
@@ -34,10 +28,7 @@ class _DevicesTempWidgetState extends State<DevicesTempWidget> {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
// temp = temp - .5;
|
||||
widget.model.temperature = widget.model.temperature - .5;
|
||||
});
|
||||
AcCubit.get(context).decreaseACTemp(index);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
@@ -45,7 +36,7 @@ class _DevicesTempWidgetState extends State<DevicesTempWidget> {
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${widget.model.temperature}° C",
|
||||
text: "${AcCubit.get(context).getTemp(index)}° C",
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
@@ -55,10 +46,7 @@ class _DevicesTempWidgetState extends State<DevicesTempWidget> {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
// temp = temp + .5
|
||||
widget.model.temperature = widget.model.temperature + .5;
|
||||
});
|
||||
AcCubit.get(context).increaseACTemp(index);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
|
||||
@@ -17,7 +17,7 @@ class DevicesViewBody extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
return state is DevicesLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: DevicesCubit.get(context).chosenCategory ??
|
||||
: DevicesCubit.get(context).chosenCategoryView ??
|
||||
const CategoriesView();
|
||||
},
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.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/utils/resource_manager/font_manager.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
|
||||
import '../../bloc/devices_cubit.dart';
|
||||
|
||||
@@ -30,11 +30,10 @@ class Switches extends StatelessWidget {
|
||||
itemCount: DevicesCubit.categories.length,
|
||||
itemBuilder: (_, index) {
|
||||
return InkWell(
|
||||
onTap: () => DevicesCubit.get(context).updateCategory(index),
|
||||
onTap: () => DevicesCubit.get(context).selectCategory(index),
|
||||
child: DefaultContainer(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
padding: const EdgeInsets.only(top: 10, right: 10, left: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -47,15 +46,24 @@ class Switches extends StatelessWidget {
|
||||
DevicesCubit.categories[index].icon,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
CustomSwitch(),
|
||||
CustomSwitch(
|
||||
category: DevicesCubit.categories[index],
|
||||
),
|
||||
],
|
||||
),
|
||||
BodyLarge(
|
||||
text: DevicesCubit.categories[index].name,
|
||||
fontWeight: FontsManager.bold,
|
||||
fontSize: 24,
|
||||
fontColor: const Color(0xFF848484),
|
||||
)
|
||||
Expanded(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: BodyLarge(
|
||||
text: DevicesCubit.categories[index].name,
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 0,
|
||||
fontSize: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,69 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class CustomSwitch extends StatefulWidget {
|
||||
// final bool value;
|
||||
// final ValueChanged<bool> onChanged;
|
||||
class CustomSwitch extends StatelessWidget {
|
||||
const CustomSwitch({super.key, required this.category});
|
||||
|
||||
const CustomSwitch({
|
||||
super.key,
|
||||
// required this.value,
|
||||
// required this.onChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
_CustomSwitchState createState() => _CustomSwitchState();
|
||||
}
|
||||
|
||||
class _CustomSwitchState extends State<CustomSwitch>
|
||||
with SingleTickerProviderStateMixin {
|
||||
Animation? _circleAnimation;
|
||||
AnimationController? _animationController;
|
||||
|
||||
bool value = false;
|
||||
|
||||
void onChange(bool customValue) {
|
||||
value = customValue;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
vsync: this, duration: const Duration(milliseconds: 300));
|
||||
_circleAnimation = AlignmentTween(
|
||||
begin: value ? Alignment.centerRight : Alignment.centerLeft,
|
||||
end: value ? Alignment.centerLeft : Alignment.centerRight,
|
||||
).animate(
|
||||
CurvedAnimation(
|
||||
parent: _animationController!,
|
||||
curve: Curves.linear,
|
||||
),
|
||||
);
|
||||
}
|
||||
final DevicesCategoryModel category;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animationController!,
|
||||
builder: (context, child) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_animationController!.isCompleted
|
||||
? _animationController!.reverse()
|
||||
: _animationController!.forward();
|
||||
value ? onChange(false) : onChange(true);
|
||||
});
|
||||
DevicesCubit.get(context).changeCategorySwitchValue(category);
|
||||
},
|
||||
child: Container(
|
||||
width: 45.0,
|
||||
height: 28.0,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
color: _circleAnimation!.value == Alignment.centerLeft
|
||||
? Color(0xFFD9D9D9)
|
||||
: ColorsManager.primaryColor,
|
||||
color: category.devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
: const Color(0xFFD9D9D9),
|
||||
),
|
||||
child: Center(
|
||||
child: Container(
|
||||
@@ -76,16 +37,17 @@ class _CustomSwitchState extends State<CustomSwitch>
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2.0),
|
||||
child: Container(
|
||||
alignment:
|
||||
value ? Alignment.centerRight : Alignment.centerLeft,
|
||||
alignment: category.devicesStatus
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: 20.0,
|
||||
height: 20.0,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _circleAnimation!.value == Alignment.centerLeft
|
||||
? Color(0xFFD9D9D9)
|
||||
: ColorsManager.primaryColor,
|
||||
color: category.devicesStatus
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/ac_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class DevicesDefaultSwitch extends StatefulWidget {
|
||||
class DevicesDefaultSwitch extends StatelessWidget {
|
||||
const DevicesDefaultSwitch({
|
||||
super.key,
|
||||
required this.model,
|
||||
@@ -11,73 +13,67 @@ class DevicesDefaultSwitch extends StatefulWidget {
|
||||
|
||||
final ACModel model;
|
||||
|
||||
@override
|
||||
State<DevicesDefaultSwitch> createState() => _DevicesDefaultSwitchState();
|
||||
}
|
||||
|
||||
class _DevicesDefaultSwitchState extends State<DevicesDefaultSwitch> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
// isOn = !isOn;
|
||||
widget.model.status = !widget.model.status;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.model.status
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: widget.model.status ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnACOn(model);
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.status
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: model.status ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
widget.model.status = !widget.model.status;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.model.status
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: widget.model.status ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context).turnACOff(model);
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.status
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: model.status ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class BodyLarge extends StatelessWidget {
|
||||
textAlign: textAlign,
|
||||
style: style ??
|
||||
context.bodyLarge.copyWith(
|
||||
height: height ?? 1.5,
|
||||
height: height,
|
||||
fontWeight: fontWeight,
|
||||
color: fontColor,
|
||||
fontSize: fontSize,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
class Assets {
|
||||
Assets._();
|
||||
|
||||
static const String assetsIconsHome = 'assets/icons/home.svg';
|
||||
static const String fontsAftikaRegular = 'assets/fonts/AftikaRegular.ttf';
|
||||
static const String iconsAC = 'assets/icons/AC.svg';
|
||||
static const String iconsActive = 'assets/icons/active.svg';
|
||||
@@ -20,18 +19,18 @@ class Assets {
|
||||
static const String iconsFan3 = 'assets/icons/fan-3.svg';
|
||||
static const String iconsFrequency = 'assets/icons/frequency.svg';
|
||||
static const String iconsGateway = 'assets/icons/Gateway.svg';
|
||||
static const String iconsHome = 'assets/icons/home.jpg';
|
||||
static const String iconsHome2 = 'assets/icons/home-2.svg';
|
||||
static const String iconsHome = 'assets/icons/home.svg';
|
||||
static const String iconsHot1 = 'assets/icons/hot1.jpg';
|
||||
static const String iconsLayout = 'assets/icons/Layout.svg';
|
||||
static const String iconsLayoutFill = 'assets/icons/Layout-fill.svg';
|
||||
static const String iconsLight = 'assets/icons/Light.svg';
|
||||
static const String iconsLogo = 'assets/icons/logo.png';
|
||||
static const String iconsMenu = 'assets/icons/Menu.svg';
|
||||
static const String iconsMenuFill = 'assets/icons/Menu-fill.svg';
|
||||
static const String iconsMinus = 'assets/icons/minus.svg';
|
||||
static const String iconsPlus = 'assets/icons/plus.svg';
|
||||
static const String iconsRoutineFill = 'assets/icons/Routine-fill.svg';
|
||||
static const String iconsRoutines = 'assets/icons/Routines.svg';
|
||||
static const String iconsRoutinesFill = 'assets/icons/Routines-fill.svg';
|
||||
static const String iconsScreen = 'assets/icons/Screen.svg';
|
||||
static const String iconsSummer = 'assets/icons/Summer.svg';
|
||||
static const String iconsSummerMode = 'assets/icons/summer_mode.svg';
|
||||
|
||||
Reference in New Issue
Block a user