mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 07:29:40 +00:00
implement SceneDevicesBodyTabBar
for improved tab management in SceneDevicesBody
.
This commit is contained in:
@ -7,11 +7,9 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart'
|
|||||||
import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart';
|
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_devices/scene_devices_body_tab_bar.dart';
|
||||||
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_list.dart';
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_list.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
||||||
|
|
||||||
class SceneDevicesBody extends StatelessWidget {
|
class SceneDevicesBody extends StatelessWidget {
|
||||||
const SceneDevicesBody({
|
const SceneDevicesBody({
|
||||||
@ -25,47 +23,27 @@ class SceneDevicesBody extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
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>(
|
return BlocBuilder<TabBarBloc, TabBarState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
SceneDevicesBodyTabBar(
|
||||||
controller: tabController,
|
tabController: tabController,
|
||||||
dividerColor: Colors.transparent,
|
rooms: rooms,
|
||||||
indicatorColor: Colors.transparent,
|
selectedRoomId: state is TabSelected ? state.roomId : '-1',
|
||||||
isScrollable: true,
|
|
||||||
tabAlignment: TabAlignment.start,
|
|
||||||
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(),
|
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
controller: tabController,
|
controller: tabController,
|
||||||
children: rooms
|
children: rooms
|
||||||
.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus))
|
.map(
|
||||||
|
(room) => _buildRoomTab(
|
||||||
|
room,
|
||||||
|
_isAutomationDeviceStatus(context),
|
||||||
|
),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -75,9 +53,16 @@ class SceneDevicesBody extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isAutomationDeviceStatus(BuildContext context) {
|
||||||
|
final routeArguments =
|
||||||
|
ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?;
|
||||||
|
final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name;
|
||||||
|
final sceneType = routeArguments?.sceneType;
|
||||||
|
return sceneType == deviceStatusChangesScene;
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildRoomTab(
|
Widget _buildRoomTab(
|
||||||
SubSpaceModel room,
|
SubSpaceModel room,
|
||||||
BuildContext context,
|
|
||||||
bool isAutomationDeviceStatus,
|
bool isAutomationDeviceStatus,
|
||||||
) {
|
) {
|
||||||
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
||||||
@ -96,12 +81,14 @@ class SceneDevicesBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
final invalidWidgetEntry = MapEntry(
|
||||||
|
true,
|
||||||
|
Center(child: Text('This subspace has no devices')),
|
||||||
|
);
|
||||||
|
|
||||||
final validWidgetEntry = widgets.entries.firstWhere(
|
final validWidgetEntry = widgets.entries.firstWhere(
|
||||||
(entry) => entry.key == true,
|
(entry) => entry.key == true,
|
||||||
orElse: () => MapEntry(
|
orElse: () => invalidWidgetEntry,
|
||||||
true,
|
|
||||||
Center(child: Text('This subspace has no devices')),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return validWidgetEntry.value;
|
return validWidgetEntry.value;
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/subspace_model.dart';
|
||||||
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
class SceneDevicesBodyTabBar extends StatelessWidget {
|
||||||
|
const SceneDevicesBodyTabBar({
|
||||||
|
required this.tabController,
|
||||||
|
required this.rooms,
|
||||||
|
required this.selectedRoomId,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String selectedRoomId;
|
||||||
|
|
||||||
|
final TabController tabController;
|
||||||
|
final List<SubSpaceModel> rooms;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return TabBar(
|
||||||
|
controller: tabController,
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
indicatorColor: Colors.transparent,
|
||||||
|
isScrollable: true,
|
||||||
|
tabAlignment: TabAlignment.start,
|
||||||
|
tabs: rooms.map((e) {
|
||||||
|
final isSelected = selectedRoomId == 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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user