mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 20:24:54 +00:00
code refactoring
This commit is contained in:
@ -1,17 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_list.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view_list.dart';
|
||||
|
||||
import '../../../../../generated/assets.dart';
|
||||
import '../../../../../utils/resource_manager/color_manager.dart';
|
||||
import '../../../../app_layout/view/widgets/default_app_bar.dart';
|
||||
import '../../../../app_layout/view/widgets/default_nav_bar.dart';
|
||||
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||
import '../../../bloc/devices_cubit.dart';
|
||||
import '../../../bloc/lights/lights_cubit.dart';
|
||||
import '../../../model/light_model.dart';
|
||||
import '../universal_switch.dart';
|
||||
import 'light_interface.dart';
|
||||
|
||||
class LightsView extends StatelessWidget {
|
||||
const LightsView({super.key});
|
||||
@ -22,6 +21,11 @@ class LightsView extends StatelessWidget {
|
||||
create: (context) => LightsCubit(),
|
||||
child: BlocBuilder<LightsCubit, LightsState>(
|
||||
builder: (context, state) {
|
||||
LightModel? selectedLight;
|
||||
if (DevicesCubit.get(context).getSelectedDevice() is LightModel) {
|
||||
selectedLight =
|
||||
DevicesCubit.get(context).getSelectedDevice() as LightModel;
|
||||
}
|
||||
List<LightModel> lights = [];
|
||||
for (var device in DevicesCubit.categories[1].devices) {
|
||||
if (device is LightModel) {
|
||||
@ -51,24 +55,9 @@ class LightsView extends StatelessWidget {
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 70, right: 15, left: 15, bottom: 80),
|
||||
child: SizedBox.expand(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const BodySmall(text: "All Lights"),
|
||||
UniversalSwitch(
|
||||
category: DevicesCubit.categories[1],
|
||||
),
|
||||
LightsList(lights: lights),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: selectedLight != null
|
||||
? LightInterface(light: selectedLight)
|
||||
: LightsViewList(lights: lights),
|
||||
),
|
||||
bottomNavigationBar: const DefaultNavBar(),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user