Skip to content

Commit 1c54995

Browse files
authored
✨ add web and windows support in example. (#172)
1 parent f26baba commit 1c54995

32 files changed

+1328
-1
lines changed

example/.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@
6969
!**/ios/**/default.perspectivev3
7070
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
7171
/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
72-
pubspec.lock
72+
pubspec.lock
73+
74+
# Windows project.
75+
windows/flutter/generated_plugin_registrant.cc
76+
windows/flutter/generated_plugin_registrant.h
77+
windows/flutter/generated_plugins.cmake

example/android/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.simform.example
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity: FlutterActivity() {
6+
}
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>

example/ios/.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*.mode1v3
2+
*.mode2v3
3+
*.moved-aside
4+
*.pbxuser
5+
*.perspectivev3
6+
**/*sync/
7+
.sconsign.dblite
8+
.tags*
9+
**/.vagrant/
10+
**/DerivedData/
11+
Icon?
12+
**/Pods/
13+
**/.symlinks/
14+
profile
15+
xcuserdata
16+
**/.generated/
17+
Flutter/App.framework
18+
Flutter/Flutter.framework
19+
Flutter/Flutter.podspec
20+
Flutter/Generated.xcconfig
21+
Flutter/ephemeral/
22+
Flutter/app.flx
23+
Flutter/app.zip
24+
Flutter/flutter_assets/
25+
Flutter/flutter_export_environment.sh
26+
ServiceDefinitions.json
27+
Runner/GeneratedPluginRegistrant.*
28+
29+
# Exceptions to above rules.
30+
!default.mode1v3
31+
!default.mode2v3
32+
!default.pbxuser
33+
!default.perspectivev3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>PreviewsEnabled</key>
6+
<false/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

example/test/widget_test.dart

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This is a basic Flutter widget test.
2+
//
3+
// To perform an interaction with a widget in your test, use the WidgetTester
4+
// utility that Flutter provides. For example, you can send tap and scroll
5+
// gestures. You can also use WidgetTester to find child widgets in the widget
6+
// tree, read text, and verify that the values of widget properties are correct.
7+
8+
import 'package:flutter/material.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
import 'package:example/main.dart';
12+
13+
void main() {
14+
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15+
// Build our app and trigger a frame.
16+
await tester.pumpWidget(MyApp());
17+
18+
// Verify that our counter starts at 0.
19+
expect(find.text('0'), findsOneWidget);
20+
expect(find.text('1'), findsNothing);
21+
22+
// Tap the '+' icon and trigger a frame.
23+
await tester.tap(find.byIcon(Icons.add));
24+
await tester.pump();
25+
26+
// Verify that our counter has incremented.
27+
expect(find.text('0'), findsNothing);
28+
expect(find.text('1'), findsOneWidget);
29+
});
30+
}

example/web/favicon.png

917 Bytes
Loading

example/web/icons/Icon-192.png

5.17 KB
Loading

example/web/icons/Icon-512.png

8.06 KB
Loading

example/web/index.html

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!--
5+
If you are serving your web app in a path other than the root, change the
6+
href value below to reflect the base path you are serving from.
7+
8+
The path provided below has to start and end with a slash "/" in order for
9+
it to work correctly.
10+
11+
For more details:
12+
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
13+
-->
14+
<base href="/">
15+
16+
<meta charset="UTF-8">
17+
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
18+
<meta name="description" content="A new Flutter project.">
19+
20+
<!-- iOS meta tags & icons -->
21+
<meta name="apple-mobile-web-app-capable" content="yes">
22+
<meta name="apple-mobile-web-app-status-bar-style" content="black">
23+
<meta name="apple-mobile-web-app-title" content="example">
24+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
25+
26+
<title>example</title>
27+
<link rel="manifest" href="manifest.json">
28+
</head>
29+
<body>
30+
<!-- This script installs service_worker.js to provide PWA functionality to
31+
application. For more information, see:
32+
https://developers.google.com/web/fundamentals/primers/service-workers -->
33+
<script>
34+
var serviceWorkerVersion = null;
35+
var scriptLoaded = false;
36+
function loadMainDartJs() {
37+
if (scriptLoaded) {
38+
return;
39+
}
40+
scriptLoaded = true;
41+
var scriptTag = document.createElement('script');
42+
scriptTag.src = 'main.dart.js';
43+
scriptTag.type = 'application/javascript';
44+
document.body.append(scriptTag);
45+
}
46+
47+
if ('serviceWorker' in navigator) {
48+
// Service workers are supported. Use them.
49+
window.addEventListener('load', function () {
50+
// Wait for registration to finish before dropping the <script> tag.
51+
// Otherwise, the browser will load the script multiple times,
52+
// potentially different versions.
53+
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
54+
navigator.serviceWorker.register(serviceWorkerUrl)
55+
.then((reg) => {
56+
function waitForActivation(serviceWorker) {
57+
serviceWorker.addEventListener('statechange', () => {
58+
if (serviceWorker.state == 'activated') {
59+
console.log('Installed new service worker.');
60+
loadMainDartJs();
61+
}
62+
});
63+
}
64+
if (!reg.active && (reg.installing || reg.waiting)) {
65+
// No active web worker and we have installed or are installing
66+
// one for the first time. Simply wait for it to activate.
67+
waitForActivation(reg.installing ?? reg.waiting);
68+
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
69+
// When the app updates the serviceWorkerVersion changes, so we
70+
// need to ask the service worker to update.
71+
console.log('New service worker available.');
72+
reg.update();
73+
waitForActivation(reg.installing);
74+
} else {
75+
// Existing service worker is still good.
76+
console.log('Loading app from service worker.');
77+
loadMainDartJs();
78+
}
79+
});
80+
81+
// If service worker doesn't succeed in a reasonable amount of time,
82+
// fallback to plaint <script> tag.
83+
setTimeout(() => {
84+
if (!scriptLoaded) {
85+
console.warn(
86+
'Failed to load app from service worker. Falling back to plain <script> tag.',
87+
);
88+
loadMainDartJs();
89+
}
90+
}, 4000);
91+
});
92+
} else {
93+
// Service workers not supported. Just drop the <script> tag.
94+
loadMainDartJs();
95+
}
96+
</script>
97+
</body>
98+
</html>

example/web/manifest.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "example",
3+
"short_name": "example",
4+
"start_url": ".",
5+
"display": "standalone",
6+
"background_color": "#0175C2",
7+
"theme_color": "#0175C2",
8+
"description": "A new Flutter project.",
9+
"orientation": "portrait-primary",
10+
"prefer_related_applications": false,
11+
"icons": [
12+
{
13+
"src": "icons/Icon-192.png",
14+
"sizes": "192x192",
15+
"type": "image/png"
16+
},
17+
{
18+
"src": "icons/Icon-512.png",
19+
"sizes": "512x512",
20+
"type": "image/png"
21+
}
22+
]
23+
}

example/windows/.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
flutter/ephemeral/
2+
3+
# Visual Studio user-specific files.
4+
*.suo
5+
*.user
6+
*.userosscache
7+
*.sln.docstates
8+
9+
# Visual Studio build-related files.
10+
x64/
11+
x86/
12+
13+
# Visual Studio cache files
14+
# files ending in .cache can be ignored
15+
*.[Cc]ache
16+
# but keep track of directories ending in .cache
17+
!*.[Cc]ache/

example/windows/CMakeLists.txt

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(example LANGUAGES CXX)
3+
4+
set(BINARY_NAME "example")
5+
6+
cmake_policy(SET CMP0063 NEW)
7+
8+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9+
10+
# Configure build options.
11+
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
12+
if(IS_MULTICONFIG)
13+
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
14+
CACHE STRING "" FORCE)
15+
else()
16+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17+
set(CMAKE_BUILD_TYPE "Debug" CACHE
18+
STRING "Flutter build mode" FORCE)
19+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
20+
"Debug" "Profile" "Release")
21+
endif()
22+
endif()
23+
24+
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
25+
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
26+
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
27+
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
28+
29+
# Use Unicode for all projects.
30+
add_definitions(-DUNICODE -D_UNICODE)
31+
32+
# Compilation settings that should be applied to most targets.
33+
function(APPLY_STANDARD_SETTINGS TARGET)
34+
target_compile_features(${TARGET} PUBLIC cxx_std_17)
35+
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
36+
target_compile_options(${TARGET} PRIVATE /EHsc)
37+
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
38+
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
39+
endfunction()
40+
41+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
42+
43+
# Flutter library and tool build rules.
44+
add_subdirectory(${FLUTTER_MANAGED_DIR})
45+
46+
# Application build
47+
add_subdirectory("runner")
48+
49+
# Generated plugin build rules, which manage building the plugins and adding
50+
# them to the application.
51+
include(flutter/generated_plugins.cmake)
52+
53+
54+
# === Installation ===
55+
# Support files are copied into place next to the executable, so that it can
56+
# run in place. This is done instead of making a separate bundle (as on Linux)
57+
# so that building and running from within Visual Studio will work.
58+
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
59+
# Make the "install" step default, as it's required to run.
60+
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
61+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
62+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
63+
endif()
64+
65+
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
66+
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
67+
68+
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
69+
COMPONENT Runtime)
70+
71+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
72+
COMPONENT Runtime)
73+
74+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
75+
COMPONENT Runtime)
76+
77+
if(PLUGIN_BUNDLED_LIBRARIES)
78+
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
79+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
80+
COMPONENT Runtime)
81+
endif()
82+
83+
# Fully re-copy the assets directory on each build to avoid having stale files
84+
# from a previous install.
85+
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
86+
install(CODE "
87+
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
88+
" COMPONENT Runtime)
89+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
90+
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
91+
92+
# Install the AOT library on non-Debug builds only.
93+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
94+
CONFIGURATIONS Profile;Release
95+
COMPONENT Runtime)

0 commit comments

Comments
 (0)