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

feat: live view link #89

Merged
merged 3 commits into from
Feb 3, 2025
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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ PF2E_URI="https://raw.githubusercontent.com/VytorCalixto/pf2e-fvtt-bestiary/refs
API_5E_URI="https://api.open5e.com"
API_URI="<URI>"
FLAGSMITH_URI="<URI>"
FLAGSMITH_API_KEY=""
FLAGSMITH_API_KEY=""
BASE_URL="https://app.battlemaster.com.br"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:share_plus/share_plus.dart';
import 'package:toastification/toastification.dart';

class EncounterCodeDialog extends StatelessWidget {
Expand Down Expand Up @@ -61,9 +62,12 @@ class EncounterCodeDialog extends StatelessWidget {
showProgressBar: false,
title: Text(localization.copied_to_clipboard),
);
const baseUrl = String.fromEnvironment("BASE_URL");
Share.share(localization
.share_encounter_code("$baseUrl/live/$code"));
},
color: Colors.grey.shade800,
icon: Icon(MingCute.copy_2_fill),
icon: Icon(MingCute.share_3_fill),
),
],
),
Expand Down
38 changes: 38 additions & 0 deletions lib/features/player_view/player_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:battlemaster/features/player_view/providers/player_view_notifier
import 'package:battlemaster/features/player_view/widgets/live_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:pinput/pinput.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -47,3 +48,40 @@ class PlayerViewPage extends StatelessWidget {
);
}
}

class CodeViewPage extends StatefulWidget {
const CodeViewPage({
super.key,
required this.code,
});

final String code;

@override
State<CodeViewPage> createState() => _CodeViewPageState();
}

class _CodeViewPageState extends State<CodeViewPage> {
@override
void initState() {
super.initState();
context.read<PlayerViewNotifier>().subscribe(code: widget.code);
}

@override
Widget build(BuildContext context) {
final liveViewState = context.watch<PlayerViewNotifier>();
return Scaffold(
body: SafeArea(
child: Center(
child: LiveView(
onLeave: () {
liveViewState.unsubscribe();
context.replaceNamed("home");
},
),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum PlayerViewState { disconnected, loading, ready, error }
class PlayerViewNotifier extends ChangeNotifier {
String? _code;
final PocketBase _pb;
PlayerViewState _state = PlayerViewState.loading;
PlayerViewState _state = PlayerViewState.disconnected;
EncounterView? _encounter;
AuthProvider auth;
final _activeIndexController = StreamController<int>.broadcast();
Expand Down
11 changes: 11 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,17 @@
"@copied_to_clipboard": {
"description": "The message to show the text was copied to the clipboard."
},
"share_encounter_code": "Check out the encounter at {url}",
"@share_encounter_code": {
"description": "share encounter code text",
"placeholders": {
"url": {
"type": "String",
"description": "the url",
"example": "https://foo.bar"
}
}
},
"pf2e_variable_action_preposition": "to",
"@pf2e_variable_action_preposition": {
"description": "The preposition for the variable action."
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"health_indicator_critical": "Crítico",
"health_indicator_dead": "Morto",
"copied_to_clipboard": "Copiado para a área de transferência!",
"share_encounter_code": "Acompanhe o combate em {url}",
"pf2e_variable_action_preposition": "a",
"pf2e_creature_level": "Criatura {level}",
"pf2e_items": "Itens",
Expand Down
7 changes: 7 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:battlemaster/database/database.dart';
import 'package:battlemaster/features/analytics/analytics_service.dart';
import 'package:battlemaster/features/auth/providers/auth_provider.dart';
import 'package:battlemaster/features/conditions/custom_conditions_page.dart';
import 'package:battlemaster/features/player_view/player_view_page.dart';
import 'package:battlemaster/features/player_view/providers/player_view_notifier.dart';
import 'package:battlemaster/features/settings/providers/system_settings_provider.dart';
import 'package:battlemaster/features/sync/providers/sync_encounter_repository.dart';
Expand Down Expand Up @@ -99,6 +100,12 @@ final _router = GoRouter(
name: 'conditions',
builder: (context, state) => const CustomConditionsPage(),
),
GoRoute(
path: '/live/:code',
name: 'live',
builder: (context, state) =>
CodeViewPage(code: state.pathParameters["code"]!),
),
],
);

Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <file_saver/file_saver_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_saver_registrar =
Expand All @@ -20,4 +21,7 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_saver
sentry_flutter
sqlite3_flutter_libs
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import file_saver
import package_info_plus
import path_provider_foundation
import sentry_flutter
import share_plus
import shared_preferences_foundation
import sqlite3_flutter_libs

Expand All @@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
}
6 changes: 6 additions & 0 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PODS:
- Flutter
- FlutterMacOS
- Sentry/HybridSDK (= 8.40.1)
- share_plus (0.0.1):
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand Down Expand Up @@ -43,6 +45,7 @@ DEPENDENCIES:
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- sentry_flutter (from `Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos`)
- share_plus (from `Flutter/ephemeral/.symlinks/plugins/share_plus/macos`)
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqlite3_flutter_libs (from `Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/macos`)

Expand All @@ -64,6 +67,8 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
sentry_flutter:
:path: Flutter/ephemeral/.symlinks/plugins/sentry_flutter/macos
share_plus:
:path: Flutter/ephemeral/.symlinks/plugins/share_plus/macos
shared_preferences_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/darwin
sqlite3_flutter_libs:
Expand All @@ -77,6 +82,7 @@ SPEC CHECKSUMS:
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
Sentry: e9215d7b17f7902692b4f8700e061e4f853e3521
sentry_flutter: 927eed60d66951d1b0f1db37fe94ff5cb7c80231
share_plus: 1fa619de8392a4398bfaf176d441853922614e89
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqlite3: 1e522f0938463e44b7faf50393b40bdc1e1e456d
sqlite3_flutter_libs: f0b7a85544d8bac7b8bac12eac7d05bcfdd786d0
Expand Down
48 changes: 48 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.10.1"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: fce43200aa03ea87b91ce4c3ac79f0cecd52e2a7a56c7a4185023c271fbfa6da
url: "https://pub.dev"
source: hosted
version: "10.1.4"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: cc012a23fc2d479854e6c80150696c4a5f5bb62cb89af4de1c505cf78d0a5d0b
url: "https://pub.dev"
source: hosted
version: "5.0.2"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1255,6 +1271,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77"
url: "https://pub.dev"
source: hosted
version: "3.1.4"
uuid:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies:
flagsmith: ^6.0.0
device_info_plus: ^11.1.1
email_validator: ^3.0.0
share_plus: ^10.1.4

dev_dependencies:
flutter_test:
Expand Down
6 changes: 6 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

#include <file_saver/file_saver_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSaverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSaverPlugin"));
SentryFlutterPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SentryFlutterPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
file_saver
sentry_flutter
share_plus
sqlite3_flutter_libs
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down