mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
Scenes have been added to the device page
This commit is contained in:
@ -3,12 +3,27 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_header.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/room_page.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/rooms_slider.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/wizard_page.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/wizard_page.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/view/scene_view.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
class DevicesViewPage extends StatelessWidget {
|
||||||
|
const DevicesViewPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => SceneBloc(), // Initialize your SceneBloc here
|
||||||
|
child: DevicesViewBody(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DevicesViewBody extends StatelessWidget {
|
class DevicesViewBody extends StatelessWidget {
|
||||||
const DevicesViewBody({
|
const DevicesViewBody({
|
||||||
@ -27,57 +42,73 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
return HomeCubit.getInstance().spaces?.isEmpty ?? true
|
return HomeCubit.getInstance().spaces?.isEmpty ?? true
|
||||||
? const CreateUnitWidget()
|
? const CreateUnitWidget()
|
||||||
: Column(
|
: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
TitleMedium(
|
||||||
|
text: StringsManager.devices,
|
||||||
|
style: context.titleMedium.copyWith(
|
||||||
|
fontSize: 25,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: MediaQuery.of(context).size.height/11,
|
||||||
|
child: const SceneView(pageType: true,)),
|
||||||
|
const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
const RoomsSlider(),
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: PageView(
|
||||||
|
controller: HomeCubit.getInstance().devicesPageController,
|
||||||
|
onPageChanged: (index) {
|
||||||
|
HomeCubit.getInstance().devicesPageChanged(index);
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
const DevicesViewHeader(),
|
WizardPage(
|
||||||
const RoomsSlider(),
|
groupsList: DevicesCubit.getInstance().allCategories ?? [],
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
),
|
||||||
Expanded(
|
if (HomeCubit.getInstance().selectedSpace != null)
|
||||||
child: PageView(
|
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
|
||||||
controller: HomeCubit.getInstance().devicesPageController,
|
...HomeCubit.getInstance().selectedSpace!.rooms!.map(
|
||||||
onPageChanged: (index) {
|
(room) {
|
||||||
HomeCubit.getInstance().devicesPageChanged(index);
|
return RoomPage(
|
||||||
},
|
room: room,
|
||||||
children: [
|
);
|
||||||
WizardPage(
|
},
|
||||||
groupsList: DevicesCubit.getInstance().allCategories ?? [],
|
)
|
||||||
),
|
|
||||||
if (HomeCubit.getInstance().selectedSpace != null)
|
|
||||||
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
|
|
||||||
...HomeCubit.getInstance().selectedSpace!.rooms!.map(
|
|
||||||
(room) {
|
|
||||||
return RoomPage(
|
|
||||||
room: room,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
HomeCubit.getInstance().selectedSpace != null
|
|
||||||
? Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 7,
|
|
||||||
),
|
|
||||||
child: SmoothPageIndicator(
|
|
||||||
controller: HomeCubit.getInstance().devicesPageController,
|
|
||||||
count: HomeCubit.getInstance().selectedSpace!.rooms!.length + 1,
|
|
||||||
effect: const WormEffect(
|
|
||||||
paintStyle: PaintingStyle.stroke,
|
|
||||||
dotHeight: 8,
|
|
||||||
dotWidth: 8,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Center(
|
|
||||||
child: BodyLarge(text: 'No Home Found'),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
|
),
|
||||||
|
HomeCubit.getInstance().selectedSpace != null
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 7,
|
||||||
|
),
|
||||||
|
child: SmoothPageIndicator(
|
||||||
|
controller: HomeCubit.getInstance().devicesPageController,
|
||||||
|
count: HomeCubit.getInstance().selectedSpace!.rooms!.length + 1,
|
||||||
|
effect: const WormEffect(
|
||||||
|
paintStyle: PaintingStyle.stroke,
|
||||||
|
dotHeight: 8,
|
||||||
|
dotWidth: 8,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Center(
|
||||||
|
child: BodyLarge(text: 'No Home Found'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,11 +8,11 @@ import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_
|
|||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
import 'package:syncrow_app/features/shared_widgets/create_unit.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
|
||||||
class SceneView extends StatelessWidget {
|
class SceneView extends StatelessWidget {
|
||||||
const SceneView({super.key});
|
final bool pageType;
|
||||||
|
const SceneView({super.key,this.pageType=false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -46,8 +46,10 @@ class SceneView extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
|
if(pageType==false)
|
||||||
const SceneHeader(),
|
const SceneHeader(),
|
||||||
const SizedBox(height: 8),
|
if(pageType==false)
|
||||||
|
const SizedBox(height: 8),
|
||||||
BlocBuilder<SceneBloc, SceneState>(
|
BlocBuilder<SceneBloc, SceneState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SceneLoading) {
|
if (state is SceneLoading) {
|
||||||
@ -64,6 +66,7 @@ class SceneView extends StatelessWidget {
|
|||||||
if (state.scenes.isNotEmpty) {
|
if (state.scenes.isNotEmpty) {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: SceneGrid(
|
child: SceneGrid(
|
||||||
|
pageType: pageType,
|
||||||
scenes: state.scenes,
|
scenes: state.scenes,
|
||||||
loadingSceneId: state.loadingSceneId,
|
loadingSceneId: state.loadingSceneId,
|
||||||
),
|
),
|
||||||
@ -78,7 +81,6 @@ class SceneView extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||||
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||||
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
import 'package:syncrow_app/features/scene/model/scenes_model.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_item.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
|
|
||||||
class SceneGrid extends StatelessWidget {
|
class SceneGrid extends StatelessWidget {
|
||||||
final List<ScenesModel> scenes;
|
final List<ScenesModel> scenes;
|
||||||
final String? loadingSceneId;
|
final String? loadingSceneId;
|
||||||
|
final bool pageType;
|
||||||
const SceneGrid({
|
const SceneGrid({
|
||||||
|
this.pageType=false,
|
||||||
required this.scenes,
|
required this.scenes,
|
||||||
required this.loadingSceneId,
|
required this.loadingSceneId,
|
||||||
super.key,
|
super.key,
|
||||||
@ -15,7 +23,61 @@ class SceneGrid extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GridView.builder(
|
return pageType?
|
||||||
|
ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: scenes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final scene = scenes[index];
|
||||||
|
final isLoading = loadingSceneId == scene.id;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.only(right: 10),
|
||||||
|
child:DefaultContainer(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
Routes.sceneTasksRoute,
|
||||||
|
arguments: SceneSettingsRouteArguments(
|
||||||
|
sceneType: CreateSceneEnum.tabToRun.name,
|
||||||
|
sceneId: scene.id,
|
||||||
|
sceneName: scene.name,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
BlocProvider.of<CreateSceneBloc>(context)
|
||||||
|
.add(FetchSceneTasksEvent(sceneId: scene.id));
|
||||||
|
},
|
||||||
|
child: SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width/2.5,
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Image.asset(
|
||||||
|
height: 32,
|
||||||
|
width: 32,
|
||||||
|
Assets.assetsIconsLogo,
|
||||||
|
fit: BoxFit.fill,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: BodyMedium(
|
||||||
|
text: scene.name,
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
):
|
||||||
|
GridView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: 2,
|
crossAxisCount: 2,
|
||||||
@ -27,7 +89,6 @@ class SceneGrid extends StatelessWidget {
|
|||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final scene = scenes[index];
|
final scene = scenes[index];
|
||||||
final isLoading = loadingSceneId == scene.id;
|
final isLoading = loadingSceneId == scene.id;
|
||||||
|
|
||||||
return SceneItem(scene: scene, isLoading: isLoading);
|
return SceneItem(scene: scene, isLoading: isLoading);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -6,6 +6,7 @@ import 'package:syncrow_app/navigation/navigation_service.dart';
|
|||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
|
||||||
|
import 'features/scene/bloc/scene_bloc/scene_bloc.dart';
|
||||||
import 'navigation/router.dart' as router;
|
import 'navigation/router.dart' as router;
|
||||||
import 'navigation/routing_constants.dart';
|
import 'navigation/routing_constants.dart';
|
||||||
|
|
||||||
@ -23,7 +24,9 @@ class MyApp extends StatelessWidget {
|
|||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(create: (context) => AuthCubit()),
|
BlocProvider(create: (context) => AuthCubit()),
|
||||||
BlocProvider(create: (context) => CreateSceneBloc())
|
BlocProvider(create: (context) => CreateSceneBloc()),
|
||||||
|
BlocProvider(create: (context) => SceneBloc()),
|
||||||
|
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
navigatorKey: NavigationService.navigatorKey,
|
navigatorKey: NavigationService.navigatorKey,
|
||||||
|
Reference in New Issue
Block a user