mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 01:19:40 +00:00
refactor: simplify SceneDevicesBody widget structure and improve loading indicator handling
This commit is contained in:
@ -9,6 +9,7 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.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/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.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/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
@ -19,49 +20,57 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
class SceneDevicesBody extends StatelessWidget {
|
||||
const SceneDevicesBody({
|
||||
super.key,
|
||||
required TabController tabController,
|
||||
required this.tabController,
|
||||
required this.rooms,
|
||||
}) : _tabController = tabController;
|
||||
});
|
||||
|
||||
final TabController _tabController;
|
||||
final List<SubSpaceModel>? rooms;
|
||||
final TabController tabController;
|
||||
final List<SubSpaceModel> rooms;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isAutomationDeviceStatus =
|
||||
((ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?)?.sceneType ==
|
||||
CreateSceneEnum.deviceStatusChanges.name);
|
||||
final routeArguments =
|
||||
ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?;
|
||||
final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name;
|
||||
final sceneType = routeArguments?.sceneType;
|
||||
final isAutomationDeviceStatus = sceneType == deviceStatusChangesScene;
|
||||
|
||||
return BlocBuilder<TabBarBloc, TabBarState>(
|
||||
builder: (context, tabState) {
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
controller: tabController,
|
||||
dividerColor: Colors.transparent,
|
||||
indicatorColor: Colors.transparent,
|
||||
tabs: [
|
||||
...rooms!.map((e) => Tab(
|
||||
child: BodyLarge(
|
||||
text: e.name ?? '',
|
||||
textAlign: TextAlign.start,
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: (tabState is TabSelected) && tabState.roomId == e.id
|
||||
? ColorsManager.textPrimaryColor
|
||||
: ColorsManager.textPrimaryColor.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
tabs: rooms.map((e) {
|
||||
final isStateTabSelected = state is TabSelected;
|
||||
final isSelected = isStateTabSelected && state.roomId == e.id;
|
||||
return Tab(
|
||||
child: BodyLarge(
|
||||
text: e.name ?? '',
|
||||
textAlign: TextAlign.start,
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: isSelected
|
||||
? ColorsManager.textPrimaryColor
|
||||
: ColorsManager.textPrimaryColor.withValues(
|
||||
alpha: 0.2,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children:
|
||||
rooms!.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus)).toList(),
|
||||
controller: tabController,
|
||||
children: rooms
|
||||
.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -70,22 +79,26 @@ class SceneDevicesBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRoomTab(SubSpaceModel room, BuildContext context, bool isAutomationDeviceStatus) {
|
||||
Widget _buildRoomTab(
|
||||
SubSpaceModel room,
|
||||
BuildContext context,
|
||||
bool isAutomationDeviceStatus,
|
||||
) {
|
||||
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
||||
builder: (context, state) {
|
||||
if (state.loading && state.devices == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
return const AppLoadingIndicator();
|
||||
} else if (state.devices != null && state.devices!.isNotEmpty) {
|
||||
return ListView.builder(
|
||||
itemCount: state.devices!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final device = state.devices![index];
|
||||
final device = state.devices?[index];
|
||||
return DefaultContainer(
|
||||
child: SceneListTile(
|
||||
minLeadingWidth: 40,
|
||||
leadingWidget: SvgPicture.asset(device.icon ?? ''),
|
||||
leadingWidget: SvgPicture.asset(device?.icon ?? ''),
|
||||
titleWidget: BodyMedium(
|
||||
text: device.name ?? '',
|
||||
text: device?.name ?? '',
|
||||
style: context.titleSmall.copyWith(
|
||||
color: ColorsManager.secondaryTextColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
@ -97,16 +110,14 @@ class SceneDevicesBody extends StatelessWidget {
|
||||
color: ColorsManager.greyColor,
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.deviceFunctionsRoute,
|
||||
arguments: {
|
||||
"device": device,
|
||||
"isAutomationDeviceStatus": isAutomationDeviceStatus
|
||||
},
|
||||
);
|
||||
},
|
||||
onPressed: () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.deviceFunctionsRoute,
|
||||
arguments: {
|
||||
"device": device,
|
||||
"isAutomationDeviceStatus": isAutomationDeviceStatus
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
Reference in New Issue
Block a user