Код: Выделить всё
import 'package:flutter/services.dart';
class SecureScreen {
static const MethodChannel _channel = MethodChannel('secure_screen');
static Future enableSecureMode() async {
await _channel.invokeMethod('enableSecureMode');
}
static Future disableSecureMode() async {
await _channel.invokeMethod('disableSecureMode');
}
}
< /code>
Но мне нужен собственный код для каждой платформы. Итак, вот что я попробовал в Windows/Runner/main.cpp Код: Выделить всё
#include
#include
#include
#include
#include "flutter_window.h"
#include "utils.h"
#include
#include
#ifndef WDA_MONITOR
#define WDA_MONITOR 1
#endif
void SetScreenCaptureProtection(HWND hwnd, bool disable) {
if (disable) {
SetWindowDisplayAffinity(hwnd, WDA_MONITOR);
} else {
SetWindowDisplayAffinity(hwnd, 0); // WDA_NONE
}
}
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector command_line_arguments = GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
if (!window.Create(L"schooler", origin, size)) {
return EXIT_FAILURE;
}
window.SetMinimumSize(400, 600);
window.SetQuitOnClose(true);
HWND hwnd = window.GetHandle();
// Create a MethodChannel for communication from Dart
// This is the corrected way to access the engine object.
auto channel = std::make_unique(
window.GetController()->engine(), "secure_screen",
&flutter::StandardMethodCodec::GetInstance());
channel->SetMethodCallHandler(
[hwnd](const flutter::MethodCall& call,
std::unique_ptr result) {
if (call.method_name().compare("enableSecureMode") == 0) {
SetScreenCaptureProtection(hwnd, true);
result->Success();
} else if (call.method_name().compare("disableSecureMode") == 0) {
SetScreenCaptureProtection(hwnd, false);
result->Success();
} else {
result->NotImplemented();
}
});
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app dwmapi)
< /code>
Затем, когда я запускаю трепещение следующей ошибки, и сбой сборки приложения < /p>
C:\Users\moham\OneDrive\Pictures\Portfolios\school\schooler\windows\runner\main.cpp(49,16): error C2039: 'engine': is not a member of 'FlutterWindow' [C:\Users\moham\OneDrive\Pictures\Portfolios\school\schooler\build\windows\x64\runner\schooler.vcxproj]
ake_unique': no matching overloaded function found [C:\Users\moham\OneDrive\Pictures\Portfolios\school\schooler\build\windows\x64\runner\schooler.vcxproj]
C:\Users\moham\OneDrive\Pictures\Portfolios\school\schooler\windows\runner\main.cpp(52,5): error C3536: 'channel': cannot be used before it is initialized [C:\Users\moham\OneDrive\Pictures\Portfolios\school\schooler\build\windows\x64\runner\schooler.vcxproj]
Building Windows application... 1108.5s
Error: Build process failed.
< /code>
Я искал Интернет, и для этого нет документов, видео или статей. Не могли бы вы помочь мне здесь?
Подробнее здесь: https://stackoverflow.com/questions/797 ... lutter-app
Мобильная версия