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