Files
syncrow-app/lib/features/devices/view/widgets/devices_view_body.dart
T
Mohammad Salameh e17c0af144 Add HomeCubit and HomeState classes
This commit adds the HomeCubit class along with its corresponding HomeState
class. It also includes necessary imports and updates references to the
previously used SpacesCubit to the new HomeCubit in various files.
handled the multible onCreate -- HomeCubit
2024-03-24 14:43:13 +03:00

92 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/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/rooms_slider.dart';
import 'package:syncrow_app/features/devices/view/widgets/wizard_page.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
import '../../bloc/devices_cubit.dart';
class DevicesViewBody extends StatelessWidget {
const DevicesViewBody({
super.key,
});
@override
Widget build(BuildContext context) {
return BlocBuilder<HomeCubit, SpacesState>(
builder: (context, state) {
return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) {
//TODO : move to NavigationCubit
if (state is DevicesLoading) {
return const Center(child: CircularProgressIndicator());
} else {
return Padding(
padding: EdgeInsets.only(
top: Constants.appBarHeight,
bottom: Constants.bottomNavBarHeight,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const DevicesViewHeader(),
const RoomsSlider(),
const SizedBox(
height: 10,
),
Expanded(
child: PageView(
controller:
HomeCubit.get(context).devicesPageController,
onPageChanged: (index) {
HomeCubit.get(context).devicesPageChanged(index);
},
children: [
const WizardPage(),
if (HomeCubit.selectedSpace != null)
if (HomeCubit.selectedSpace!.rooms != null)
...HomeCubit.selectedSpace!.rooms!.map(
(room) {
return RoomPage(
room: room,
);
},
)
],
),
),
HomeCubit.selectedSpace != null
? Padding(
padding: const EdgeInsets.symmetric(
vertical: 7,
),
child: SmoothPageIndicator(
controller:
HomeCubit.get(context).devicesPageController,
count: HomeCubit.selectedSpace!.rooms!.length + 1,
effect: const WormEffect(
paintStyle: PaintingStyle.stroke,
dotHeight: 8,
dotWidth: 8,
),
),
)
: const Center(
child: BodyLarge(text: 'No Home Found'),
),
],
),
);
}
},
);
},
);
}
}