Skip to content

Commit 2127794

Browse files
author
stalin
committed
fix example build problem of flutter-windows for new version of flutter . regenerate project by
flutter create.
1 parent e7c825b commit 2127794

20 files changed

+323
-278
lines changed

example/analysis_options.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
24+
rules:
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
28+
# Additional information about this file can be found at
29+
# https://dart.dev/guides/language/analysis-options
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
5.46 KB
Loading
20.5 KB
Loading

example/windows/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22
project(example LANGUAGES CXX)
33

44
set(BINARY_NAME "example")

example/windows/flutter/.template_version

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/windows/flutter/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22

33
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
44

@@ -23,6 +23,7 @@ list(APPEND FLUTTER_LIBRARY_HEADERS
2323
"flutter_windows.h"
2424
"flutter_messenger.h"
2525
"flutter_plugin_registrar.h"
26+
"flutter_texture_registrar.h"
2627
)
2728
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
2829
add_library(flutter INTERFACE)
@@ -34,15 +35,16 @@ add_dependencies(flutter flutter_assemble)
3435

3536
# === Wrapper ===
3637
list(APPEND CPP_WRAPPER_SOURCES_CORE
37-
"engine_method_result.cc"
38-
"standard_codec.cc"
38+
"core_implementations.cc"
39+
"standard_codec.cc"
3940
)
4041
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
4142
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
4243
"plugin_registrar.cc"
4344
)
4445
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
4546
list(APPEND CPP_WRAPPER_SOURCES_APP
47+
"flutter_engine.cc"
4648
"flutter_view_controller.cc"
4749
)
4850
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
@@ -79,15 +81,18 @@ add_dependencies(flutter_wrapper_app flutter_assemble)
7981
# _phony_ is a non-existent file to force this command to run every time,
8082
# since currently there's no way to get a full input/output list from the
8183
# flutter tool.
84+
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
85+
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
8286
add_custom_command(
8387
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
8488
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
8589
${CPP_WRAPPER_SOURCES_APP}
86-
${CMAKE_CURRENT_BINARY_DIR}/_phony_
90+
${PHONY_OUTPUT}
8791
COMMAND ${CMAKE_COMMAND} -E env
8892
${FLUTTER_TOOL_ENVIRONMENT}
8993
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
9094
windows-x64 $<CONFIG>
95+
VERBATIM
9196
)
9297
add_custom_target(flutter_assemble DEPENDS
9398
"${FLUTTER_LIBRARY}"

example/windows/runner/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
cmake_minimum_required(VERSION 3.15)
1+
cmake_minimum_required(VERSION 3.14)
22
project(runner LANGUAGES CXX)
33

44
add_executable(${BINARY_NAME} WIN32
55
"flutter_window.cpp"
66
"main.cpp"
7-
"run_loop.cpp"
87
"utils.cpp"
98
"win32_window.cpp"
10-
"window_configuration.cpp"
119
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1210
"Runner.rc"
1311
"runner.exe.manifest"
1412
)
1513
apply_standard_settings(${BINARY_NAME})
14+
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
1615
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
1716
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
1817
add_dependencies(${BINARY_NAME} flutter_assemble)

example/windows/runner/Runner.rc

Lines changed: 121 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,121 @@
1-
// Microsoft Visual C++ generated resource script.
2-
//
3-
#pragma code_page(65001)
4-
#include "resource.h"
5-
6-
#define APSTUDIO_READONLY_SYMBOLS
7-
/////////////////////////////////////////////////////////////////////////////
8-
//
9-
// Generated from the TEXTINCLUDE 2 resource.
10-
//
11-
#include "winres.h"
12-
13-
/////////////////////////////////////////////////////////////////////////////
14-
#undef APSTUDIO_READONLY_SYMBOLS
15-
16-
/////////////////////////////////////////////////////////////////////////////
17-
// English (United States) resources
18-
19-
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20-
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21-
22-
#ifdef APSTUDIO_INVOKED
23-
/////////////////////////////////////////////////////////////////////////////
24-
//
25-
// TEXTINCLUDE
26-
//
27-
28-
1 TEXTINCLUDE
29-
BEGIN
30-
"resource.h\0"
31-
END
32-
33-
2 TEXTINCLUDE
34-
BEGIN
35-
"#include ""winres.h""\r\n"
36-
"\0"
37-
END
38-
39-
3 TEXTINCLUDE
40-
BEGIN
41-
"\r\n"
42-
"\0"
43-
END
44-
45-
#endif // APSTUDIO_INVOKED
46-
47-
48-
/////////////////////////////////////////////////////////////////////////////
49-
//
50-
// Icon
51-
//
52-
53-
// Icon with lowest ID value placed first to ensure application icon
54-
// remains consistent on all systems.
55-
IDI_APP_ICON ICON "resources\\app_icon.ico"
56-
57-
#endif // English (United States) resources
58-
/////////////////////////////////////////////////////////////////////////////
59-
60-
61-
62-
#ifndef APSTUDIO_INVOKED
63-
/////////////////////////////////////////////////////////////////////////////
64-
//
65-
// Generated from the TEXTINCLUDE 3 resource.
66-
//
67-
68-
69-
/////////////////////////////////////////////////////////////////////////////
70-
#endif // not APSTUDIO_INVOKED
1+
// Microsoft Visual C++ generated resource script.
2+
//
3+
#pragma code_page(65001)
4+
#include "resource.h"
5+
6+
#define APSTUDIO_READONLY_SYMBOLS
7+
/////////////////////////////////////////////////////////////////////////////
8+
//
9+
// Generated from the TEXTINCLUDE 2 resource.
10+
//
11+
#include "winres.h"
12+
13+
/////////////////////////////////////////////////////////////////////////////
14+
#undef APSTUDIO_READONLY_SYMBOLS
15+
16+
/////////////////////////////////////////////////////////////////////////////
17+
// English (United States) resources
18+
19+
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20+
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21+
22+
#ifdef APSTUDIO_INVOKED
23+
/////////////////////////////////////////////////////////////////////////////
24+
//
25+
// TEXTINCLUDE
26+
//
27+
28+
1 TEXTINCLUDE
29+
BEGIN
30+
"resource.h\0"
31+
END
32+
33+
2 TEXTINCLUDE
34+
BEGIN
35+
"#include ""winres.h""\r\n"
36+
"\0"
37+
END
38+
39+
3 TEXTINCLUDE
40+
BEGIN
41+
"\r\n"
42+
"\0"
43+
END
44+
45+
#endif // APSTUDIO_INVOKED
46+
47+
48+
/////////////////////////////////////////////////////////////////////////////
49+
//
50+
// Icon
51+
//
52+
53+
// Icon with lowest ID value placed first to ensure application icon
54+
// remains consistent on all systems.
55+
IDI_APP_ICON ICON "resources\\app_icon.ico"
56+
57+
58+
/////////////////////////////////////////////////////////////////////////////
59+
//
60+
// Version
61+
//
62+
63+
#ifdef FLUTTER_BUILD_NUMBER
64+
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
65+
#else
66+
#define VERSION_AS_NUMBER 1,0,0
67+
#endif
68+
69+
#ifdef FLUTTER_BUILD_NAME
70+
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
71+
#else
72+
#define VERSION_AS_STRING "1.0.0"
73+
#endif
74+
75+
VS_VERSION_INFO VERSIONINFO
76+
FILEVERSION VERSION_AS_NUMBER
77+
PRODUCTVERSION VERSION_AS_NUMBER
78+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79+
#ifdef _DEBUG
80+
FILEFLAGS VS_FF_DEBUG
81+
#else
82+
FILEFLAGS 0x0L
83+
#endif
84+
FILEOS VOS__WINDOWS32
85+
FILETYPE VFT_APP
86+
FILESUBTYPE 0x0L
87+
BEGIN
88+
BLOCK "StringFileInfo"
89+
BEGIN
90+
BLOCK "040904e4"
91+
BEGIN
92+
VALUE "CompanyName", "com.example" "\0"
93+
VALUE "FileDescription", "A new Flutter project." "\0"
94+
VALUE "FileVersion", VERSION_AS_STRING "\0"
95+
VALUE "InternalName", "example" "\0"
96+
VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0"
97+
VALUE "OriginalFilename", "example.exe" "\0"
98+
VALUE "ProductName", "example" "\0"
99+
VALUE "ProductVersion", VERSION_AS_STRING "\0"
100+
END
101+
END
102+
BLOCK "VarFileInfo"
103+
BEGIN
104+
VALUE "Translation", 0x409, 1252
105+
END
106+
END
107+
108+
#endif // English (United States) resources
109+
/////////////////////////////////////////////////////////////////////////////
110+
111+
112+
113+
#ifndef APSTUDIO_INVOKED
114+
/////////////////////////////////////////////////////////////////////////////
115+
//
116+
// Generated from the TEXTINCLUDE 3 resource.
117+
//
118+
119+
120+
/////////////////////////////////////////////////////////////////////////////
121+
#endif // not APSTUDIO_INVOKED
Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
11
#include "flutter_window.h"
22

3+
#include <optional>
4+
35
#include "flutter/generated_plugin_registrant.h"
46

5-
FlutterWindow::FlutterWindow(RunLoop* run_loop,
6-
const flutter::DartProject& project)
7-
: run_loop_(run_loop), project_(project) {}
7+
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8+
: project_(project) {}
89

910
FlutterWindow::~FlutterWindow() {}
1011

11-
void FlutterWindow::OnCreate() {
12-
Win32Window::OnCreate();
12+
bool FlutterWindow::OnCreate() {
13+
if (!Win32Window::OnCreate()) {
14+
return false;
15+
}
16+
17+
RECT frame = GetClientArea();
1318

14-
// The size here is arbitrary since SetChildContent will resize it.
15-
flutter_controller_ =
16-
std::make_unique<flutter::FlutterViewController>(100, 100, project_);
17-
RegisterPlugins(flutter_controller_.get());
18-
run_loop_->RegisterFlutterInstance(flutter_controller_.get());
19+
// The size here must match the window dimensions to avoid unnecessary surface
20+
// creation / destruction in the startup path.
21+
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
22+
frame.right - frame.left, frame.bottom - frame.top, project_);
23+
// Ensure that basic setup of the controller was successful.
24+
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25+
return false;
26+
}
27+
RegisterPlugins(flutter_controller_->engine());
1928
SetChildContent(flutter_controller_->view()->GetNativeWindow());
29+
return true;
2030
}
2131

2232
void FlutterWindow::OnDestroy() {
2333
if (flutter_controller_) {
24-
run_loop_->UnregisterFlutterInstance(flutter_controller_.get());
2534
flutter_controller_ = nullptr;
2635
}
2736

2837
Win32Window::OnDestroy();
2938
}
39+
40+
LRESULT
41+
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42+
WPARAM const wparam,
43+
LPARAM const lparam) noexcept {
44+
// Give Flutter, including plugins, an opportunity to handle window messages.
45+
if (flutter_controller_) {
46+
std::optional<LRESULT> result =
47+
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48+
lparam);
49+
if (result) {
50+
return *result;
51+
}
52+
}
53+
54+
switch (message) {
55+
case WM_FONTCHANGE:
56+
flutter_controller_->engine()->ReloadSystemFonts();
57+
break;
58+
}
59+
60+
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61+
}

0 commit comments

Comments
 (0)