mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-27 03:57:54 +00:00
implemented light brightness slider
optimised state emit to only emit when change is detected
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_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';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../model/light_model.dart';
|
||||
|
||||
class LightBrightness extends StatelessWidget {
|
||||
const LightBrightness({
|
||||
super.key,
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<LightsCubit, LightsState>(
|
||||
builder: (context, state) {
|
||||
return GestureDetector(
|
||||
onHorizontalDragUpdate: (details) => LightsCubit.get(context)
|
||||
.onHorizontalDragUpdate(light, details.localPosition.dx,
|
||||
MediaQuery.of(context).size.width - 15),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
const DefaultContainer(
|
||||
height: 60,
|
||||
child: SizedBox.expand(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
left: 0,
|
||||
duration: const Duration(milliseconds: 50),
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: (MediaQuery.of(context).size.width - 30) *
|
||||
light.brightness /
|
||||
100,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
borderRadius: light.brightness != 100
|
||||
? const BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
bottomLeft: Radius.circular(20),
|
||||
)
|
||||
: BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${light.brightness}%",
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: Colors.black,
|
||||
fontSize: 23,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_brightness.dart';
|
||||
|
||||
import '../../../../shared_widgets/devices_default_switch.dart';
|
||||
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||
@@ -47,6 +48,8 @@ class LightsList extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(model: lights[index]),
|
||||
const SizedBox(height: 10),
|
||||
LightBrightness(light: lights[index]),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -53,7 +53,7 @@ class LightsView extends StatelessWidget {
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 60, right: 15, left: 15, bottom: 80),
|
||||
top: 70, right: 15, left: 15, bottom: 80),
|
||||
child: SizedBox.expand(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
||||
Reference in New Issue
Block a user