Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct view tab #169

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'dart:convert';

import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/server_provider.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;

Expand Down Expand Up @@ -73,7 +74,7 @@ class Device {
return '${server.ip}:${server.port}/$id';
}

static Device fromUUID(String uuid) {
static Device? fromUUID(String uuid) {
final serverIp = uuid.split(':')[0];
final serverPort = int.tryParse(uuid.split(':')[1].split('/')[0]) ?? -1;
final deviceId = int.tryParse(uuid.split(':')[1].split('/')[1]) ?? -1;
Expand All @@ -83,7 +84,7 @@ class Device {
orElse: Server.dump,
);

return server.devices.firstWhere((d) => d.id == deviceId);
return server.devices.firstWhereOrNull((d) => d.id == deviceId);
}

factory Device.fromServerJson(Map map, Server server) {
Expand Down
1 change: 1 addition & 0 deletions lib/providers/downloads_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class DownloadsManager extends ChangeNotifier {
}

String getDownloadedPathForEvent(int eventId) {
assert(isEventDownloaded(eventId));
return downloadedEvents
.firstWhere((de) => de.event.id == eventId)
.downloadPath;
Expand Down
6 changes: 4 additions & 2 deletions lib/providers/server_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class ServersProvider extends ChangeNotifier {
return add(server);
}

final s =
servers.firstWhere((s) => s.ip == server.ip && s.port == server.port);
final s = servers.firstWhere(
(s) => s.ip == server.ip && s.port == server.port,
orElse: () => server,
);
final serverIndex = servers.indexOf(s);

for (final device in server.devices) {
Expand Down
3 changes: 2 additions & 1 deletion lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ class SettingsProvider extends ChangeNotifier {
systemLocale,
);
_snoozedUntil =
DateTime.tryParse(data[kHiveSnoozedUntil]) ?? defaultSnoozedUntil;
DateTime.tryParse((data[kHiveSnoozedUntil] as String?) ?? '') ??
defaultSnoozedUntil;
_notificationClickBehavior = NotificationClickBehavior.values[
data[kHiveNotificationClickBehavior] ??
kDefaultNotificationClickBehavior.index];
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ class UnityPlayers with ChangeNotifier {
/// [onlyIfTimedOut], if true, the device will only be reloaded if it's timed out
static void reloadAll({bool onlyIfTimedOut = false}) {
for (final entry in players.entries) {
final device = entry.key;
final player = entry.value;
if (onlyIfTimedOut) {
if (!player.isImageOld) continue;
}
reloadDevice(Device.fromUUID(device));
final deviceUUID = entry.key;
final device = Device.fromUUID(deviceUUID);
if (device != null) reloadDevice(device);
}
}
}
6 changes: 4 additions & 2 deletions lib/widgets/device_grid/desktop/desktop_device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ class LayoutView extends StatelessWidget {
if (amountOfItemsOnScreen > foldedDevices.length) {
// final diff = amountOfItemsOnScreen - foldedDevices.length;
while (amountOfItemsOnScreen > foldedDevices.length) {
final lastFullFold =
foldedDevices.firstWhere((fold) => fold.length > 1);
final lastFullFold = foldedDevices.firstWhere(
(fold) => fold.length > 1,
orElse: () => foldedDevices.first,
);
final foldIndex = foldedDevices.indexOf(lastFullFold);
foldedDevices.insert(
(foldIndex - 1).clamp(0, foldedDevices.length).toInt(),
Expand Down
7 changes: 6 additions & 1 deletion lib/widgets/device_grid/mobile/mobile_device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ class _MobileDeviceGridState extends State<MobileDeviceGrid> {
child: PageTransitionSwitcher(
child: view.devices.keys
.map((key) => _MobileDeviceGridChild(tab: key))
.elementAt(view.tab.clamp(0, view.devices.length - 1)),
.elementAt(
view.devices.keys
.toList()
.indexOf(view.tab)
.clamp(0, view.devices.length - 1),
),
transitionBuilder: (child, primaryAnimation, secondaryAnimation) {
return FadeThroughTransition(
animation: primaryAnimation,
Expand Down
9 changes: 7 additions & 2 deletions lib/widgets/events_timeline/events_playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ class _EventsPlaybackState extends EventsScreenState<EventsPlayback> {
continue;
}

final device =
event.server.devices.firstWhere((d) => d.id == event.deviceID);
final device = event.server.devices.firstWhere(
(d) => d.id == event.deviceID,
orElse: () => Device.dump(
name: event.deviceName,
id: event.deviceID,
),
);
devices[device] ??= [];

if (devices[device]!.any((e) {
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/servers/edit_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class _EditServerState extends State<EditServer> {
Server get server {
return ServersProvider.instance.servers.firstWhere(
(s) => s.ip == widget.serverIp && s.port == widget.serverPort,
orElse: () => Server.dump(
ip: widget.serverIp,
port: widget.serverPort,
),
);
}

Expand Down
7 changes: 6 additions & 1 deletion windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down