mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
light switch
code refactor
This commit is contained in:
@ -8,6 +8,11 @@ class LightsCubit extends Cubit<LightsState> {
|
|||||||
|
|
||||||
static LightsCubit get(context) => BlocProvider.of(context);
|
static LightsCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
|
toggleLight(LightModel light) {
|
||||||
|
light.status != null ? light.status = !light.status! : light.status = true;
|
||||||
|
emit(LightToggled(light));
|
||||||
|
}
|
||||||
|
|
||||||
int getBrightness(LightModel light) {
|
int getBrightness(LightModel light) {
|
||||||
return light.brightness.toInt();
|
return light.brightness.toInt();
|
||||||
}
|
}
|
||||||
|
@ -19,3 +19,9 @@ class LightBrightnessChanged extends LightsState {
|
|||||||
|
|
||||||
LightBrightnessChanged(this.brightness);
|
LightBrightnessChanged(this.brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LightToggled extends LightsState {
|
||||||
|
final LightModel light;
|
||||||
|
|
||||||
|
LightToggled(this.light);
|
||||||
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/devices_mode_tab.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/devices_mode_tab.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/switches.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/switches.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||||
@ -15,6 +17,7 @@ class DevicesCategoriesView extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
|
flex: 3,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -30,7 +33,7 @@ class DevicesCategoriesView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 3,
|
flex: 11,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
@ -9,10 +9,6 @@ import '../../bloc/devices_cubit.dart';
|
|||||||
import 'switches.dart';
|
import 'switches.dart';
|
||||||
|
|
||||||
class DevicesViewBody extends StatelessWidget {
|
class DevicesViewBody extends StatelessWidget {
|
||||||
const DevicesViewBody({
|
|
||||||
super.key,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
@ -24,10 +20,12 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
return state is DevicesLoading
|
return state is DevicesLoading
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
: Column(
|
: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.sizeOf(context).width,
|
||||||
height: MediaQuery.sizeOf(context).height - 252,
|
height: MediaQuery.sizeOf(context).height -
|
||||||
|
MediaQuery.sizeOf(context).height * .3,
|
||||||
child: PageView(
|
child: PageView(
|
||||||
controller: pageController,
|
controller: pageController,
|
||||||
children: const [
|
children: const [
|
||||||
@ -112,11 +110,25 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
SmoothPageIndicator(
|
SmoothPageIndicator(
|
||||||
controller: pageController,
|
controller: pageController,
|
||||||
count: 3,
|
count: 3,
|
||||||
effect: const WormEffect()),
|
effect: const WormEffect(
|
||||||
|
dotHeight: 8,
|
||||||
|
dotWidth: 8,
|
||||||
|
),
|
||||||
|
onDotClicked: (index) {
|
||||||
|
pageController.animateToPage(
|
||||||
|
index,
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
curve: Curves.ease,
|
||||||
|
);
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DevicesViewBody({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class LightBrightness extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
AnimatedPositioned(
|
AnimatedPositioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
duration: const Duration(milliseconds: 50),
|
duration: const Duration(milliseconds: 0),
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
width: (MediaQuery.of(context).size.width - 30) *
|
width: (MediaQuery.of(context).size.width - 30) *
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
import 'package:syncrow_app/features/devices/model/light_model.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';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
|
||||||
|
import '../../../../shared_widgets/default_container.dart';
|
||||||
|
|
||||||
class LightInterface extends StatelessWidget {
|
class LightInterface extends StatelessWidget {
|
||||||
const LightInterface({super.key, required this.light});
|
const LightInterface({super.key, required this.light});
|
||||||
@ -11,34 +16,84 @@ class LightInterface extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<LightsCubit, LightsState>(
|
||||||
|
builder: (context, state) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 70),
|
||||||
Container(
|
Container(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
maxHeight: 65,
|
maxHeight: 65,
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
margin:
|
||||||
child: const DefaultContainer(child: SizedBox.expand()),
|
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
|
child: DefaultContainer(
|
||||||
|
child: SizedBox.expand(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
BodyLarge(
|
||||||
|
text: light.status ?? false
|
||||||
|
? StringsManager.on
|
||||||
|
: StringsManager.off,
|
||||||
|
style: context.bodyLarge
|
||||||
|
.copyWith(color: Colors.grey, fontSize: 24),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
constraints: const BoxConstraints(
|
width: 35,
|
||||||
|
decoration: ShapeDecoration(
|
||||||
|
color: light.status ?? false
|
||||||
|
? ColorsManager.primaryWithOpacity
|
||||||
|
: Colors.grey,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: IconButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(
|
||||||
|
const EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
iconSize: MaterialStateProperty.all(25),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
LightsCubit.get(context).toggleLight(light);
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.power_settings_new,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
const DefaultContainer(
|
||||||
|
boxConstraints: BoxConstraints(
|
||||||
maxHeight: 310,
|
maxHeight: 310,
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
child: const SizedBox.expand(),
|
child: SizedBox.expand(
|
||||||
|
child: Center(child: Text("Light Controls")),
|
||||||
),
|
),
|
||||||
Container(
|
),
|
||||||
constraints: const BoxConstraints(
|
const DefaultContainer(
|
||||||
|
boxConstraints: BoxConstraints(
|
||||||
maxHeight: 65,
|
maxHeight: 65,
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
child: const SizedBox.expand(),
|
child: Center(child: Text("Timer")),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,9 @@ class LightsView extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => LightsCubit(),
|
create: (context) => LightsCubit(),
|
||||||
child: BlocBuilder<LightsCubit, LightsState>(
|
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return BlocBuilder<LightsCubit, LightsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
LightModel? selectedLight;
|
LightModel? selectedLight;
|
||||||
if (DevicesCubit.get(context).getSelectedDevice() is LightModel) {
|
if (DevicesCubit.get(context).getSelectedDevice() is LightModel) {
|
||||||
@ -64,6 +66,8 @@ class LightsView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,15 @@ class DefaultContainer extends StatelessWidget {
|
|||||||
this.height,
|
this.height,
|
||||||
this.width,
|
this.width,
|
||||||
this.color,
|
this.color,
|
||||||
|
this.boxConstraints,
|
||||||
|
this.margin,
|
||||||
});
|
});
|
||||||
|
|
||||||
final double? height;
|
final double? height;
|
||||||
final double? width;
|
final double? width;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
|
final BoxConstraints? boxConstraints;
|
||||||
|
final EdgeInsets? margin;
|
||||||
final Color? color;
|
final Color? color;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -20,6 +23,8 @@ class DefaultContainer extends StatelessWidget {
|
|||||||
return Container(
|
return Container(
|
||||||
height: height,
|
height: height,
|
||||||
width: width,
|
width: width,
|
||||||
|
margin: margin,
|
||||||
|
constraints: boxConstraints,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: color ?? Colors.white,
|
color: color ?? Colors.white,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
abstract class ColorsManager {
|
abstract class ColorsManager {
|
||||||
static const Color textPrimaryColor = Color(0xFF5D5D5D);
|
static const Color textPrimaryColor = Color(0xFF5D5D5D);
|
||||||
static const Color primaryColor = Color(0xFF0030CB);
|
static const Color primaryColor = Color(0xFF0030CB);
|
||||||
|
static Color primaryWithOpacity = const Color(0xFF023DFE).withOpacity(0.6);
|
||||||
static const Color onPrimaryColor = Colors.white;
|
static const Color onPrimaryColor = Colors.white;
|
||||||
static const Color secondaryColor = Color(0xFF023DFE);
|
static const Color secondaryColor = Color(0xFF023DFE);
|
||||||
static const Color onSecondaryColor = Color(0xFF023DFE);
|
static const Color onSecondaryColor = Color(0xFF023DFE);
|
||||||
|
Reference in New Issue
Block a user