Skip to content

Commit

Permalink
chore(streaming mode): made scene buttons horizontally scrollable in …
Browse files Browse the repository at this point in the history
…streaming mode, need to fix scrollbar position
  • Loading branch information
Kounex committed Feb 21, 2024
1 parent 7c4ab98 commit 9e6c4b9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 35 deletions.
1 change: 1 addition & 0 deletions lib/views/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class _DashboardViewState extends State<DashboardView> {
@override
Widget build(BuildContext context) {
final DashboardStore dashboardStore = GetIt.instance<DashboardStore>();

return ThemedCupertinoScaffold(
body: Stack(
alignment: Alignment.topCenter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DashboardContentStreaming extends StatelessWidget {
const SizedBox(height: 12.0),
const SceneButtons(
size: 64,
mode: SceneButtonsMode.horizontalScroll,
),
const SizedBox(height: 12.0),
const Flexible(
Expand All @@ -30,7 +31,7 @@ class DashboardContentStreaming extends StatelessWidget {
),
),
SizedBox(
height: 50 + MediaQuery.viewInsetsOf(context).bottom,
height: MediaQuery.of(context).padding.bottom,
),
],
),
Expand Down
105 changes: 71 additions & 34 deletions lib/views/dashboard/widgets/scenes/scene_buttons/scene_buttons.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:get_it/get_it.dart';
import 'package:hive/hive.dart';
Expand All @@ -12,11 +14,20 @@ import '../../../../../types/enums/hive_keys.dart';
import '../scenes.dart';
import 'scene_button.dart';

enum SceneButtonsMode {
wrap,
horizontalScroll,
}

class SceneButtons extends StatelessWidget {
final double size;

final SceneButtonsMode mode;

const SceneButtons({
super.key,
this.size = 100,
this.mode = SceneButtonsMode.wrap,
});

@override
Expand Down Expand Up @@ -74,40 +85,66 @@ class SceneButtons extends StatelessWidget {
(hiddenScene) => scene.sceneName != hiddenScene.sceneName));
}

return Wrap(
runSpacing: kSceneButtonSpace,
spacing: kSceneButtonSpace,
children: visibleScenes != null && visibleScenes.isNotEmpty
? visibleScenes.map((scene) {
HiddenScene? hiddenScene;
try {
hiddenScene = hiddenScenes.firstWhere(
(element) => element.sceneName == scene.sceneName);
} catch (e) {}

return SceneButton(
scene: scene,
height: size,
width: size,
visible: hiddenScene == null,
onVisibilityTap: () {
if (hiddenScene != null) {
hiddenScene!.delete();
} else {
hiddenScene = HiddenScene(
scene.sceneName,
networkStore.activeSession!.connection.name,
networkStore.activeSession!.connection.host,
);

Hive.box<HiddenScene>(HiveKeys.HiddenScene.name)
.add(hiddenScene!);
}
},
);
}).toList()
: [const Text('No Scenes available')],
);
final List<Widget>? sceneButtons = visibleScenes?.map((scene) {
HiddenScene? hiddenScene;
try {
hiddenScene = hiddenScenes.firstWhere(
(element) => element.sceneName == scene.sceneName);
} catch (e) {}

return SceneButton(
scene: scene,
height: size,
width: size,
visible: hiddenScene == null,
onVisibilityTap: () {
if (hiddenScene != null) {
hiddenScene!.delete();
} else {
hiddenScene = HiddenScene(
scene.sceneName,
networkStore.activeSession!.connection.name,
networkStore.activeSession!.connection.host,
);

Hive.box<HiddenScene>(HiveKeys.HiddenScene.name)
.add(hiddenScene!);
}
},
);
}).toList();

if (sceneButtons == null || sceneButtons.isEmpty) {
return const Center(
child: Text(
'No Scenes available',
),
);
}

return switch (this.mode) {
SceneButtonsMode.wrap => Wrap(
runSpacing: kSceneButtonSpace,
spacing: kSceneButtonSpace,
children: sceneButtons,
),
SceneButtonsMode.horizontalScroll => SizedBox(
height: this.size,
child: Scrollbar(
scrollbarOrientation: ScrollbarOrientation.bottom,
thumbVisibility: true,
trackVisibility: true,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.only(left: 12.0),
itemCount: sceneButtons.length,
itemBuilder: (context, index) => sceneButtons[index],
separatorBuilder: (context, index) =>
const SizedBox(width: 12.0),
),
),
),
};
}),
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class _ScenePreviewState extends State<ScenePreview> {
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: double.infinity,
color: Colors.black,
),
if (_imageAvailable && !_fullscreen)
Observer(builder: (context) {
return AnimatedScale(
Expand Down

0 comments on commit 9e6c4b9

Please sign in to comment.