├── .flutter-plugins ├── .flutter-plugins-dependencies ├── .gitignore ├── .metadata ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── assets ├── demo.mov ├── screenshot-1.png └── screenshot-2.png ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Podfile │ ├── Podfile.lock │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── Icon-App-20x20@1x.png │ │ │ ├── Icon-App-20x20@2x.png │ │ │ ├── Icon-App-20x20@3x.png │ │ │ ├── Icon-App-29x29@1x.png │ │ │ ├── Icon-App-29x29@2x.png │ │ │ ├── Icon-App-29x29@3x.png │ │ │ ├── Icon-App-40x40@1x.png │ │ │ ├── Icon-App-40x40@2x.png │ │ │ ├── Icon-App-40x40@3x.png │ │ │ ├── Icon-App-60x60@2x.png │ │ │ ├── Icon-App-60x60@3x.png │ │ │ ├── Icon-App-76x76@1x.png │ │ │ ├── Icon-App-76x76@2x.png │ │ │ └── Icon-App-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ └── main.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Podfile │ ├── Podfile.lock │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── app_icon_1024.png │ │ │ ├── app_icon_128.png │ │ │ ├── app_icon_16.png │ │ │ ├── app_icon_256.png │ │ │ ├── app_icon_32.png │ │ │ ├── app_icon_512.png │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ ├── Configs │ │ ├── AppInfo.xcconfig │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── test │ └── widget_test.dart ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── flutter_simulator.dart └── src │ ├── app.dart │ ├── bindings │ ├── _bindings.dart │ ├── interceptable_binary_messenger.dart │ ├── interceptable_renderer_binding.dart │ ├── screen_interceptor.dart │ └── simulator_widgets_binding.dart │ ├── core │ ├── _core.dart │ ├── simulator_params.dart │ ├── system_platform_channel_interceptor.dart │ ├── system_text_input_channel_interceptor.dart │ ├── text_input │ │ └── simulated_ime.dart │ └── window_size_manager.dart │ ├── devices │ ├── _devices.dart │ ├── apple │ │ ├── _apple.dart │ │ ├── ios_keyboard_animation.dart │ │ └── iphone_14.dart │ └── core │ │ ├── device_frame.dart │ │ ├── device_info.dart │ │ ├── device_keyboard.dart │ │ └── device_orientation.dart │ ├── imports.dart │ ├── utils │ ├── _utils.dart │ ├── byte_data.dart │ ├── color.dart │ ├── list_extension.dart │ ├── screenshot.dart │ ├── scroll_behavior.dart │ └── size.dart │ └── widgets │ ├── _widgets.dart │ ├── app.dart │ ├── header │ └── header.dart │ ├── simulator.dart │ ├── simulator │ └── simulator_render_object.dart │ └── utils │ ├── animated_view_insets.dart │ └── resizable_gesture_detector.dart └── pubspec.yaml /.flutter-plugins: -------------------------------------------------------------------------------- 1 | # This is a generated file; do not edit or check into version control. 2 | flutter_desktop_cursor=/Users/kekland/.pub-cache/hosted/pub.dev/flutter_desktop_cursor-0.0.1/ 3 | path_provider=/Users/kekland/.pub-cache/hosted/pub.dev/path_provider-2.0.14/ 4 | path_provider_android=/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_android-2.0.25/ 5 | path_provider_foundation=/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.2/ 6 | path_provider_linux=/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10/ 7 | path_provider_windows=/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5/ 8 | screen_retriever=/Users/kekland/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/ 9 | url_launcher=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher-6.1.10/ 10 | url_launcher_android=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.27/ 11 | url_launcher_ios=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.4/ 12 | url_launcher_linux=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4/ 13 | url_launcher_macos=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.5/ 14 | url_launcher_web=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16/ 15 | url_launcher_windows=/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5/ 16 | window_manager=/Users/kekland/.pub-cache/git/window_manager-37ae2cf2cf8b82d50e08b3875a22f31201306982/ 17 | -------------------------------------------------------------------------------- /.flutter-plugins-dependencies: -------------------------------------------------------------------------------- 1 | {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.2/","native_build":true,"dependencies":[]},{"name":"url_launcher_ios","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_ios-6.1.4/","native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_android-2.0.25/","native_build":true,"dependencies":[]},{"name":"url_launcher_android","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_android-6.0.27/","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_desktop_cursor","path":"/Users/kekland/.pub-cache/hosted/pub.dev/flutter_desktop_cursor-0.0.1/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_foundation-2.2.2/","native_build":true,"dependencies":[]},{"name":"screen_retriever","path":"/Users/kekland/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"url_launcher_macos","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_macos-3.0.5/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/Users/kekland/.pub-cache/git/window_manager-37ae2cf2cf8b82d50e08b3875a22f31201306982/","native_build":true,"dependencies":["screen_retriever"]}],"linux":[{"name":"path_provider_linux","path":"/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_linux-2.1.10/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/kekland/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"url_launcher_linux","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_linux-3.0.4/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/Users/kekland/.pub-cache/git/window_manager-37ae2cf2cf8b82d50e08b3875a22f31201306982/","native_build":true,"dependencies":["screen_retriever"]}],"windows":[{"name":"path_provider_windows","path":"/Users/kekland/.pub-cache/hosted/pub.dev/path_provider_windows-2.1.5/","native_build":false,"dependencies":[]},{"name":"screen_retriever","path":"/Users/kekland/.pub-cache/hosted/pub.dev/screen_retriever-0.1.6/","native_build":true,"dependencies":[]},{"name":"url_launcher_windows","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_windows-3.0.5/","native_build":true,"dependencies":[]},{"name":"window_manager","path":"/Users/kekland/.pub-cache/git/window_manager-37ae2cf2cf8b82d50e08b3875a22f31201306982/","native_build":true,"dependencies":["screen_retriever"]}],"web":[{"name":"url_launcher_web","path":"/Users/kekland/.pub-cache/hosted/pub.dev/url_launcher_web-2.0.16/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_desktop_cursor","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"screen_retriever","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_android","url_launcher_ios","url_launcher_linux","url_launcher_macos","url_launcher_web","url_launcher_windows"]},{"name":"url_launcher_android","dependencies":[]},{"name":"url_launcher_ios","dependencies":[]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]},{"name":"window_manager","dependencies":["screen_retriever"]}],"date_created":"2023-04-23 20:36:58.991716","version":"3.7.10"} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 26 | /pubspec.lock 27 | **/doc/api/ 28 | .dart_tool/ 29 | .packages 30 | build/ 31 | .flutter-plugins 32 | .flutter-plugins-dependencies 33 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 4b12645012342076800eb701bcdfe18f87da21cf 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.0.1 2 | 3 | * TODO: Describe initial release. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | TODO: Add your license here. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_simulator 2 | 3 | # Deprecation notice 4 | 5 | **This package has been deprecated and archived in favor of https://github.com/kekland/simulator. It's a complete rewrite of this project and offers way more features.** 6 | 7 | **Warning: still highly experimental.** 8 | 9 |

10 | Light 11 |         12 | Dark 13 |

14 | 15 | https://github.com/kekland/flutter_simulator/blob/master/assets/demo.mov 16 | 17 | ## Features 18 | 19 | - Support for emulating any kind of a device 20 | - Rotating devices 21 | - Emulating the software keyboard 22 | - Brightness selector 23 | - Quickly screenshotting the screen/frame 24 | 25 | ## TODO 26 | 27 | - Improve documentation 28 | - Improve iOS keyboard 29 | - Emulating gestures (pinch, zoom, rotate) 30 | - Improve `window_manager` to handle some cases when the window is resized 31 | - Fix some antialiasing issues 32 | - Add more devices 33 | - Optimize rasterization performance (e.g. `screen_interceptor.dart`) - maybe add quality toggles? 34 | 35 | ## Devices 36 | 37 | - iPhone 14 38 | 39 | ## Installation 40 | 41 | This is still WIP, so I didn't publish it to Pub yet. Will do once it's more-less stable. 42 | 43 | Add this package with a git reference to `pubspec.yaml`: 44 | 45 | ```yaml 46 | flutter_simulator: 47 | git: 48 | url: https://github.com/kekland/flutter_simulator 49 | ref: f8368c5 50 | ``` 51 | 52 | Edit `main.dart` or create another entrypoint (something like `simulator.main.dart`), and tweak a couple of things: 53 | 54 | - Instead of calling `WidgetsFlutterBinding.ensureInitialized()`, call `await SimulatorWidgetsBinding.ensureInitialized()`. 55 | - Instead of calling `runApp(...)`, call `runFlutterSimulatorApp(...)` 56 | - Doesn't work with `FlutterNativeSplash`. Remove any calls to `FlutterNativeSplash.preserve()` in the entrypoint. This might be fixed in the future, but due to the native splash package delaying the first frame paint, the stuff needed to initialize the simulator are never called. 57 | 58 | ## Credits 59 | 60 | - https://github.com/leanflutter/window_manager 61 | - https://github.com/alexmercerind/flutter_acrylic 62 | - https://github.com/drogel/keyboard_attachable 63 | 64 | iPhone Simulator: 65 | - Apple 66 | - https://useyourloaf.com/blog/iphone-14-screen-sizes/ 67 | - https://medium.com/@nathangitter/reverse-engineering-the-iphone-x-home-indicator-color-a4c112f84d34 68 | 69 | Supporters: 70 | - Azat Smet 71 | - Dilmurat Yunussov 72 | - Daniyar Zakarin 73 | 74 | ## Contact me 75 | 76 | If you have any questions or suggestions feel free to open an issue or email me directly at `kk.erzhan@gmail.com`. 77 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | # Additional information about this file can be found at 4 | # https://dart.dev/guides/language/analysis-options 5 | -------------------------------------------------------------------------------- /assets/demo.mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/assets/demo.mov -------------------------------------------------------------------------------- /assets/screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/assets/screenshot-1.png -------------------------------------------------------------------------------- /assets/screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/assets/screenshot-2.png -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Symbolication related 36 | app.*.symbols 37 | 38 | # Obfuscation related 39 | app.*.map.json 40 | 41 | # Android Studio will place build artifacts here 42 | /android/app/debug 43 | /android/app/profile 44 | /android/app/release 45 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled. 5 | 6 | version: 7 | revision: 4b12645012342076800eb701bcdfe18f87da21cf 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 17 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 18 | - platform: android 19 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 20 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 21 | - platform: ios 22 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 23 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 24 | - platform: linux 25 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 26 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 27 | - platform: macos 28 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 29 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 30 | - platform: web 31 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 32 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 33 | - platform: windows 34 | create_revision: 4b12645012342076800eb701bcdfe18f87da21cf 35 | base_revision: 4b12645012342076800eb701bcdfe18f87da21cf 36 | 37 | # User provided section 38 | 39 | # List of Local paths (relative to this file) that should be 40 | # ignored by the migrate tool. 41 | # 42 | # Files that are not part of the templates will be ignored by default. 43 | unmanaged_files: 44 | - 'lib/main.dart' 45 | - 'ios/Runner.xcodeproj/project.pbxproj' 46 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) 13 | 14 | For help getting started with Flutter development, view the 15 | [online documentation](https://docs.flutter.dev/), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 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 30 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 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 12 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.example.example" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.7.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.2.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip 6 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '11.0' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | 34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 35 | end 36 | 37 | post_install do |installer| 38 | installer.pods_project.targets.each do |target| 39 | flutter_additional_ios_build_settings(target) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Flutter (1.0.0) 3 | - path_provider_foundation (0.0.1): 4 | - Flutter 5 | - FlutterMacOS 6 | - url_launcher_ios (0.0.1): 7 | - Flutter 8 | 9 | DEPENDENCIES: 10 | - Flutter (from `Flutter`) 11 | - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`) 12 | - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) 13 | 14 | EXTERNAL SOURCES: 15 | Flutter: 16 | :path: Flutter 17 | path_provider_foundation: 18 | :path: ".symlinks/plugins/path_provider_foundation/ios" 19 | url_launcher_ios: 20 | :path: ".symlinks/plugins/url_launcher_ios/ios" 21 | 22 | SPEC CHECKSUMS: 23 | Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 24 | path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 25 | url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4 26 | 27 | PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 28 | 29 | COCOAPODS: 1.11.2 30 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | UIApplicationSupportsIndirectInputEvents 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:flutter_simulator/flutter_simulator.dart'; 4 | 5 | void main() { 6 | runFlutterSimulatorApp(const MyApp()); 7 | } 8 | 9 | class MyApp extends StatefulWidget { 10 | const MyApp({super.key}); 11 | 12 | @override 13 | State createState() => _MyAppState(); 14 | } 15 | 16 | class _MyAppState extends State { 17 | @override 18 | void initState() { 19 | super.initState(); 20 | 21 | // SystemChrome.setPreferredOrientations([ 22 | // DeviceOrientation.portraitUp, 23 | // DeviceOrientation.portraitDown, 24 | // ]); 25 | } 26 | 27 | @override 28 | Widget build(BuildContext context) { 29 | final lightTheme = ThemeData.from( 30 | colorScheme: ColorScheme.fromSeed( 31 | seedColor: Colors.green, 32 | brightness: Brightness.dark, 33 | ), 34 | ).copyWith( 35 | scaffoldBackgroundColor: Colors.white, 36 | appBarTheme: ThemeData.light().appBarTheme.copyWith( 37 | color: Colors.white, 38 | foregroundColor: Colors.black, 39 | systemOverlayStyle: const SystemUiOverlayStyle( 40 | statusBarIconBrightness: Brightness.dark, 41 | statusBarBrightness: Brightness.light, 42 | ), 43 | ), 44 | ); 45 | 46 | final darkTheme = ThemeData.from( 47 | colorScheme: ColorScheme.fromSeed( 48 | seedColor: Colors.green, 49 | brightness: Brightness.dark, 50 | ), 51 | ); 52 | 53 | return MaterialApp( 54 | title: 'Flutter Demo', 55 | useInheritedMediaQuery: true, 56 | color: Colors.yellow, 57 | scrollBehavior: FlutterSimulatorScrollBehavior(), 58 | theme: lightTheme, 59 | darkTheme: darkTheme, 60 | themeMode: ThemeMode.system, 61 | debugShowCheckedModeBanner: false, 62 | home: const MyHomePage(title: 'Flutter Demo Home Page'), 63 | ); 64 | } 65 | } 66 | 67 | class MyHomePage extends StatefulWidget { 68 | const MyHomePage({ 69 | super.key, 70 | required this.title, 71 | }); 72 | 73 | final String title; 74 | 75 | @override 76 | State createState() => _MyHomePageState(); 77 | } 78 | 79 | class _MyHomePageState extends State { 80 | @override 81 | Widget build(BuildContext context) { 82 | final colors = [ 83 | Colors.white, 84 | Colors.red, 85 | Colors.green, 86 | Colors.blue, 87 | Colors.yellow, 88 | Colors.purple, 89 | Colors.orange, 90 | Colors.pink, 91 | Colors.teal, 92 | Colors.cyan, 93 | Colors.lime, 94 | Colors.indigo, 95 | Colors.brown, 96 | Colors.grey, 97 | Colors.amber, 98 | Colors.lightBlue, 99 | Colors.lightGreen, 100 | Colors.deepOrange, 101 | Colors.deepPurple, 102 | Colors.blueGrey, 103 | ]; 104 | 105 | return Scaffold( 106 | appBar: AppBar(title: Text(widget.title)), 107 | resizeToAvoidBottomInset: true, 108 | // bottomNavigationBar: BottomNavigationBar( 109 | // items: const [ 110 | // BottomNavigationBarItem( 111 | // icon: Icon(Icons.home), 112 | // label: 'Home', 113 | // ), 114 | // BottomNavigationBarItem( 115 | // icon: Icon(Icons.newspaper), 116 | // label: 'News', 117 | // ), 118 | // BottomNavigationBarItem( 119 | // icon: Icon(Icons.person), 120 | // label: 'Profile', 121 | // ), 122 | // ], 123 | // ), 124 | body: ListView.builder( 125 | itemBuilder: (context, i) { 126 | if (i % 5 == 0) { 127 | return const ColoredBox( 128 | color: Colors.white, 129 | child: SizedBox( 130 | width: double.infinity, 131 | height: 128.0, 132 | child: TextField( 133 | maxLines: 3, 134 | keyboardAppearance: Brightness.light, 135 | ), 136 | ), 137 | ); 138 | } 139 | if (i % 5 == 1) { 140 | return const ColoredBox( 141 | color: Colors.black, 142 | child: SizedBox( 143 | width: double.infinity, 144 | height: 128.0, 145 | child: TextField( 146 | maxLines: 3, 147 | ), 148 | ), 149 | ); 150 | } 151 | 152 | if (i % 5 == 2) { 153 | return Row( 154 | children: [ 155 | for (var j = 0; j < 5; j++) 156 | Expanded( 157 | child: ColoredBox( 158 | color: (i + j) % 2 == 0 ? Colors.white : Colors.black, 159 | child: const SizedBox( 160 | width: double.infinity, 161 | height: 128.0, 162 | ), 163 | ), 164 | ), 165 | ], 166 | ); 167 | } 168 | 169 | return Row( 170 | children: [ 171 | Expanded( 172 | child: ColoredBox( 173 | color: colors[i % colors.length], 174 | child: const SizedBox( 175 | width: double.infinity, 176 | height: 128.0, 177 | ), 178 | ), 179 | ), 180 | Expanded( 181 | child: ColoredBox( 182 | color: colors[(i + 5) % colors.length], 183 | child: const SizedBox( 184 | width: double.infinity, 185 | height: 128.0, 186 | ), 187 | ), 188 | ), 189 | ], 190 | ); 191 | }, 192 | ), 193 | ); 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.example.example") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Generated plugin build rules, which manage building the plugins and adding 90 | # them to the application. 91 | include(flutter/generated_plugins.cmake) 92 | 93 | 94 | # === Installation === 95 | # By default, "installing" just makes a relocatable bundle in the build 96 | # directory. 97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 100 | endif() 101 | 102 | # Start with a clean build bundle directory every time. 103 | install(CODE " 104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 105 | " COMPONENT Runtime) 106 | 107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 109 | 110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 111 | COMPONENT Runtime) 112 | 113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 114 | COMPONENT Runtime) 115 | 116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 117 | COMPONENT Runtime) 118 | 119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 120 | install(FILES "${bundled_library}" 121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 122 | COMPONENT Runtime) 123 | endforeach(bundled_library) 124 | 125 | # Fully re-copy the assets directory on each build to avoid having stale files 126 | # from a previous install. 127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 128 | install(CODE " 129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 130 | " COMPONENT Runtime) 131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 133 | 134 | # Install the AOT library on non-Debug builds only. 135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 137 | COMPONENT Runtime) 138 | endif() 139 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void fl_register_plugins(FlPluginRegistry* registry) { 14 | g_autoptr(FlPluginRegistrar) screen_retriever_registrar = 15 | fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin"); 16 | screen_retriever_plugin_register_with_registrar(screen_retriever_registrar); 17 | g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = 18 | fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); 19 | url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); 20 | g_autoptr(FlPluginRegistrar) window_manager_registrar = 21 | fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin"); 22 | window_manager_plugin_register_with_registrar(window_manager_registrar); 23 | } 24 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | screen_retriever 7 | url_launcher_linux 8 | window_manager 9 | ) 10 | 11 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 12 | ) 13 | 14 | set(PLUGIN_BUNDLED_LIBRARIES) 15 | 16 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 17 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 18 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 21 | endforeach(plugin) 22 | 23 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 24 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 25 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 26 | endforeach(ffi_plugin) 27 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "ephemeral/Flutter-Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | import flutter_desktop_cursor 9 | import path_provider_foundation 10 | import screen_retriever 11 | import url_launcher_macos 12 | import window_manager 13 | 14 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 15 | FlutterDesktopCursorPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopCursorPlugin")) 16 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) 17 | ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) 18 | UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) 19 | WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin")) 20 | } 21 | -------------------------------------------------------------------------------- /example/macos/Podfile: -------------------------------------------------------------------------------- 1 | platform :osx, '10.14' 2 | 3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 5 | 6 | project 'Runner', { 7 | 'Debug' => :debug, 8 | 'Profile' => :release, 9 | 'Release' => :release, 10 | } 11 | 12 | def flutter_root 13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) 14 | unless File.exist?(generated_xcode_build_settings_path) 15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" 16 | end 17 | 18 | File.foreach(generated_xcode_build_settings_path) do |line| 19 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 20 | return matches[1].strip if matches 21 | end 22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" 23 | end 24 | 25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 26 | 27 | flutter_macos_podfile_setup 28 | 29 | target 'Runner' do 30 | use_frameworks! 31 | use_modular_headers! 32 | 33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_macos_build_settings(target) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /example/macos/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - flutter_desktop_cursor (0.0.1): 3 | - FlutterMacOS 4 | - FlutterMacOS (1.0.0) 5 | - path_provider_foundation (0.0.1): 6 | - Flutter 7 | - FlutterMacOS 8 | - screen_retriever (0.0.1): 9 | - FlutterMacOS 10 | - url_launcher_macos (0.0.1): 11 | - FlutterMacOS 12 | - window_manager (0.2.0): 13 | - FlutterMacOS 14 | 15 | DEPENDENCIES: 16 | - flutter_desktop_cursor (from `Flutter/ephemeral/.symlinks/plugins/flutter_desktop_cursor/macos`) 17 | - FlutterMacOS (from `Flutter/ephemeral`) 18 | - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`) 19 | - screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`) 20 | - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) 21 | - window_manager (from `Flutter/ephemeral/.symlinks/plugins/window_manager/macos`) 22 | 23 | EXTERNAL SOURCES: 24 | flutter_desktop_cursor: 25 | :path: Flutter/ephemeral/.symlinks/plugins/flutter_desktop_cursor/macos 26 | FlutterMacOS: 27 | :path: Flutter/ephemeral 28 | path_provider_foundation: 29 | :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos 30 | screen_retriever: 31 | :path: Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos 32 | url_launcher_macos: 33 | :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos 34 | window_manager: 35 | :path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos 36 | 37 | SPEC CHECKSUMS: 38 | flutter_desktop_cursor: b8a6dd1f34dca571187d7b4a2b2c3cb5bcec087b 39 | FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 40 | path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 41 | screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38 42 | url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451 43 | window_manager: 3a1844359a6295ab1e47659b1a777e36773cd6e8 44 | 45 | PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 46 | 47 | COCOAPODS: 1.11.2 48 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @NSApplicationMain 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2023 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | # The following line prevents the package from being accidentally published to 4 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 5 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 6 | 7 | # The following defines the version and build number for your application. 8 | # A version number is three numbers separated by dots, like 1.2.43 9 | # followed by an optional build number separated by a +. 10 | # Both the version and the builder number may be overridden in flutter 11 | # build by specifying --build-name and --build-number, respectively. 12 | # In Android, build-name is used as versionName while build-number used as versionCode. 13 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 14 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. 15 | # Read more about iOS versioning at 16 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 | # In Windows, build-name is used as the major, minor, and patch parts 18 | # of the product and file versions while build-number is used as the build suffix. 19 | version: 1.0.0+1 20 | 21 | environment: 22 | sdk: '>=2.19.6 <3.0.0' 23 | 24 | # Dependencies specify other packages that your package needs in order to work. 25 | # To automatically upgrade your package dependencies to the latest versions 26 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 27 | # dependencies can be manually updated by changing the version numbers below to 28 | # the latest version available on pub.dev. To see which dependencies have newer 29 | # versions available, run `flutter pub outdated`. 30 | dependencies: 31 | flutter: 32 | sdk: flutter 33 | 34 | 35 | # The following adds the Cupertino Icons font to your application. 36 | # Use with the CupertinoIcons class for iOS style icons. 37 | cupertino_icons: ^1.0.2 38 | 39 | flutter_simulator: 40 | path: .. 41 | 42 | dev_dependencies: 43 | flutter_test: 44 | sdk: flutter 45 | 46 | # The "flutter_lints" package below contains a set of recommended lints to 47 | # encourage good coding practices. The lint set provided by the package is 48 | # activated in the `analysis_options.yaml` file located at the root of your 49 | # package. See that file for information about deactivating specific lint 50 | # rules and activating additional ones. 51 | flutter_lints: ^2.0.0 52 | 53 | # For information on the generic Dart part of this file, see the 54 | # following page: https://dart.dev/tools/pub/pubspec 55 | 56 | # The following section is specific to Flutter packages. 57 | flutter: 58 | 59 | # The following line ensures that the Material Icons font is 60 | # included with your application, so that you can use the icons in 61 | # the material Icons class. 62 | uses-material-design: true 63 | 64 | # To add assets to your application, add an assets section, like this: 65 | # assets: 66 | # - images/a_dot_burr.jpeg 67 | # - images/a_dot_ham.jpeg 68 | 69 | # An image asset can refer to one or more resolution-specific "variants", see 70 | # https://flutter.dev/assets-and-images/#resolution-aware 71 | 72 | # For details regarding adding assets from package dependencies, see 73 | # https://flutter.dev/assets-and-images/#from-packages 74 | 75 | # To add custom fonts to your application, add a fonts section here, 76 | # in this "flutter" section. Each entry in this list should have a 77 | # "family" key with the font family name, and a "fonts" key with a 78 | # list giving the asset and other descriptors for the font. For 79 | # example: 80 | # fonts: 81 | # - family: Schyler 82 | # fonts: 83 | # - asset: fonts/Schyler-Regular.ttf 84 | # - asset: fonts/Schyler-Italic.ttf 85 | # style: italic 86 | # - family: Trajan Pro 87 | # fonts: 88 | # - asset: fonts/TrajanPro.ttf 89 | # - asset: fonts/TrajanPro_Bold.ttf 90 | # weight: 700 91 | # 92 | # For details regarding fonts from package dependencies, 93 | # see https://flutter.dev/custom-fonts/#from-packages 94 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 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 in the flutter_test package. 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(const 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 | } 31 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 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 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 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/ 18 | -------------------------------------------------------------------------------- /example/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.14) 3 | project(example LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "example") 8 | 9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 10 | # versions of CMake. 11 | cmake_policy(SET CMP0063 NEW) 12 | 13 | # Define build configuration option. 14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 15 | if(IS_MULTICONFIG) 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" 17 | CACHE STRING "" FORCE) 18 | else() 19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 20 | set(CMAKE_BUILD_TYPE "Debug" CACHE 21 | STRING "Flutter build mode" FORCE) 22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 23 | "Debug" "Profile" "Release") 24 | endif() 25 | endif() 26 | # Define settings for the Profile build mode. 27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") 28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") 29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") 30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") 31 | 32 | # Use Unicode for all projects. 33 | add_definitions(-DUNICODE -D_UNICODE) 34 | 35 | # Compilation settings that should be applied to most targets. 36 | # 37 | # Be cautious about adding new options here, as plugins use this function by 38 | # default. In most cases, you should add new options to specific targets instead 39 | # of modifying this function. 40 | function(APPLY_STANDARD_SETTINGS TARGET) 41 | target_compile_features(${TARGET} PUBLIC cxx_std_17) 42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") 43 | target_compile_options(${TARGET} PRIVATE /EHsc) 44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") 45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") 46 | endfunction() 47 | 48 | # Flutter library and tool build rules. 49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 50 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 51 | 52 | # Application build; see runner/CMakeLists.txt. 53 | add_subdirectory("runner") 54 | 55 | # Generated plugin build rules, which manage building the plugins and adding 56 | # them to the application. 57 | include(flutter/generated_plugins.cmake) 58 | 59 | 60 | # === Installation === 61 | # Support files are copied into place next to the executable, so that it can 62 | # run in place. This is done instead of making a separate bundle (as on Linux) 63 | # so that building and running from within Visual Studio will work. 64 | set(BUILD_BUNDLE_DIR "$") 65 | # Make the "install" step default, as it's required to run. 66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) 67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 69 | endif() 70 | 71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") 73 | 74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 75 | COMPONENT Runtime) 76 | 77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 78 | COMPONENT Runtime) 79 | 80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 81 | COMPONENT Runtime) 82 | 83 | if(PLUGIN_BUNDLED_LIBRARIES) 84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" 85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 86 | COMPONENT Runtime) 87 | endif() 88 | 89 | # Fully re-copy the assets directory on each build to avoid having stale files 90 | # from a previous install. 91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 92 | install(CODE " 93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 94 | " COMPONENT Runtime) 95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 97 | 98 | # Install the AOT library on non-Debug builds only. 99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 100 | CONFIGURATIONS Profile;Release 101 | COMPONENT Runtime) 102 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # Set fallback configurations for older versions of the flutter tool. 14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM) 15 | set(FLUTTER_TARGET_PLATFORM "windows-x64") 16 | endif() 17 | 18 | # === Flutter Library === 19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 20 | 21 | # Published to parent scope for install step. 22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 26 | 27 | list(APPEND FLUTTER_LIBRARY_HEADERS 28 | "flutter_export.h" 29 | "flutter_windows.h" 30 | "flutter_messenger.h" 31 | "flutter_plugin_registrar.h" 32 | "flutter_texture_registrar.h" 33 | ) 34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 35 | add_library(flutter INTERFACE) 36 | target_include_directories(flutter INTERFACE 37 | "${EPHEMERAL_DIR}" 38 | ) 39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 40 | add_dependencies(flutter flutter_assemble) 41 | 42 | # === Wrapper === 43 | list(APPEND CPP_WRAPPER_SOURCES_CORE 44 | "core_implementations.cc" 45 | "standard_codec.cc" 46 | ) 47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 49 | "plugin_registrar.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 52 | list(APPEND CPP_WRAPPER_SOURCES_APP 53 | "flutter_engine.cc" 54 | "flutter_view_controller.cc" 55 | ) 56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 57 | 58 | # Wrapper sources needed for a plugin. 59 | add_library(flutter_wrapper_plugin STATIC 60 | ${CPP_WRAPPER_SOURCES_CORE} 61 | ${CPP_WRAPPER_SOURCES_PLUGIN} 62 | ) 63 | apply_standard_settings(flutter_wrapper_plugin) 64 | set_target_properties(flutter_wrapper_plugin PROPERTIES 65 | POSITION_INDEPENDENT_CODE ON) 66 | set_target_properties(flutter_wrapper_plugin PROPERTIES 67 | CXX_VISIBILITY_PRESET hidden) 68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 69 | target_include_directories(flutter_wrapper_plugin PUBLIC 70 | "${WRAPPER_ROOT}/include" 71 | ) 72 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 73 | 74 | # Wrapper sources needed for the runner. 75 | add_library(flutter_wrapper_app STATIC 76 | ${CPP_WRAPPER_SOURCES_CORE} 77 | ${CPP_WRAPPER_SOURCES_APP} 78 | ) 79 | apply_standard_settings(flutter_wrapper_app) 80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 81 | target_include_directories(flutter_wrapper_app PUBLIC 82 | "${WRAPPER_ROOT}/include" 83 | ) 84 | add_dependencies(flutter_wrapper_app flutter_assemble) 85 | 86 | # === Flutter tool backend === 87 | # _phony_ is a non-existent file to force this command to run every time, 88 | # since currently there's no way to get a full input/output list from the 89 | # flutter tool. 90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 92 | add_custom_command( 93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 95 | ${CPP_WRAPPER_SOURCES_APP} 96 | ${PHONY_OUTPUT} 97 | COMMAND ${CMAKE_COMMAND} -E env 98 | ${FLUTTER_TOOL_ENVIRONMENT} 99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 100 | ${FLUTTER_TARGET_PLATFORM} $ 101 | VERBATIM 102 | ) 103 | add_custom_target(flutter_assemble DEPENDS 104 | "${FLUTTER_LIBRARY}" 105 | ${FLUTTER_LIBRARY_HEADERS} 106 | ${CPP_WRAPPER_SOURCES_CORE} 107 | ${CPP_WRAPPER_SOURCES_PLUGIN} 108 | ${CPP_WRAPPER_SOURCES_APP} 109 | ) 110 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | void RegisterPlugins(flutter::PluginRegistry* registry) { 14 | ScreenRetrieverPluginRegisterWithRegistrar( 15 | registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); 16 | UrlLauncherWindowsRegisterWithRegistrar( 17 | registry->GetRegistrarForPlugin("UrlLauncherWindows")); 18 | WindowManagerPluginRegisterWithRegistrar( 19 | registry->GetRegistrarForPlugin("WindowManagerPlugin")); 20 | } 21 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | screen_retriever 7 | url_launcher_windows 8 | window_manager 9 | ) 10 | 11 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 12 | ) 13 | 14 | set(PLUGIN_BUNDLED_LIBRARIES) 15 | 16 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 17 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 18 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 21 | endforeach(plugin) 22 | 23 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 24 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 25 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 26 | endforeach(ffi_plugin) 27 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Add preprocessor definitions for the build version. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") 25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") 26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") 27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") 28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") 29 | 30 | # Disable Windows macros that collide with C++ standard library functions. 31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 32 | 33 | # Add dependency libraries and include directories. Add any application-specific 34 | # dependencies here. 35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") 37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 38 | 39 | # Run the Flutter tool portions of the build. This must not be removed. 40 | add_dependencies(${BINARY_NAME} flutter_assemble) 41 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 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 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD) 64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0,0 67 | #endif 68 | 69 | #if defined(FLUTTER_VERSION) 70 | #define VERSION_AS_STRING FLUTTER_VERSION 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", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2023 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 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 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( 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()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | 30 | flutter_controller_->engine()->SetNextFrameCallback([&]() { 31 | this->Show(); 32 | }); 33 | 34 | // Flutter can complete the first frame before the "show window" callback is 35 | // registered. The following call ensures a frame is pending to ensure the 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. 37 | flutter_controller_->ForceRedraw(); 38 | 39 | return true; 40 | } 41 | 42 | void FlutterWindow::OnDestroy() { 43 | if (flutter_controller_) { 44 | flutter_controller_ = nullptr; 45 | } 46 | 47 | Win32Window::OnDestroy(); 48 | } 49 | 50 | LRESULT 51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 52 | WPARAM const wparam, 53 | LPARAM const lparam) noexcept { 54 | // Give Flutter, including plugins, an opportunity to handle window messages. 55 | if (flutter_controller_) { 56 | std::optional result = 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 58 | lparam); 59 | if (result) { 60 | return *result; 61 | } 62 | } 63 | 64 | switch (message) { 65 | case WM_FONTCHANGE: 66 | flutter_controller_->engine()->ReloadSystemFonts(); 67 | break; 68 | } 69 | 70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 71 | } 72 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.Create(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kekland/flutter_simulator/60572b717be35d2f74057f88e643de7d99f21342/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates a win32 window with |title| that is positioned and sized using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size this function will scale the inputted width and height as 35 | // as appropriate for the default monitor. The window is invisible until 36 | // |Show| is called. Returns true if the window was created successfully. 37 | bool Create(const std::wstring& title, const Point& origin, const Size& size); 38 | 39 | // Show the current window. Returns true if the window was successfully shown. 40 | bool Show(); 41 | 42 | // Release OS resources associated with window. 43 | void Destroy(); 44 | 45 | // Inserts |content| into the window tree. 46 | void SetChildContent(HWND content); 47 | 48 | // Returns the backing Window handle to enable clients to set icon and other 49 | // window properties. Returns nullptr if the window has been destroyed. 50 | HWND GetHandle(); 51 | 52 | // If true, closing this window will quit the application. 53 | void SetQuitOnClose(bool quit_on_close); 54 | 55 | // Return a RECT representing the bounds of the current client area. 56 | RECT GetClientArea(); 57 | 58 | protected: 59 | // Processes and route salient window messages for mouse handling, 60 | // size change and DPI. Delegates handling of these to member overloads that 61 | // inheriting classes can handle. 62 | virtual LRESULT MessageHandler(HWND window, 63 | UINT const message, 64 | WPARAM const wparam, 65 | LPARAM const lparam) noexcept; 66 | 67 | // Called when CreateAndShow is called, allowing subclass window-related 68 | // setup. Subclasses should return false if setup fails. 69 | virtual bool OnCreate(); 70 | 71 | // Called when Destroy is called. 72 | virtual void OnDestroy(); 73 | 74 | private: 75 | friend class WindowClassRegistrar; 76 | 77 | // OS callback called by message pump. Handles the WM_NCCREATE message which 78 | // is passed when the non-client area is being created and enables automatic 79 | // non-client DPI scaling so that the non-client area automatically 80 | // responsponds to changes in DPI. All other messages are handled by 81 | // MessageHandler. 82 | static LRESULT CALLBACK WndProc(HWND const window, 83 | UINT const message, 84 | WPARAM const wparam, 85 | LPARAM const lparam) noexcept; 86 | 87 | // Retrieves a class instance pointer for |window| 88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 89 | 90 | // Update the window frame's theme to match the system theme. 91 | static void UpdateTheme(HWND const window); 92 | 93 | bool quit_on_close_ = false; 94 | 95 | // window handle for top level window. 96 | HWND window_handle_ = nullptr; 97 | 98 | // window handle for hosted content. 99 | HWND child_content_ = nullptr; 100 | }; 101 | 102 | #endif // RUNNER_WIN32_WINDOW_H_ 103 | -------------------------------------------------------------------------------- /lib/flutter_simulator.dart: -------------------------------------------------------------------------------- 1 | export 'src/imports.dart'; 2 | export 'src/app.dart'; -------------------------------------------------------------------------------- /lib/src/app.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_simulator/src/imports.dart'; 3 | import 'package:window_manager/window_manager.dart'; 4 | 5 | Future runFlutterSimulatorApp(Widget app) async { 6 | await SimulatorWidgetsBinding.ensureInitialized(); 7 | 8 | // TODO: Make this preserve the old size 9 | const windowOptions = WindowOptions( 10 | backgroundColor: Colors.transparent, 11 | skipTaskbar: false, 12 | ); 13 | 14 | await windowManager.waitUntilReadyToShow( 15 | windowOptions, 16 | () async { 17 | await windowManager.setAsFrameless(); 18 | await windowManager.show(); 19 | }, 20 | ); 21 | 22 | SimulatorWidgetsBinding.instance 23 | ..attachRootWidget(FlutterSimulatorApp(appChild: app)) 24 | ..scheduleWarmUpFrame(); 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/bindings/_bindings.dart: -------------------------------------------------------------------------------- 1 | export 'interceptable_binary_messenger.dart'; 2 | export 'interceptable_renderer_binding.dart'; 3 | export 'screen_interceptor.dart'; 4 | export 'simulator_widgets_binding.dart'; 5 | -------------------------------------------------------------------------------- /lib/src/bindings/interceptable_renderer_binding.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: invalid_use_of_visible_for_testing_member, invalid_use_of_protected_member 2 | 3 | import 'dart:developer'; 4 | 5 | import 'package:flutter/foundation.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter/rendering.dart'; 8 | import 'package:flutter/services.dart'; 9 | import 'dart:ui' as ui; 10 | 11 | import 'package:flutter_simulator/flutter_simulator.dart'; 12 | 13 | /// A mixin on [WidgetsFlutterBinding] that allows for intercepting the scene 14 | /// building process. It initializes the [renderView] with a custom 15 | /// implementation called [InterceptableRenderView]. 16 | mixin InterceptableRendererBinding on WidgetsFlutterBinding { 17 | void initRenderView() { 18 | appRenderView = InterceptableRenderView( 19 | configuration: null, 20 | view: PlatformDispatcher.instance.implicitView!, 21 | ); 22 | 23 | appRenderView.configuration = createViewConfigurationFor(appRenderView); 24 | } 25 | 26 | late final InterceptableRenderView appRenderView; 27 | 28 | @override 29 | InterceptableRenderView get renderView => 30 | super.renderViews.first as InterceptableRenderView; 31 | } 32 | 33 | /// A [RenderView] that allows for intercepting the scene building process. 34 | /// 35 | /// This is used to allow for the device frame to be painted on top of the 36 | /// Flutter app. 37 | class InterceptableRenderView extends RenderView { 38 | InterceptableRenderView({ 39 | required super.configuration, 40 | required ui.FlutterView view, 41 | }) : _view = view, 42 | super(view: view); 43 | 44 | final ui.FlutterView _view; 45 | ui.FlutterView get simulatorView => _view; 46 | 47 | /// Callback for before the scene is built in [compositeFrame]. 48 | final onBeforeBuildSceneNotifier = ChangeNotifier(); 49 | 50 | /// Callback for after the scene is built in [compositeFrame]. 51 | final onAfterBuildSceneNotifier = ChangeNotifier(); 52 | 53 | /// Copy of the original [RenderView.compositeFrame], with callbacks for 54 | /// before and after the scene is built. 55 | @override 56 | void compositeFrame() { 57 | if (!kReleaseMode) { 58 | Timeline.startSync('COMPOSITING'); 59 | } 60 | try { 61 | onBeforeBuildSceneNotifier.notifyListeners(); 62 | 63 | final ui.SceneBuilder builder = ui.SceneBuilder(); 64 | final ui.Scene scene = layer!.buildScene(builder); 65 | 66 | if (automaticSystemUiAdjustment) { 67 | _updateSystemChrome(); 68 | } 69 | 70 | onAfterBuildSceneNotifier.notifyListeners(); 71 | 72 | _view.render(scene); 73 | scene.dispose(); 74 | 75 | assert(() { 76 | if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled) { 77 | debugCurrentRepaintColor = debugCurrentRepaintColor 78 | .withHue((debugCurrentRepaintColor.hue + 2.0) % 360.0); 79 | } 80 | return true; 81 | }()); 82 | } finally { 83 | if (!kReleaseMode) { 84 | Timeline.finishSync(); 85 | } 86 | } 87 | } 88 | 89 | /// Copy of [RenderView._updateSystemChrome] with the following changes: 90 | /// - [RenderView] is replaced with [InterceptableRenderView] 91 | /// - Utilizes the device screen area instead of the entire screen. 92 | void _updateSystemChrome() { 93 | final deviceScreenKey = SimulatorWidgetsBinding.instance.deviceScreenKey; 94 | final deviceScreenRenderObject = 95 | SimulatorWidgetsBinding.instance.deviceScreenRenderObject; 96 | 97 | final mediaQuery = MediaQuery.of(deviceScreenKey.currentContext!); 98 | 99 | final layer = deviceScreenRenderObject.layer; 100 | if (layer == null) return; 101 | 102 | // Take overlay style from the place where a system status bar and system 103 | // navigation bar are placed to update system style overlay. 104 | // The center of the system navigation bar and the center of the status bar 105 | // are used to get SystemUiOverlayStyle's to update system overlay appearance. 106 | // 107 | // Horizontal center of the screen 108 | // V 109 | // ++++++++++++++++++++++++++ 110 | // | | 111 | // | System status bar | <- Vertical center of the status bar 112 | // | | 113 | // ++++++++++++++++++++++++++ 114 | // | | 115 | // | Content | 116 | // ~ ~ 117 | // | | 118 | // ++++++++++++++++++++++++++ 119 | // | | 120 | // | System navigation bar | <- Vertical center of the navigation bar 121 | // | | 122 | // ++++++++++++++++++++++++++ <- bounds.bottom 123 | final Rect bounds = deviceScreenRenderObject.paintBounds; 124 | // Center of the status bar 125 | final Offset top = Offset( 126 | // Horizontal center of the screen 127 | bounds.center.dx, 128 | // The vertical center of the system status bar. The system status bar 129 | // height is kept as top window padding. 130 | mediaQuery.padding.top / 2.0, 131 | ); 132 | // Center of the navigation bar 133 | final Offset bottom = Offset( 134 | // Horizontal center of the screen 135 | bounds.center.dx, 136 | // Vertical center of the system navigation bar. The system navigation bar 137 | // height is kept as bottom window padding. The "1" needs to be subtracted 138 | // from the bottom because available pixels are in (0..bottom) range. 139 | // I.e. for a device with 1920 height, bound.bottom is 1920, but the most 140 | // bottom drawn pixel is at 1919 position. 141 | bounds.bottom - 1.0 - mediaQuery.padding.bottom / 2.0, 142 | ); 143 | 144 | final layerOffset = (layer as OffsetLayer).offset; 145 | 146 | final SystemUiOverlayStyle? upperOverlayStyle = 147 | layer.find(top + layerOffset); 148 | // Only android has a customizable system navigation bar. 149 | SystemUiOverlayStyle? lowerOverlayStyle; 150 | switch (defaultTargetPlatform) { 151 | case TargetPlatform.android: 152 | lowerOverlayStyle = layer.find( 153 | bottom + layerOffset, 154 | ); 155 | break; 156 | case TargetPlatform.iOS: 157 | case TargetPlatform.fuchsia: 158 | case TargetPlatform.linux: 159 | case TargetPlatform.macOS: 160 | case TargetPlatform.windows: 161 | break; 162 | } 163 | // If there are no overlay style in the UI don't bother updating. 164 | if (upperOverlayStyle == null && lowerOverlayStyle == null) { 165 | return; 166 | } 167 | 168 | // If both are not null, the upper provides the status bar properties and the lower provides 169 | // the system navigation bar properties. This is done for advanced use cases where a widget 170 | // on the top (for instance an app bar) will create an annotated region to set the status bar 171 | // style and another widget on the bottom will create an annotated region to set the system 172 | // navigation bar style. 173 | if (upperOverlayStyle != null && lowerOverlayStyle != null) { 174 | final SystemUiOverlayStyle overlayStyle = SystemUiOverlayStyle( 175 | statusBarBrightness: upperOverlayStyle.statusBarBrightness, 176 | statusBarIconBrightness: upperOverlayStyle.statusBarIconBrightness, 177 | statusBarColor: upperOverlayStyle.statusBarColor, 178 | systemStatusBarContrastEnforced: 179 | upperOverlayStyle.systemStatusBarContrastEnforced, 180 | systemNavigationBarColor: lowerOverlayStyle.systemNavigationBarColor, 181 | systemNavigationBarDividerColor: 182 | lowerOverlayStyle.systemNavigationBarDividerColor, 183 | systemNavigationBarIconBrightness: 184 | lowerOverlayStyle.systemNavigationBarIconBrightness, 185 | systemNavigationBarContrastEnforced: 186 | lowerOverlayStyle.systemNavigationBarContrastEnforced, 187 | ); 188 | SystemChrome.setSystemUIOverlayStyle(overlayStyle); 189 | return; 190 | } 191 | // If only one of the upper or the lower overlay style is not null, it provides all properties. 192 | // This is done for developer convenience as it allows setting both status bar style and 193 | // navigation bar style using only one annotated region layer (for instance the one 194 | // automatically created by an [AppBar]). 195 | final bool isAndroid = defaultTargetPlatform == TargetPlatform.android; 196 | final SystemUiOverlayStyle definedOverlayStyle = 197 | (upperOverlayStyle ?? lowerOverlayStyle)!; 198 | final SystemUiOverlayStyle overlayStyle = SystemUiOverlayStyle( 199 | statusBarBrightness: definedOverlayStyle.statusBarBrightness, 200 | statusBarIconBrightness: definedOverlayStyle.statusBarIconBrightness, 201 | statusBarColor: definedOverlayStyle.statusBarColor, 202 | systemStatusBarContrastEnforced: 203 | definedOverlayStyle.systemStatusBarContrastEnforced, 204 | systemNavigationBarColor: 205 | isAndroid ? definedOverlayStyle.systemNavigationBarColor : null, 206 | systemNavigationBarDividerColor: isAndroid 207 | ? definedOverlayStyle.systemNavigationBarDividerColor 208 | : null, 209 | systemNavigationBarIconBrightness: isAndroid 210 | ? definedOverlayStyle.systemNavigationBarIconBrightness 211 | : null, 212 | systemNavigationBarContrastEnforced: isAndroid 213 | ? definedOverlayStyle.systemNavigationBarContrastEnforced 214 | : null, 215 | ); 216 | SystemChrome.setSystemUIOverlayStyle(overlayStyle); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /lib/src/bindings/screen_interceptor.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | import 'package:flutter_simulator/src/imports.dart'; 4 | 5 | mixin ScreenInterceptor on WidgetsFlutterBinding { 6 | ByteData? screenByteData; 7 | Size? screenByteDataSize; 8 | 9 | void initScreenInterceptor() { 10 | final binding = this as SimulatorWidgetsBinding; 11 | 12 | binding.appRenderView.onAfterBuildSceneNotifier.addListener(() { 13 | final image = binding.deviceScreenRenderObject.toImageSync(); 14 | 15 | image.toByteData().then((byteData) { 16 | if (byteData == null) return; 17 | 18 | screenByteData = byteData; 19 | screenByteDataSize = Size( 20 | image.width.toDouble(), 21 | image.height.toDouble(), 22 | ); 23 | 24 | image.dispose(); 25 | }); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/bindings/simulator_widgets_binding.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import 'package:flutter/rendering.dart'; 3 | import 'package:flutter/widgets.dart'; 4 | import 'package:flutter_simulator/flutter_simulator.dart'; 5 | 6 | import 'package:window_manager/window_manager.dart'; 7 | 8 | /// A [WidgetsBinding] that can be used to run the Flutter Simulator. 9 | /// 10 | /// This binding can intercept system calls through 11 | /// [InterceptableDefaultBinaryMessengerBinding] and the rendering process 12 | /// through [InterceptableRendererBinding]. 13 | class SimulatorWidgetsBinding extends WidgetsFlutterBinding 14 | with 15 | InterceptableDefaultBinaryMessengerBinding, 16 | InterceptableRendererBinding, 17 | ScreenInterceptor { 18 | static Future ensureInitialized() async { 19 | if (_instance != null) { 20 | return _instance!; 21 | } 22 | 23 | _instance = SimulatorWidgetsBinding(); 24 | _instance!.initRenderView(); 25 | 26 | await windowManager.ensureInitialized(); 27 | _instance!.initScreenInterceptor(); 28 | 29 | return _instance!; 30 | } 31 | 32 | static SimulatorWidgetsBinding get instance => 33 | BindingBase.checkInstance(_instance); 34 | 35 | static SimulatorWidgetsBinding? _instance; 36 | 37 | /// The widget that contains the device screen is keyed with this key. 38 | final deviceScreenKey = GlobalKey(); 39 | 40 | /// Render object of the device screen. 41 | RenderRepaintBoundary get deviceScreenRenderObject => 42 | deviceScreenKey.currentContext!.findRenderObject()! 43 | as RenderRepaintBoundary; 44 | 45 | /// The widget that contains the device frame is keyed with this key. 46 | final deviceFrameKey = GlobalKey(); 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/core/_core.dart: -------------------------------------------------------------------------------- 1 | export 'text_input/simulated_ime.dart'; 2 | export 'simulator_params.dart'; 3 | export 'system_platform_channel_interceptor.dart'; 4 | export 'system_text_input_channel_interceptor.dart'; 5 | export 'window_size_manager.dart'; 6 | -------------------------------------------------------------------------------- /lib/src/core/simulator_params.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | import 'dart:ui'; 3 | 4 | import 'package:flutter/services.dart'; 5 | import 'package:flutter/widgets.dart'; 6 | import 'package:flutter_simulator/src/imports.dart'; 7 | 8 | /// Set of parameters in [SimulatorParams] that should be animated. 9 | class _AnimatedSimulatorParams { 10 | _AnimatedSimulatorParams({ 11 | required this.deviceOrientationRad, 12 | }); 13 | 14 | _AnimatedSimulatorParams.fromParams(SimulatorParams params) 15 | : this( 16 | deviceOrientationRad: params._deviceOrientationRad, 17 | ); 18 | 19 | final double deviceOrientationRad; 20 | 21 | static _AnimatedSimulatorParams lerp( 22 | _AnimatedSimulatorParams? a, 23 | _AnimatedSimulatorParams? b, 24 | double t, 25 | ) { 26 | if (a == null && b == null) throw Exception('a and b cannot be null'); 27 | 28 | final fromParams = a ?? b!; 29 | final toParams = b ?? a!; 30 | 31 | return _AnimatedSimulatorParams( 32 | deviceOrientationRad: lerpDouble( 33 | fromParams.deviceOrientationRad, 34 | toParams.deviceOrientationRad, 35 | t, 36 | )!, 37 | ); 38 | } 39 | 40 | SimulatorParams toParams(SimulatorParams params) { 41 | return params.copyWith( 42 | deviceOrientationRad: deviceOrientationRad, 43 | deviceScreenSizeOverride: params.deviceScreenSizeOverride, 44 | deviceOrientationRadOverride: params.deviceOrientationRadOverride, 45 | ); 46 | } 47 | 48 | @override 49 | int get hashCode => deviceOrientationRad.hashCode; 50 | 51 | @override 52 | bool operator ==(Object other) => 53 | identical(this, other) || 54 | other is _AnimatedSimulatorParams && 55 | deviceOrientationRad == other.deviceOrientationRad; 56 | } 57 | 58 | /// Set of parameters to configure the simulator. 59 | class SimulatorParams { 60 | const SimulatorParams({ 61 | required this.deviceInfo, 62 | required double deviceOrientationRad, 63 | required this.previousScreenOrientation, 64 | required this.simulatorBrightness, 65 | required this.systemUiOverlayStyle, 66 | required this.isKeyboardVisible, 67 | this.applicationSwitcherDescription, 68 | this.appPreferredOrientations, 69 | this.deviceScreenSizeOverride, 70 | this.deviceOrientationRadOverride, 71 | }) : _deviceOrientationRad = deviceOrientationRad; 72 | 73 | /// Current device's info 74 | final DeviceInfo deviceInfo; 75 | 76 | /// Physical device orientation in radians 77 | final double _deviceOrientationRad; 78 | double get deviceOrientationRad => 79 | deviceOrientationRadOverride ?? _deviceOrientationRad; 80 | 81 | /// Screen orientation in the previous frame 82 | final DeviceOrientation previousScreenOrientation; 83 | 84 | /// Brightness of the simulator 85 | final Brightness simulatorBrightness; 86 | 87 | /// Intercepted [SystemUiOverlayStyle] from the app 88 | final SystemUiOverlayStyle systemUiOverlayStyle; 89 | 90 | /// Intercepted [ApplicationSwitcherDescription] from the app 91 | final ApplicationSwitcherDescription? applicationSwitcherDescription; 92 | 93 | /// Intercepted [Set] from the app 94 | final Set? appPreferredOrientations; 95 | 96 | /// Whether the keyboard is shown 97 | final bool isKeyboardVisible; 98 | 99 | final Size? deviceScreenSizeOverride; 100 | 101 | final double? deviceOrientationRadOverride; 102 | 103 | Size get deviceScreenSize => 104 | deviceScreenSizeOverride ?? deviceInfo.screenSize; 105 | 106 | Size get phyiscalPixelsScreenSize => 107 | deviceScreenSize * deviceInfo.devicePixelRatio; 108 | 109 | /// Returns the preferred (raw) screen orientation based on the 110 | /// [deviceOrientationRad] 111 | DeviceOrientation get rawDeviceScreenOrientation { 112 | var rotation = deviceOrientationRad - 113 | (deviceOrientationRad / (2 * pi)).floor() * (2 * pi); 114 | 115 | if (rotation < 0) rotation += 2 * pi; 116 | 117 | if (rotation < pi / 4) return DeviceOrientation.portraitUp; 118 | if (rotation < 3 * pi / 4) return DeviceOrientation.landscapeRight; 119 | if (rotation < 5 * pi / 4) return DeviceOrientation.portraitDown; 120 | if (rotation < 7 * pi / 4) return DeviceOrientation.landscapeLeft; 121 | 122 | return DeviceOrientation.portraitUp; 123 | } 124 | 125 | Set get _allowedOrientations => deviceInfo 126 | .allowedOrientations 127 | .intersection(appPreferredOrientations ?? deviceInfo.allowedOrientations); 128 | 129 | /// Returns the screen orientation based on the raw orientation from 130 | /// [rawDeviceScreenOrientation] and the [allowedOrientations] from 131 | /// [deviceInfo]. 132 | DeviceOrientation get deviceScreenOrientation { 133 | if (_allowedOrientations.isEmpty) { 134 | throw Exception('allowedOrientations cannot be empty'); 135 | } 136 | 137 | final preferredOrientation = rawDeviceScreenOrientation; 138 | 139 | if (_allowedOrientations.contains(preferredOrientation)) { 140 | return preferredOrientation; 141 | } 142 | 143 | return _allowedOrientations.contains(previousScreenOrientation) 144 | ? previousScreenOrientation 145 | : _allowedOrientations.first; 146 | } 147 | 148 | DeviceFrame get deviceFrame => deviceInfo.deviceFrame; 149 | 150 | Size get orientedScreenSize => 151 | deviceScreenOrientation.transformSize(deviceInfo.screenSize); 152 | 153 | EdgeInsets get viewPadding => 154 | deviceInfo.viewPaddings[deviceScreenOrientation]!; 155 | 156 | SimulatorParams copyWith({ 157 | DeviceInfo? deviceInfo, 158 | double? deviceOrientationRad, 159 | Brightness? simulatorBrightness, 160 | SystemUiOverlayStyle? systemUiOverlayStyle, 161 | ApplicationSwitcherDescription? applicationSwitcherDescription, 162 | List? appPreferredOrientations, 163 | bool? isKeyboardVisible, 164 | Size? deviceScreenSizeOverride, 165 | double? deviceOrientationRadOverride, 166 | }) { 167 | return SimulatorParams( 168 | deviceInfo: deviceInfo ?? this.deviceInfo, 169 | deviceOrientationRad: deviceOrientationRad ?? _deviceOrientationRad, 170 | simulatorBrightness: simulatorBrightness ?? this.simulatorBrightness, 171 | systemUiOverlayStyle: systemUiOverlayStyle ?? this.systemUiOverlayStyle, 172 | applicationSwitcherDescription: 173 | applicationSwitcherDescription ?? this.applicationSwitcherDescription, 174 | appPreferredOrientations: 175 | appPreferredOrientations?.toSet() ?? this.appPreferredOrientations, 176 | previousScreenOrientation: deviceScreenOrientation, 177 | isKeyboardVisible: isKeyboardVisible ?? this.isKeyboardVisible, 178 | deviceOrientationRadOverride: deviceOrientationRadOverride, 179 | deviceScreenSizeOverride: deviceScreenSizeOverride, 180 | ); 181 | } 182 | 183 | SimulatorParams copyWithoutOverrides() { 184 | return SimulatorParams( 185 | deviceInfo: deviceInfo, 186 | deviceOrientationRad: deviceOrientationRad, 187 | simulatorBrightness: simulatorBrightness, 188 | systemUiOverlayStyle: systemUiOverlayStyle, 189 | applicationSwitcherDescription: applicationSwitcherDescription, 190 | appPreferredOrientations: appPreferredOrientations, 191 | previousScreenOrientation: deviceScreenOrientation, 192 | isKeyboardVisible: isKeyboardVisible, 193 | deviceScreenSizeOverride: null, 194 | deviceOrientationRadOverride: null, 195 | ); 196 | } 197 | 198 | @override 199 | int get hashCode => Object.hash( 200 | deviceInfo, 201 | deviceOrientationRad, 202 | previousScreenOrientation, 203 | simulatorBrightness, 204 | systemUiOverlayStyle, 205 | applicationSwitcherDescription?.label, 206 | applicationSwitcherDescription?.primaryColor, 207 | appPreferredOrientations, 208 | isKeyboardVisible, 209 | ); 210 | 211 | @override 212 | bool operator ==(Object other) { 213 | return other is SimulatorParams && other.hashCode == hashCode; 214 | } 215 | } 216 | 217 | class _AnimatedSimulatorParamsTween extends Tween<_AnimatedSimulatorParams> { 218 | _AnimatedSimulatorParamsTween({super.begin}); 219 | 220 | @override 221 | _AnimatedSimulatorParams lerp(double t) { 222 | return _AnimatedSimulatorParams.lerp(begin, end, t); 223 | } 224 | } 225 | 226 | class AnimatedSimulatorParams extends ImplicitlyAnimatedWidget { 227 | const AnimatedSimulatorParams({ 228 | super.key, 229 | required super.duration, 230 | super.curve, 231 | required this.data, 232 | required this.builder, 233 | }); 234 | 235 | final SimulatorParams data; 236 | final Widget Function(BuildContext context, SimulatorParams params) builder; 237 | 238 | @override 239 | ImplicitlyAnimatedWidgetState createState() => 240 | _AnimatedIconThemeState(); 241 | } 242 | 243 | class _AnimatedIconThemeState 244 | extends AnimatedWidgetBaseState { 245 | _AnimatedSimulatorParamsTween? _data; 246 | 247 | @override 248 | void forEachTween(TweenVisitor visitor) { 249 | _data = visitor( 250 | _data, 251 | _AnimatedSimulatorParams.fromParams(widget.data), 252 | (dynamic value) => _AnimatedSimulatorParamsTween(begin: value), 253 | ) as _AnimatedSimulatorParamsTween?; 254 | } 255 | 256 | @override 257 | Widget build(BuildContext context) { 258 | return widget.builder( 259 | context, 260 | _data!.evaluate(animation).toParams(widget.data), 261 | ); 262 | } 263 | } 264 | -------------------------------------------------------------------------------- /lib/src/core/system_platform_channel_interceptor.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import 'package:flutter/services.dart'; 3 | import 'package:flutter_simulator/src/imports.dart'; 4 | 5 | /// Listens to [SystemChrome.setSystemUIOverlayStyle] calls and notifies 6 | /// listeners if the value changes. 7 | class SystemPlatformChannelInterceptor extends ChangeNotifier { 8 | SystemPlatformChannelInterceptor(); 9 | 10 | static SystemPlatformChannelInterceptor ensureInitialized() { 11 | if (SystemPlatformChannelInterceptor._instance != null) { 12 | return SystemPlatformChannelInterceptor._instance!; 13 | } 14 | 15 | final instance = SystemPlatformChannelInterceptor(); 16 | SystemPlatformChannelInterceptor._instance = instance; 17 | 18 | SimulatorWidgetsBinding.instance.defaultBinaryMessenger 19 | .setMockMethodCallHandler( 20 | SystemChannels.platform, 21 | instance._onMethodCall, 22 | ); 23 | 24 | return instance; 25 | } 26 | 27 | static SystemPlatformChannelInterceptor get instance => _instance!; 28 | static SystemPlatformChannelInterceptor? _instance; 29 | 30 | SystemUiOverlayStyle? systemUiOverlayStyle; 31 | ApplicationSwitcherDescription? applicationSwitcherDescription; 32 | List? appPreferredOrientations; 33 | 34 | @override 35 | void dispose() { 36 | SimulatorWidgetsBinding.instance.defaultBinaryMessenger 37 | .setMockMethodCallHandler(SystemChannels.platform, null); 38 | 39 | _instance = null; 40 | 41 | super.dispose(); 42 | } 43 | 44 | Future? _onMethodCall(MethodCall message) { 45 | if (message.method == 'SystemChrome.setSystemUIOverlayStyle') { 46 | final data = message.arguments as Map; 47 | systemUiOverlayStyle = systemUiOverlayStyleFromJson(data); 48 | 49 | notifyListeners(); 50 | } else if (message.method == 51 | 'SystemChrome.setApplicationSwitcherDescription') { 52 | if (message.arguments['label'] == 'simulator-app') { 53 | return null; 54 | } 55 | 56 | applicationSwitcherDescription = ApplicationSwitcherDescription( 57 | label: message.arguments['label'], 58 | primaryColor: message.arguments['primaryColor'], 59 | ); 60 | 61 | notifyListeners(); 62 | } else if (message.method == 'SystemChrome.setPreferredOrientations') { 63 | appPreferredOrientations = (message.arguments as List) 64 | .map((e) => deviceOrientationFromString(e)) 65 | .toList(); 66 | 67 | notifyListeners(); 68 | } 69 | 70 | return null; 71 | } 72 | } 73 | 74 | /// Parses [SystemUiOverlayStyle] from JSON. 75 | SystemUiOverlayStyle systemUiOverlayStyleFromJson(Map json) { 76 | Brightness? decodeBrightness(String? value) { 77 | switch (value) { 78 | case 'Brightness.dark': 79 | return Brightness.dark; 80 | case 'Brightness.light': 81 | return Brightness.light; 82 | default: 83 | return null; 84 | } 85 | } 86 | 87 | Color? decodeColor(int? value) { 88 | if (value == null) { 89 | return null; 90 | } 91 | 92 | return Color(value); 93 | } 94 | 95 | return SystemUiOverlayStyle( 96 | systemNavigationBarColor: decodeColor(json['systemNavigationBarColor']), 97 | systemNavigationBarDividerColor: 98 | decodeColor(json['systemNavigationBarDividerColor']), 99 | systemNavigationBarIconBrightness: 100 | decodeBrightness(json['systemNavigationBarIconBrightness']), 101 | systemNavigationBarContrastEnforced: 102 | json['systemNavigationBarContrastEnforced'], 103 | systemStatusBarContrastEnforced: json['systemStatusBarContrastEnforced'], 104 | statusBarColor: decodeColor(json['statusBarColor']), 105 | statusBarBrightness: decodeBrightness(json['statusBarBrightness']), 106 | statusBarIconBrightness: decodeBrightness(json['statusBarIconBrightness']), 107 | ); 108 | } 109 | 110 | /// Parses [DeviceOrientation] from a string. 111 | DeviceOrientation deviceOrientationFromString(String value) { 112 | switch (value) { 113 | case 'DeviceOrientation.portraitUp': 114 | return DeviceOrientation.portraitUp; 115 | case 'DeviceOrientation.portraitDown': 116 | return DeviceOrientation.portraitDown; 117 | case 'DeviceOrientation.landscapeLeft': 118 | return DeviceOrientation.landscapeLeft; 119 | case 'DeviceOrientation.landscapeRight': 120 | return DeviceOrientation.landscapeRight; 121 | default: 122 | throw Exception('Unknown device orientation: $value'); 123 | } 124 | } 125 | 126 | class SystemApplicationSwitcherDescription { 127 | const SystemApplicationSwitcherDescription({ 128 | required this.label, 129 | required this.primaryColor, 130 | }); 131 | 132 | final String label; 133 | final Color primaryColor; 134 | } 135 | -------------------------------------------------------------------------------- /lib/src/core/text_input/simulated_ime.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/services.dart'; 4 | import 'package:flutter_simulator/src/imports.dart'; 5 | 6 | class SimulatedIME { 7 | SimulatedIME({ 8 | required this.id, 9 | required this.configuration, 10 | }); 11 | 12 | final int id; 13 | TextEditingValue value = TextEditingValue.empty; 14 | 15 | TextInputConfiguration configuration; 16 | 17 | double? width; 18 | double? height; 19 | Matrix4? transform; 20 | 21 | Rect? markedTextRect; 22 | List selectionRects = []; 23 | Rect? caretRect; 24 | 25 | String? fontFamily; 26 | double? fontSize; 27 | FontWeight? fontWeight; 28 | TextDirection? textDirection; 29 | TextAlign? textAlign; 30 | 31 | void setEditableSizeAndTransform( 32 | double width, 33 | double height, 34 | Matrix4 transform, 35 | ) { 36 | this.width = width; 37 | this.height = height; 38 | this.transform = transform; 39 | } 40 | 41 | void setMarkedTextRect(Rect rect) { 42 | markedTextRect = rect; 43 | } 44 | 45 | void setSelectionRects(List rects) { 46 | selectionRects = rects; 47 | } 48 | 49 | void setStyle( 50 | String? fontFamily, 51 | double? fontSize, 52 | FontWeight? fontWeight, 53 | TextDirection textDirection, 54 | TextAlign textAlign, 55 | ) { 56 | this.fontFamily = fontFamily; 57 | this.fontSize = fontSize; 58 | this.fontWeight = fontWeight; 59 | this.textDirection = textDirection; 60 | this.textAlign = textAlign; 61 | } 62 | 63 | void setEditingState(TextEditingValue value) { 64 | this.value = value; 65 | } 66 | 67 | void setCaretRect(Rect rect) { 68 | caretRect = rect; 69 | } 70 | 71 | void _appendCharacter(String character) { 72 | value = value.replaced( 73 | value.selection, 74 | character, 75 | ); 76 | } 77 | 78 | void _deleteCharacter(int offset) { 79 | var selection = value.selection; 80 | 81 | if (selection.isCollapsed) { 82 | selection = selection.extendTo(TextPosition( 83 | offset: max(0, selection.baseOffset + offset), 84 | affinity: selection.affinity, 85 | )); 86 | 87 | final selectionLength = selection.extentOffset - selection.baseOffset; 88 | 89 | if (selection.isCollapsed || 90 | !selection.isValid || 91 | selectionLength > value.text.length) { 92 | return; 93 | } 94 | } 95 | 96 | value = value.replaced( 97 | selection, 98 | '', 99 | ); 100 | } 101 | 102 | void handleBackspacePress() { 103 | _deleteCharacter(-1); 104 | SystemTextInputChannelInterceptor.instance.updateEditingState(id, value); 105 | } 106 | 107 | void handleNewlinePress() { 108 | _appendCharacter('\n'); 109 | SystemTextInputChannelInterceptor.instance.updateEditingState(id, value); 110 | } 111 | 112 | void handleKeyEvent(RawKeyEvent event) { 113 | final interceptor = SystemTextInputChannelInterceptor.instance; 114 | 115 | // TODO: Make this work for macOS 116 | if (event is RawKeyDownEvent) { 117 | if (event.character != null) { 118 | _appendCharacter(event.character!); 119 | interceptor.updateEditingState(id, value); 120 | } else if (event.logicalKey == LogicalKeyboardKey.backspace) { 121 | handleBackspacePress(); 122 | } else if (event.logicalKey == LogicalKeyboardKey.delete) { 123 | _deleteCharacter(1); 124 | interceptor.updateEditingState(id, value); 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /lib/src/core/window_size_manager.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:flutter/widgets.dart'; 4 | import 'package:flutter_simulator/src/imports.dart'; 5 | import 'package:window_manager/window_manager.dart'; 6 | 7 | Future _awaitForWithTicker({ 8 | required Duration duration, 9 | required TickerProvider tickerProvider, 10 | }) async { 11 | final completer = Completer(); 12 | final ticker = tickerProvider.createTicker((elapsed) { 13 | if (elapsed > duration) { 14 | completer.complete(); 15 | } 16 | }); 17 | 18 | ticker.start(); 19 | await completer.future; 20 | 21 | ticker.dispose(); 22 | } 23 | 24 | class WindowSizeManager with WindowListener { 25 | WindowSizeManager() { 26 | windowManager.addListener(this); 27 | } 28 | 29 | Size? _lastSize; 30 | SimulatorParams? _lastSimulatorParams; 31 | 32 | static double get minWidth => 320.0; 33 | static double get headerHeight => 34 | SimulatorHeaderWidget.preferredHeight + 16.0; 35 | 36 | final windowSizeNotifier = ValueNotifier(const Size(0, 0)); 37 | 38 | Size _inflateSizeWithHeader(Size size) { 39 | return Size(size.width, size.height + headerHeight); 40 | } 41 | 42 | Size _squaredSize(Size size) { 43 | final max = size.longestSide; 44 | return Size(max, max); 45 | } 46 | 47 | var _isTransitioning = false; 48 | Future resizeWithSimulatorParams( 49 | SimulatorParams params, { 50 | required TickerProvider vsync, 51 | }) async { 52 | final size = params.rawDeviceScreenOrientation.transformSize( 53 | params.deviceFrame.transformSize( 54 | params.deviceScreenSize, 55 | params, 56 | ), 57 | ); 58 | 59 | final hasFixedAspectRatio = !params.deviceInfo.isResizable; 60 | 61 | if (_lastSimulatorParams?.rawDeviceScreenOrientation == 62 | params.rawDeviceScreenOrientation && 63 | _lastSize == size) return; 64 | 65 | await windowManager.setMaximumSize(const Size(-1, -1)); 66 | 67 | final willAnimate = _lastSize != null && 68 | _lastSimulatorParams?.deviceInfo.isResizable == false; 69 | 70 | final windowSize = await windowManager.getSize(); 71 | 72 | final contentAspectRatio = size.aspectRatio; 73 | 74 | final minSize = Size( 75 | minWidth, 76 | (minWidth / contentAspectRatio) + headerHeight, 77 | ); 78 | 79 | double scale; 80 | 81 | if (_lastSize != null && 82 | _lastSimulatorParams!.deviceInfo.isResizable == false) { 83 | scale = windowSize.width / _lastSize!.width; 84 | } else { 85 | scale = 1.0; 86 | } 87 | 88 | if (size.width * scale < minWidth) { 89 | scale = minWidth / size.width; 90 | } 91 | 92 | final newWindowSize = _inflateSizeWithHeader(size * scale); 93 | 94 | windowSizeNotifier.value = newWindowSize; 95 | 96 | _lastSimulatorParams = params; 97 | _lastSize = size; 98 | if (!hasFixedAspectRatio) { 99 | await windowManager.setMinimumSize(minSize.rounded); 100 | await windowManager.setAspectRatio(0.0); 101 | windowSizeNotifier.value = windowSize; 102 | return; 103 | } 104 | 105 | if (willAnimate) { 106 | _isTransitioning = true; 107 | await windowManager.setTitleBarHeight(0.0); 108 | await windowManager.setAspectRatio(1.0); 109 | await windowManager.setMinimumSize(_squaredSize(minSize).rounded); 110 | await _setWindowSize( 111 | _squaredSize(newWindowSize).rounded, 112 | reportSize: false, 113 | ); 114 | 115 | await _awaitForWithTicker( 116 | duration: const Duration(milliseconds: 300), 117 | tickerProvider: vsync, 118 | ); 119 | 120 | _isTransitioning = false; 121 | } 122 | 123 | await windowManager.setTitleBarHeight(headerHeight); 124 | await windowManager.setAspectRatio(contentAspectRatio); 125 | await windowManager.setMinimumSize(minSize.rounded); 126 | _setWindowSize(newWindowSize); 127 | } 128 | 129 | Future _setWindowSize(Size size, {bool reportSize = true}) async { 130 | if (reportSize) { 131 | windowSizeNotifier.value = size; 132 | } 133 | 134 | await windowManager.setSize(size.rounded); 135 | } 136 | 137 | @override 138 | Future onWindowResize() async { 139 | if (_isTransitioning) return; 140 | windowSizeNotifier.value = await windowManager.getSize(); 141 | } 142 | 143 | void dispose() { 144 | windowManager.removeListener(this); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /lib/src/devices/_devices.dart: -------------------------------------------------------------------------------- 1 | export 'apple/_apple.dart'; 2 | export 'core/device_frame.dart'; 3 | export 'core/device_info.dart'; 4 | export 'core/device_keyboard.dart'; 5 | export 'core/device_orientation.dart'; 6 | -------------------------------------------------------------------------------- /lib/src/devices/apple/_apple.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_simulator/src/imports.dart'; 2 | import 'iphone_14.dart' as iphone_14_library; 3 | 4 | class AppleDevices { 5 | static DeviceInfo get iPhone14 => iphone_14_library.iPhone14; 6 | 7 | static List get devices => [ 8 | iPhone14, 9 | ]; 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/devices/apple/ios_keyboard_animation.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/physics.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | 4 | // See: https://github.com/drogel/keyboard_attachable 5 | 6 | class IOSKeyboardAnimationController { 7 | IOSKeyboardAnimationController({required TickerProvider vsync}) 8 | : _spring = const SpringDescription(mass: 8, stiffness: 1, damping: 4.5), 9 | _springVelocity = 10, 10 | _controller = AnimationController(vsync: vsync); 11 | 12 | final SpringDescription _spring; 13 | final double _springVelocity; 14 | final AnimationController _controller; 15 | 16 | Animation get animation => _controller; 17 | 18 | TickerFuture forward() { 19 | final forwardSimulation = SpringSimulation(_spring, 0, 1, _springVelocity); 20 | return _controller.animateWith(forwardSimulation); 21 | } 22 | 23 | TickerFuture reverse() { 24 | final reverseSimulation = SpringSimulation(_spring, 1, 0, -_springVelocity); 25 | return _controller.animateWith(reverseSimulation); 26 | } 27 | 28 | void dispose() => _controller.dispose(); 29 | } 30 | 31 | class IOSKeyboardAnimatedBuilder extends StatefulWidget { 32 | const IOSKeyboardAnimatedBuilder({ 33 | super.key, 34 | required this.builder, 35 | required this.isVisible, 36 | }); 37 | 38 | final bool isVisible; 39 | final Widget Function(BuildContext context, double value) builder; 40 | 41 | @override 42 | State createState() => 43 | _IOSKeyboardAnimatedBuilderState(); 44 | } 45 | 46 | class _IOSKeyboardAnimatedBuilderState extends State 47 | with SingleTickerProviderStateMixin { 48 | late final IOSKeyboardAnimationController _controller = 49 | IOSKeyboardAnimationController(vsync: this); 50 | 51 | @override 52 | void didUpdateWidget(covariant IOSKeyboardAnimatedBuilder oldWidget) { 53 | super.didUpdateWidget(oldWidget); 54 | 55 | if (oldWidget.isVisible != widget.isVisible) { 56 | _animate(widget.isVisible); 57 | } 58 | } 59 | 60 | @override 61 | void dispose() { 62 | _controller.dispose(); 63 | super.dispose(); 64 | } 65 | 66 | @override 67 | Widget build(BuildContext context) { 68 | final animation = _controller.animation; 69 | 70 | return AnimatedBuilder( 71 | animation: animation, 72 | builder: (context, _) => widget.builder(context, animation.value), 73 | ); 74 | } 75 | 76 | void _animate(bool isKeyboardVisible) => 77 | isKeyboardVisible ? _controller.forward() : _controller.reverse(); 78 | } 79 | -------------------------------------------------------------------------------- /lib/src/devices/core/device_frame.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | import 'package:flutter/rendering.dart'; 3 | import 'package:flutter_simulator/src/imports.dart'; 4 | 5 | /// Paints the physical device frame. 6 | typedef PhysicalDeviceFramePainter = void Function( 7 | PaintingContext context, 8 | Offset offset, 9 | Size size, 10 | Rect screenRect, 11 | SimulatorParams params, 12 | ); 13 | 14 | /// Paints the physical device items that are on top of the screen. 15 | /// 16 | /// For example, this is a notch on the iPhone X. 17 | typedef ForegroundPhysicalDeviceFramePainter = void Function( 18 | PaintingContext context, 19 | Offset offset, 20 | Size size, 21 | Rect screenRect, 22 | SimulatorParams params, 23 | ); 24 | 25 | /// Paints the device screen. 26 | /// 27 | /// This is the part of the device that displays the app. 28 | /// 29 | /// An optional layer can be returned if the screen is clipped. 30 | typedef DeviceScreenPainter = ContainerLayer? Function( 31 | PaintingContext context, 32 | Offset offset, 33 | Rect screenRect, 34 | SimulatorParams params, 35 | RenderObject child, 36 | ContainerLayer? oldLayer, 37 | ); 38 | 39 | /// Paints the device screen items that are on top of the app. 40 | /// 41 | /// For example, this is the status bar. 42 | typedef DeviceScreenForegroundPainter = void Function( 43 | PaintingContext context, 44 | Offset offset, 45 | Rect screenRect, 46 | SimulatorParams params, 47 | ); 48 | 49 | /// Paints the device screen items that are on top of the app and dependent 50 | /// on the screen contents. 51 | /// 52 | /// For example, this is the home indicator on the iPhone X. 53 | typedef ContentAwareDeviceScreenForegroundPainter = void Function( 54 | Canvas canvas, 55 | Size screenSize, 56 | SimulatorParams params, 57 | ByteData? byteData, 58 | ); 59 | 60 | /// Transforms the size of the displayed widget. 61 | typedef SizeTransformer = Size Function( 62 | Size screenSize, 63 | SimulatorParams params, 64 | ); 65 | 66 | /// Transforms the offset of the screen. 67 | typedef ScreenOffsetTransformer = Offset Function( 68 | Size size, 69 | Size screenSize, 70 | SimulatorParams params, 71 | ); 72 | 73 | class DeviceFrame { 74 | const DeviceFrame({ 75 | required this.paintDeviceScreen, 76 | required this.transformScreenOffset, 77 | required this.transformSize, 78 | this.frameRadius = Radius.zero, 79 | this.paintPhysicalDeviceFrame, 80 | this.paintForegroundPhysicalDeviceFrame, 81 | this.paintDeviceScreenForeground, 82 | this.paintContentAwareDeviceScreenForeground, 83 | }); 84 | 85 | final Radius frameRadius; 86 | final ScreenOffsetTransformer transformScreenOffset; 87 | final SizeTransformer transformSize; 88 | final PhysicalDeviceFramePainter? paintPhysicalDeviceFrame; 89 | final ForegroundPhysicalDeviceFramePainter? 90 | paintForegroundPhysicalDeviceFrame; 91 | final DeviceScreenPainter paintDeviceScreen; 92 | final DeviceScreenForegroundPainter? paintDeviceScreenForeground; 93 | final ContentAwareDeviceScreenForegroundPainter? 94 | paintContentAwareDeviceScreenForeground; 95 | 96 | /// A device frame that does no transformations to the screen. 97 | static const DeviceFrame none = DeviceFrame( 98 | paintDeviceScreen: _noneDeviceScreenPainter, 99 | transformScreenOffset: _noneScreenOffsetTransformer, 100 | transformSize: _noneSizeTransformer, 101 | ); 102 | } 103 | 104 | ContainerLayer? _noneDeviceScreenPainter( 105 | PaintingContext context, 106 | Offset offset, 107 | Rect screenRect, 108 | SimulatorParams params, 109 | RenderObject child, 110 | ContainerLayer? oldLayer, 111 | ) { 112 | context.paintChild(child, offset); 113 | return null; 114 | } 115 | 116 | Offset _noneScreenOffsetTransformer( 117 | Size size, 118 | Size screenSize, 119 | SimulatorParams params, 120 | ) { 121 | return const Offset(2, 2); 122 | } 123 | 124 | Size _noneSizeTransformer( 125 | Size size, 126 | SimulatorParams params, 127 | ) { 128 | return Size(size.width + 4, size.height + 4); 129 | } 130 | -------------------------------------------------------------------------------- /lib/src/devices/core/device_info.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | import 'package:flutter_simulator/src/devices/core/device_keyboard.dart'; 4 | import 'package:flutter_simulator/src/imports.dart'; 5 | 6 | const _allDeviceOrientations = { 7 | DeviceOrientation.landscapeLeft, 8 | DeviceOrientation.landscapeRight, 9 | DeviceOrientation.portraitUp, 10 | DeviceOrientation.portraitDown, 11 | }; 12 | 13 | class DeviceInfo { 14 | const DeviceInfo({ 15 | required this.name, 16 | required this.platform, 17 | required this.screenDiagonalInches, 18 | required this.devicePixelRatio, 19 | required this.screenSize, 20 | required this.viewPaddings, 21 | this.deviceKeyboard = DeviceKeyboard.none, 22 | this.deviceFrame = DeviceFrame.none, 23 | this.allowedOrientations = _allDeviceOrientations, 24 | this.isResizable = false, 25 | }); 26 | 27 | /// Name must be unique 28 | final String name; 29 | final TargetPlatform platform; 30 | final double screenDiagonalInches; 31 | final double devicePixelRatio; 32 | final Size screenSize; 33 | final Map viewPaddings; 34 | final Set allowedOrientations; 35 | final DeviceFrame deviceFrame; 36 | final DeviceKeyboard deviceKeyboard; 37 | final bool isResizable; 38 | 39 | Size get phyiscalPixelsScreenSize => screenSize * devicePixelRatio; 40 | 41 | @override 42 | bool operator ==(Object other) => 43 | identical(this, other) || other is DeviceInfo && name == other.name; 44 | 45 | @override 46 | int get hashCode => name.hashCode; 47 | 48 | static const DeviceInfo none = DeviceInfo( 49 | name: 'frameless', 50 | platform: TargetPlatform.windows, 51 | devicePixelRatio: 2.0, 52 | screenDiagonalInches: 0.0, 53 | screenSize: Size.square(300.0), 54 | isResizable: true, 55 | viewPaddings: { 56 | DeviceOrientation.landscapeLeft: EdgeInsets.zero, 57 | DeviceOrientation.landscapeRight: EdgeInsets.zero, 58 | DeviceOrientation.portraitUp: EdgeInsets.zero, 59 | DeviceOrientation.portraitDown: EdgeInsets.zero, 60 | }, 61 | allowedOrientations: {DeviceOrientation.portraitUp}, 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/devices/core/device_keyboard.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:flutter_simulator/src/imports.dart'; 3 | 4 | mixin ViewInsettingWidget on Widget { 5 | EdgeInsets get viewInsets; 6 | } 7 | 8 | typedef DeviceKeyboardAnimationBuilder = Widget Function( 9 | BuildContext context, 10 | Size screenSize, 11 | SimulatorParams params, 12 | bool isVisible, 13 | PreferredSizeWidget keyboardWidget, 14 | ); 15 | 16 | typedef DeviceKeyboardBuilder = PreferredSizeWidget Function( 17 | BuildContext context, 18 | SimulatorParams params, 19 | SimulatedIME? ime, 20 | ); 21 | 22 | typedef ViewInsetsBuilder = Widget Function( 23 | BuildContext context, 24 | SimulatorParams params, 25 | SimulatedIME? ime, 26 | bool isVisible, 27 | Widget Function(BuildContext context, EdgeInsets viewInsets) builder, 28 | ); 29 | 30 | class DeviceKeyboard { 31 | const DeviceKeyboard({ 32 | required this.builder, 33 | required this.viewInsetsBuilder, 34 | this.animationBuilder = _buildDefaultKeyboardAnimation, 35 | }); 36 | 37 | final DeviceKeyboardAnimationBuilder animationBuilder; 38 | final DeviceKeyboardBuilder builder; 39 | final ViewInsetsBuilder viewInsetsBuilder; 40 | 41 | static const DeviceKeyboard none = DeviceKeyboard( 42 | builder: _buildNoKeyboard, 43 | viewInsetsBuilder: _buildNoInsets, 44 | ); 45 | } 46 | 47 | PreferredSizeWidget _buildNoKeyboard( 48 | BuildContext context, 49 | SimulatorParams params, 50 | SimulatedIME? ime, 51 | ) { 52 | return const PreferredSize( 53 | preferredSize: Size.zero, 54 | child: SizedBox.shrink(), 55 | ); 56 | } 57 | 58 | Widget _buildNoInsets( 59 | BuildContext context, 60 | SimulatorParams params, 61 | SimulatedIME? ime, 62 | bool isVisible, 63 | Widget Function(BuildContext context, EdgeInsets viewInsets) builder, 64 | ) { 65 | return builder(context, EdgeInsets.zero); 66 | } 67 | 68 | Widget _buildDefaultKeyboardAnimation( 69 | BuildContext context, 70 | Size screenSize, 71 | SimulatorParams params, 72 | bool isVisible, 73 | PreferredSizeWidget keyboardWidget, 74 | ) { 75 | return Positioned( 76 | width: keyboardWidget.preferredSize.width, 77 | height: keyboardWidget.preferredSize.height, 78 | bottom: 0.0, 79 | child: Visibility( 80 | visible: isVisible, 81 | child: RepaintBoundary(child: keyboardWidget), 82 | ), 83 | ); 84 | } 85 | -------------------------------------------------------------------------------- /lib/src/devices/core/device_orientation.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/services.dart'; 4 | 5 | extension DeviceOrientationUtils on DeviceOrientation { 6 | DeviceOrientation rotateCW() { 7 | switch (this) { 8 | case DeviceOrientation.portraitUp: 9 | return DeviceOrientation.landscapeRight; 10 | case DeviceOrientation.landscapeRight: 11 | return DeviceOrientation.portraitDown; 12 | case DeviceOrientation.portraitDown: 13 | return DeviceOrientation.landscapeLeft; 14 | case DeviceOrientation.landscapeLeft: 15 | return DeviceOrientation.portraitUp; 16 | } 17 | } 18 | 19 | DeviceOrientation rotateCCW() { 20 | switch (this) { 21 | case DeviceOrientation.portraitUp: 22 | return DeviceOrientation.landscapeLeft; 23 | case DeviceOrientation.landscapeRight: 24 | return DeviceOrientation.portraitUp; 25 | case DeviceOrientation.portraitDown: 26 | return DeviceOrientation.landscapeRight; 27 | case DeviceOrientation.landscapeLeft: 28 | return DeviceOrientation.portraitDown; 29 | } 30 | } 31 | 32 | bool get isLandscape => 33 | this == DeviceOrientation.landscapeLeft || 34 | this == DeviceOrientation.landscapeRight; 35 | 36 | bool get isPortrait => 37 | this == DeviceOrientation.portraitUp || 38 | this == DeviceOrientation.portraitDown; 39 | 40 | double get angleRad => index * pi / 2; 41 | 42 | Size transformSize(Size size) { 43 | switch (this) { 44 | case DeviceOrientation.portraitUp: 45 | case DeviceOrientation.portraitDown: 46 | return size; 47 | case DeviceOrientation.landscapeLeft: 48 | case DeviceOrientation.landscapeRight: 49 | return size.flipped; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/src/imports.dart: -------------------------------------------------------------------------------- 1 | export 'bindings/_bindings.dart'; 2 | export 'core/_core.dart'; 3 | export 'devices/_devices.dart'; 4 | export 'utils/_utils.dart'; 5 | export 'widgets/_widgets.dart'; 6 | -------------------------------------------------------------------------------- /lib/src/utils/_utils.dart: -------------------------------------------------------------------------------- 1 | export 'byte_data.dart'; 2 | export 'color.dart'; 3 | export 'list_extension.dart'; 4 | export 'screenshot.dart'; 5 | export 'scroll_behavior.dart'; 6 | export 'size.dart'; -------------------------------------------------------------------------------- /lib/src/utils/byte_data.dart: -------------------------------------------------------------------------------- 1 | import 'dart:typed_data'; 2 | 3 | import 'package:flutter/widgets.dart'; 4 | 5 | Color? getScreenPixel(ByteData? byteData, double? width, Offset position) { 6 | if (byteData == null || width == null) return null; 7 | 8 | final x = position.dx.toInt(); 9 | final y = position.dy.toInt(); 10 | 11 | final index = (y * (width.toInt()) + x) * 4; 12 | 13 | final r = byteData.getUint8(index); 14 | final g = byteData.getUint8(index + 1); 15 | final b = byteData.getUint8(index + 2); 16 | final a = byteData.getUint8(index + 3); 17 | 18 | return Color.fromARGB(a, r, g, b); 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/utils/color.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | // https://stackoverflow.com/questions/58360989/programmatically-lighten-or-darken-a-hex-color-in-dart 4 | extension ColorMutation on Color { 5 | Color darken(double amount) { 6 | assert(amount >= 0 && amount <= 1); 7 | 8 | final hsl = HSLColor.fromColor(this); 9 | final hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0)); 10 | 11 | return hslDark.toColor(); 12 | } 13 | 14 | Color lighten(double amount) { 15 | assert(amount >= 0 && amount <= 1); 16 | 17 | final hsl = HSLColor.fromColor(this); 18 | final hslLight = 19 | hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0)); 20 | 21 | return hslLight.toColor(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/utils/list_extension.dart: -------------------------------------------------------------------------------- 1 | extension Intersperse on Iterable { 2 | Iterable intersperse(T element) sync* { 3 | final iterator = this.iterator; 4 | if (!iterator.moveNext()) return; 5 | yield iterator.current; 6 | while (iterator.moveNext()) { 7 | yield element; 8 | yield iterator.current; 9 | } 10 | } 11 | } 12 | 13 | extension IntersperseList on List { 14 | List intersperse(T element) { 15 | final result = []; 16 | final iterator = this.iterator; 17 | if (!iterator.moveNext()) return result; 18 | result.add(iterator.current); 19 | while (iterator.moveNext()) { 20 | result.add(element); 21 | result.add(iterator.current); 22 | } 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/utils/screenshot.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter/rendering.dart'; 5 | import 'package:flutter_simulator/flutter_simulator.dart'; 6 | import 'package:image/image.dart' as img; 7 | import 'package:path_provider/path_provider.dart'; 8 | import 'package:url_launcher/url_launcher.dart'; 9 | 10 | String _generateScreenshotName() { 11 | final now = DateTime.now(); 12 | final iso = now.toIso8601String().replaceAll(':', '-'); 13 | 14 | return 'flutter_simulator_$iso.png'; 15 | } 16 | 17 | Future _generateScreenshotPath() async { 18 | final downloads = await getDownloadsDirectory(); 19 | 20 | return '${downloads!.path}\\${_generateScreenshotName()}'; 21 | } 22 | 23 | Future takeScreenshot( 24 | BuildContext context, { 25 | required DeviceInfo deviceInfo, 26 | required GlobalKey key, 27 | }) async { 28 | final renderObject = 29 | key.currentContext!.findRenderObject()! as RenderRepaintBoundary; 30 | 31 | final uiImage = await renderObject.toImage( 32 | pixelRatio: deviceInfo.devicePixelRatio, 33 | ); 34 | 35 | final image = img.Image.fromBytes( 36 | width: uiImage.width, 37 | height: uiImage.height, 38 | bytes: (await uiImage.toByteData())!.buffer, 39 | numChannels: 4, 40 | ); 41 | 42 | final path = await _generateScreenshotPath(); 43 | final fileUrl = Uri.file(path); 44 | final canOpen = await canLaunchUrl(fileUrl); 45 | 46 | File(path).writeAsBytes(img.encodePng(image)); 47 | 48 | // ignore: use_build_context_synchronously 49 | ScaffoldMessenger.of(context).showSnackBar( 50 | SnackBar( 51 | behavior: SnackBarBehavior.floating, 52 | shape: const StadiumBorder(), 53 | margin: const EdgeInsets.symmetric(horizontal: 32.0, vertical: 48.0), 54 | content: const Text('Screenshot saved to Downloads'), 55 | action: canOpen 56 | ? SnackBarAction( 57 | label: 'Show', 58 | onPressed: () => launchUrl(fileUrl), 59 | ) 60 | : null, 61 | ), 62 | ); 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/utils/scroll_behavior.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/gestures.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class FlutterSimulatorScrollBehavior extends MaterialScrollBehavior { 5 | @override 6 | Set get dragDevices => { 7 | PointerDeviceKind.touch, 8 | PointerDeviceKind.mouse, 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/utils/size.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | extension RoundedSize on Size { 4 | Size get rounded => Size(width.roundToDouble(), height.roundToDouble()); 5 | } -------------------------------------------------------------------------------- /lib/src/widgets/_widgets.dart: -------------------------------------------------------------------------------- 1 | export 'header/header.dart'; 2 | export 'simulator/simulator_render_object.dart'; 3 | export 'utils/animated_view_insets.dart'; 4 | export 'utils/resizable_gesture_detector.dart'; 5 | export 'app.dart'; 6 | export 'simulator.dart'; 7 | -------------------------------------------------------------------------------- /lib/src/widgets/app.dart: -------------------------------------------------------------------------------- 1 | // ignore_for_file: use_build_context_synchronously 2 | 3 | import 'dart:async'; 4 | 5 | import 'package:flutter/cupertino.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:flutter/services.dart'; 9 | import 'package:flutter_simulator/src/imports.dart'; 10 | 11 | final _appRepaintBoundaryKey = GlobalKey(); 12 | 13 | class FlutterSimulatorApp extends StatefulWidget { 14 | const FlutterSimulatorApp({ 15 | super.key, 16 | required this.appChild, 17 | }); 18 | 19 | final Widget appChild; 20 | 21 | @override 22 | State createState() => _FlutterSimulatorAppState(); 23 | } 24 | 25 | class _FlutterSimulatorAppState extends State 26 | with TickerProviderStateMixin { 27 | late final FocusScopeNode _headerFocusScopeNode; 28 | final _windowSizeManager = WindowSizeManager(); 29 | 30 | var _params = SimulatorParams( 31 | deviceInfo: AppleDevices.iPhone14, 32 | deviceOrientationRad: 0.0, 33 | previousScreenOrientation: DeviceOrientation.portraitUp, 34 | simulatorBrightness: Brightness.light, 35 | systemUiOverlayStyle: SystemUiOverlayStyle.light, 36 | isKeyboardVisible: false, 37 | ); 38 | 39 | set params(SimulatorParams params) { 40 | if (params == _params) return; 41 | 42 | _tryResizeView(params); 43 | 44 | _params = params; 45 | 46 | debugDefaultTargetPlatformOverride = _params.deviceInfo.platform; 47 | 48 | WidgetsBinding.instance.endOfFrame.then((_) { 49 | setState(() {}); 50 | }); 51 | } 52 | 53 | @override 54 | void initState() { 55 | super.initState(); 56 | 57 | final platformChannelInterceptor = 58 | SystemPlatformChannelInterceptor.ensureInitialized(); 59 | 60 | final textInputChannelInterceptor = 61 | SystemTextInputChannelInterceptor.ensureInitialized(); 62 | 63 | platformChannelInterceptor.addListener(() { 64 | params = _params.copyWith( 65 | systemUiOverlayStyle: platformChannelInterceptor.systemUiOverlayStyle, 66 | applicationSwitcherDescription: 67 | platformChannelInterceptor.applicationSwitcherDescription, 68 | appPreferredOrientations: 69 | platformChannelInterceptor.appPreferredOrientations, 70 | ); 71 | }); 72 | 73 | textInputChannelInterceptor.keyboardVisibilityNotifier.addListener(() { 74 | params = _params.copyWith( 75 | isKeyboardVisible: 76 | textInputChannelInterceptor.keyboardVisibilityNotifier.value, 77 | ); 78 | }); 79 | 80 | _headerFocusScopeNode = FocusScopeNode(); 81 | 82 | _tryResizeView(_params); 83 | } 84 | 85 | @override 86 | void dispose() { 87 | SystemPlatformChannelInterceptor.instance.dispose(); 88 | SystemTextInputChannelInterceptor.instance.dispose(); 89 | _windowSizeManager.dispose(); 90 | _headerFocusScopeNode.dispose(); 91 | 92 | super.dispose(); 93 | } 94 | 95 | Future _tryResizeView(SimulatorParams newParams) async { 96 | return _windowSizeManager.resizeWithSimulatorParams( 97 | newParams, 98 | vsync: this, 99 | ); 100 | } 101 | 102 | Widget _buildHeader(BuildContext context, SimulatorParams params) { 103 | final header = SimulatorHeaderWidget( 104 | params: params, 105 | onChanged: (params) { 106 | this.params = params; 107 | }, 108 | onScreenshot: () async { 109 | await Future.delayed(const Duration(milliseconds: 300)); 110 | 111 | takeScreenshot( 112 | context, 113 | deviceInfo: params.deviceInfo, 114 | key: _appRepaintBoundaryKey, 115 | ); 116 | }, 117 | onScreenshotDeviceFrame: () async { 118 | await Future.delayed(const Duration(milliseconds: 300)); 119 | 120 | takeScreenshot( 121 | context, 122 | deviceInfo: params.deviceInfo, 123 | key: SimulatorWidgetsBinding.instance.deviceFrameKey, 124 | ); 125 | }, 126 | onScreenshotDeviceScreen: () async { 127 | await Future.delayed(const Duration(milliseconds: 300)); 128 | 129 | takeScreenshot( 130 | context, 131 | deviceInfo: params.deviceInfo, 132 | key: SimulatorWidgetsBinding.instance.deviceScreenKey, 133 | ); 134 | }, 135 | ); 136 | 137 | return ValueListenableBuilder( 138 | valueListenable: _windowSizeManager.windowSizeNotifier, 139 | builder: (context, size, child) { 140 | return AnimatedContainer( 141 | duration: const Duration(milliseconds: 300), 142 | curve: Curves.easeInOut, 143 | width: size.width, 144 | height: SimulatorHeaderWidget.preferredHeight, 145 | child: child, 146 | ); 147 | }, 148 | child: header, 149 | ); 150 | } 151 | 152 | Widget _buildSimulator(BuildContext context, SimulatorParams params) { 153 | return AnimatedSimulatorParams( 154 | duration: const Duration(milliseconds: 300), 155 | curve: Curves.easeInOut, 156 | data: params, 157 | builder: (context, params) => SimulatorWidget( 158 | params: params, 159 | appChild: widget.appChild, 160 | ), 161 | ); 162 | } 163 | 164 | @override 165 | Widget build(BuildContext context) { 166 | WidgetsApp; 167 | MaterialApp; 168 | print(PlatformDispatcher.instance.views); 169 | print(PlatformDispatcher.instance.implicitView!); 170 | 171 | return View( 172 | view: SimulatorWidgetsBinding.instance.appRenderView.flutterView, 173 | deprecatedDoNotUseWillBeRemovedWithoutNoticeRenderView: 174 | SimulatorWidgetsBinding.instance.appRenderView, 175 | deprecatedDoNotUseWillBeRemovedWithoutNoticePipelineOwner: 176 | SimulatorWidgetsBinding.instance.pipelineOwner, 177 | child: FocusScope( 178 | node: _headerFocusScopeNode, 179 | canRequestFocus: false, 180 | child: Directionality( 181 | textDirection: TextDirection.ltr, // TODO: Support RTL 182 | child: Localizations( 183 | delegates: const [ 184 | DefaultWidgetsLocalizations.delegate, 185 | DefaultMaterialLocalizations.delegate, 186 | DefaultCupertinoLocalizations.delegate, 187 | ], 188 | locale: const Locale('en', 'US'), 189 | child: Theme( 190 | data: ThemeData.from( 191 | colorScheme: ColorScheme.fromSeed( 192 | seedColor: Colors.teal, 193 | brightness: _params.simulatorBrightness, 194 | ), 195 | useMaterial3: true, 196 | ), 197 | child: Overlay( 198 | initialEntries: [ 199 | OverlayEntry( 200 | builder: (context) => Scaffold( 201 | backgroundColor: Colors.transparent, 202 | body: RepaintBoundary( 203 | key: _appRepaintBoundaryKey, 204 | child: ResizableSimulatorHandler( 205 | params: _params, 206 | builder: (context, params) => Column( 207 | crossAxisAlignment: CrossAxisAlignment.start, 208 | children: [ 209 | _buildHeader(context, params), 210 | const SizedBox(height: 16.0), 211 | Expanded( 212 | child: _buildSimulator(context, params), 213 | ), 214 | ], 215 | ), 216 | ), 217 | ), 218 | ), 219 | maintainState: true, 220 | opaque: true, 221 | ), 222 | ], 223 | ), 224 | ), 225 | ), 226 | ), 227 | ), 228 | ); 229 | } 230 | } 231 | 232 | class ResizableSimulatorHandler extends StatelessWidget { 233 | const ResizableSimulatorHandler({ 234 | super.key, 235 | required this.params, 236 | required this.builder, 237 | }); 238 | 239 | final SimulatorParams params; 240 | final Widget Function(BuildContext context, SimulatorParams params) builder; 241 | 242 | @override 243 | Widget build(BuildContext context) { 244 | return LayoutBuilder( 245 | builder: (context, constraints) { 246 | if (!params.deviceInfo.isResizable) { 247 | return builder(context, params.copyWithoutOverrides()); 248 | } 249 | 250 | final maxSize = constraints.biggest; 251 | final deviceScreenSize = Size( 252 | maxSize.width - 4.0, 253 | maxSize.height - SimulatorHeaderWidget.preferredHeight - 16.0 - 4.0, 254 | ); 255 | 256 | return builder( 257 | context, 258 | params.copyWith( 259 | deviceScreenSizeOverride: deviceScreenSize, 260 | deviceOrientationRadOverride: 0.0, 261 | ), 262 | ); 263 | }, 264 | ); 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /lib/src/widgets/simulator.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter/services.dart'; 5 | import 'package:flutter_simulator/src/imports.dart'; 6 | 7 | /// A widget that builds the simulator. 8 | /// 9 | /// This builds the app and the device frame. 10 | class SimulatorWidget extends StatefulWidget { 11 | const SimulatorWidget({ 12 | super.key, 13 | required this.params, 14 | required this.appChild, 15 | }); 16 | 17 | final SimulatorParams params; 18 | final Widget appChild; 19 | 20 | @override 21 | State createState() => _SimulatorWidgetState(); 22 | } 23 | 24 | class _SimulatorWidgetState extends State 25 | with WidgetsBindingObserver { 26 | /// The [MediaQueryData] of the surrounding platform. 27 | /// 28 | /// This is transformed in [_buildAppWidget()] to provide one suitable for the 29 | /// simulated app. 30 | late MediaQueryData _mediaQueryData; 31 | 32 | /// The [FocusScopeNode] of the app. 33 | late final FocusScopeNode _appFocusScopeNode; 34 | 35 | @override 36 | void initState() { 37 | super.initState(); 38 | 39 | _appFocusScopeNode = FocusScopeNode( 40 | skipTraversal: true, 41 | canRequestFocus: true, 42 | ); 43 | 44 | _mediaQueryData = MediaQueryData.fromWindow(WidgetsBinding.instance.window); 45 | WidgetsBinding.instance.addObserver(this); 46 | } 47 | 48 | @override 49 | void didChangeMetrics() { 50 | _mediaQueryData = MediaQueryData.fromWindow(WidgetsBinding.instance.window); 51 | } 52 | 53 | @override 54 | void dispose() { 55 | _appFocusScopeNode.dispose(); 56 | WidgetsBinding.instance.removeObserver(this); 57 | super.dispose(); 58 | } 59 | 60 | SimulatorParams get params => widget.params; 61 | DeviceInfo get deviceInfo => params.deviceInfo; 62 | DeviceOrientation get deviceScreenOrientation => 63 | params.deviceScreenOrientation; 64 | 65 | Brightness get simulatorBrightness => params.simulatorBrightness; 66 | 67 | SimulatedIME? _lastActiveIme; 68 | 69 | PreferredSizeWidget _buildKeyboard(BuildContext context) { 70 | final ime = SystemTextInputChannelInterceptor.instance.maybeActiveIME; 71 | if (ime != null) { 72 | _lastActiveIme = ime; 73 | } 74 | 75 | final keyboard = params.deviceInfo.deviceKeyboard; 76 | final keyboardWidget = keyboard.builder( 77 | context, 78 | params, 79 | ime ?? _lastActiveIme, 80 | ); 81 | 82 | return PreferredSize( 83 | preferredSize: keyboardWidget.preferredSize, 84 | child: RepaintBoundary(child: keyboardWidget), 85 | ); 86 | } 87 | 88 | Widget _buildKeyboardWithAnimation(BuildContext context) { 89 | final keyboard = params.deviceInfo.deviceKeyboard; 90 | return ValueListenableBuilder( 91 | valueListenable: 92 | SystemTextInputChannelInterceptor.instance.activeIMEIdNotifier, 93 | builder: (context, _, __) => ValueListenableBuilder( 94 | valueListenable: SystemTextInputChannelInterceptor 95 | .instance.keyboardVisibilityNotifier, 96 | builder: (context, isVisible, child) { 97 | final keyboardChild = child as PreferredSizeWidget; 98 | 99 | return keyboard.animationBuilder( 100 | context, 101 | params.orientedScreenSize, 102 | params, 103 | isVisible, 104 | keyboardChild, 105 | ); 106 | }, 107 | child: _buildKeyboard(context), 108 | ), 109 | ); 110 | } 111 | 112 | /// Builds the app widget. 113 | /// 114 | /// This is wrapped in a [RepaintBoundary] to prevent the simulator stuff 115 | /// from being repainted when the stuff in the app is repainted. 116 | Widget _buildAppWidget(BuildContext context) { 117 | return RepaintBoundary( 118 | key: deviceContentAwareScreenForegroundKey, 119 | child: RepaintBoundary( 120 | key: SimulatorWidgetsBinding.instance.deviceScreenKey, 121 | child: Stack( 122 | children: [ 123 | ColoredBox( 124 | color: Colors.black, 125 | child: FocusScope.withExternalFocusNode( 126 | focusScopeNode: _appFocusScopeNode, 127 | parentNode: FocusManager.instance.rootScope, 128 | child: widget.appChild, 129 | ), 130 | ), 131 | _buildKeyboardWithAnimation(context), 132 | ], 133 | ), 134 | ), 135 | ); 136 | } 137 | 138 | /// This wraps the app with appropriate [MediaQuery] data. 139 | Widget _buildMediaQuery(BuildContext context) { 140 | final size = params.orientedScreenSize; 141 | 142 | final keyboard = params.deviceInfo.deviceKeyboard; 143 | 144 | return ValueListenableBuilder( 145 | valueListenable: 146 | SystemTextInputChannelInterceptor.instance.keyboardVisibilityNotifier, 147 | builder: (context, isKeyboardVisible, child) { 148 | return keyboard.viewInsetsBuilder( 149 | context, 150 | params, 151 | SystemTextInputChannelInterceptor.instance.maybeActiveIME, 152 | isKeyboardVisible, 153 | (context, viewInsets) { 154 | final viewPadding = params.viewPadding; 155 | 156 | final padding = EdgeInsets.only( 157 | left: max(0, viewPadding.left - viewInsets.left), 158 | top: max(0, viewPadding.top - viewInsets.top), 159 | right: max(0, viewPadding.right - viewInsets.right), 160 | bottom: max(0, viewPadding.bottom - viewInsets.bottom), 161 | ); 162 | 163 | final mediaQueryData = _mediaQueryData.copyWith( 164 | size: size, 165 | viewPadding: viewPadding, 166 | viewInsets: viewInsets, 167 | padding: padding, 168 | platformBrightness: simulatorBrightness, 169 | ); 170 | 171 | return MediaQuery( 172 | data: mediaQueryData, 173 | child: child!, 174 | ); 175 | }, 176 | ); 177 | }, 178 | child: _buildAppWidget(context), 179 | ); 180 | } 181 | 182 | Widget _buildResizableArea(BuildContext context) { 183 | final size = params.orientedScreenSize; 184 | 185 | return SizedBox.fromSize( 186 | size: size, 187 | child: MouseRegion( 188 | cursor: SystemMouseCursors.basic, 189 | hitTestBehavior: HitTestBehavior.opaque, 190 | child: GestureDetector( 191 | behavior: HitTestBehavior.opaque, 192 | onPanStart: (_) {}, 193 | child: _buildMediaQuery(context), 194 | ), 195 | ), 196 | ); 197 | } 198 | 199 | void _maybeResizeDevice(BuildContext context, Size newSize) { 200 | // final deviceInfo = params.deviceInfo; 201 | // final deviceScreenOrientation = params.deviceScreenOrientation; 202 | 203 | // final newDeviceInfo = deviceInfo.copyWith( 204 | // deviceScreenOrientation: deviceScreenOrientation, 205 | // deviceScreenSize: newSize, 206 | // ); 207 | 208 | // final newParams = params.copyWith( 209 | // deviceInfo: newDeviceInfo, 210 | // ); 211 | 212 | // if (newParams != params) { 213 | // context.read().value = newParams; 214 | // } 215 | } 216 | 217 | @override 218 | Widget build(BuildContext context) { 219 | return FittedBox( 220 | fit: BoxFit.contain, 221 | alignment: Alignment.topLeft, 222 | child: ResizableGestureDetectorWidget( 223 | params: params, 224 | child: RepaintBoundary( 225 | key: SimulatorWidgetsBinding.instance.deviceFrameKey, 226 | child: SimulatorRenderObjectWidget( 227 | key: const Key('simulator-render-object'), 228 | params: params, 229 | child: _buildResizableArea(context), 230 | ), 231 | ), 232 | ), 233 | ); 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /lib/src/widgets/utils/animated_view_insets.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class AnimatedViewInsets extends ImplicitlyAnimatedWidget { 4 | const AnimatedViewInsets({ 5 | super.key, 6 | required super.duration, 7 | required super.curve, 8 | required this.viewInsets, 9 | required this.builder, 10 | }); 11 | 12 | final EdgeInsetsGeometry viewInsets; 13 | final Widget Function(BuildContext context, EdgeInsets viewInsets) builder; 14 | 15 | @override 16 | ImplicitlyAnimatedWidgetState createState() => 17 | _AnimatedViewInsetsState(); 18 | } 19 | 20 | class _AnimatedViewInsetsState 21 | extends AnimatedWidgetBaseState { 22 | EdgeInsetsGeometryTween? _padding; 23 | 24 | @override 25 | void forEachTween(TweenVisitor visitor) { 26 | _padding = visitor( 27 | _padding, 28 | widget.viewInsets, 29 | (dynamic value) => 30 | EdgeInsetsGeometryTween(begin: value as EdgeInsetsGeometry)) 31 | as EdgeInsetsGeometryTween?; 32 | } 33 | 34 | @override 35 | Widget build(BuildContext context) { 36 | return widget.builder( 37 | context, 38 | _padding!.evaluate(animation).resolve(Directionality.of(context)), 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/src/widgets/utils/resizable_gesture_detector.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'dart:math'; 3 | 4 | import 'package:flutter/widgets.dart'; 5 | 6 | import 'package:flutter/material.dart'; 7 | import 'package:flutter_desktop_cursor/flutter_desktop_cursor.dart'; 8 | import 'package:flutter_simulator/src/imports.dart'; 9 | import 'package:window_manager/window_manager.dart'; 10 | 11 | class ResizableGestureDetectorWidget extends StatelessWidget { 12 | const ResizableGestureDetectorWidget({ 13 | super.key, 14 | required this.child, 15 | required this.params, 16 | }); 17 | 18 | final Widget child; 19 | final SimulatorParams params; 20 | 21 | @override 22 | Widget build(BuildContext context) { 23 | if (Platform.isMacOS) { 24 | return _MacOSResizableGestureDetector( 25 | params: params, 26 | child: child, 27 | ); 28 | } 29 | 30 | return MouseRegion( 31 | cursor: SystemMouseCursors.resizeUpLeftDownRight, 32 | hitTestBehavior: HitTestBehavior.deferToChild, 33 | child: GestureDetector( 34 | behavior: HitTestBehavior.deferToChild, 35 | onPanStart: (_) { 36 | windowManager.startResizing(ResizeEdge.bottomRight); 37 | }, 38 | child: child, 39 | ), 40 | ); 41 | } 42 | } 43 | 44 | class _MacOSResizableGestureDetector extends StatefulWidget { 45 | const _MacOSResizableGestureDetector({ 46 | required this.child, 47 | required this.params, 48 | }); 49 | 50 | final Widget child; 51 | final SimulatorParams params; 52 | 53 | @override 54 | State<_MacOSResizableGestureDetector> createState() => 55 | _MacOSResizableGestureDetectorState(); 56 | } 57 | 58 | class _MacOSResizableGestureDetectorState 59 | extends State<_MacOSResizableGestureDetector> { 60 | Size? _initialSize; 61 | Offset? _initialPanPosition; 62 | 63 | @override 64 | void initState() { 65 | super.initState(); 66 | windowManager.setResizable(false); 67 | } 68 | 69 | @override 70 | void dispose() { 71 | windowManager.setResizable(true); 72 | super.dispose(); 73 | } 74 | 75 | Future onPanStart(DragStartDetails details) async { 76 | _initialSize = await windowManager.getSize(); 77 | _initialPanPosition = details.globalPosition; 78 | } 79 | 80 | Future onPanUpdate(DragUpdateDetails details) async { 81 | if (_initialPanPosition == null) return; 82 | final frameSize = widget.params.rawDeviceScreenOrientation.transformSize( 83 | widget.params.deviceFrame.transformSize( 84 | widget.params.deviceScreenSize, 85 | widget.params, 86 | ), 87 | ); 88 | 89 | final frameAspectRatio = frameSize.aspectRatio; 90 | 91 | final delta = details.globalPosition - _initialPanPosition!; 92 | final newSize = _initialSize! + delta; 93 | 94 | if (widget.params.deviceInfo.isResizable) { 95 | final minSize = Size.square(WindowSizeManager.minWidth); 96 | 97 | final newFixedSize = Size( 98 | max(minSize.width, newSize.width), 99 | max(minSize.height, newSize.height), 100 | ); 101 | 102 | await windowManager.setSize(newFixedSize.rounded); 103 | return; 104 | } 105 | 106 | final minFrameWidth = WindowSizeManager.minWidth; 107 | final minFrameHeight = minFrameWidth / frameAspectRatio; 108 | 109 | final frameHeight = max( 110 | minFrameHeight, 111 | newSize.height - WindowSizeManager.headerHeight, 112 | ); 113 | 114 | final frameWidth = frameHeight * frameAspectRatio; 115 | 116 | final newFixedSize = Size( 117 | frameWidth, 118 | frameHeight + WindowSizeManager.headerHeight, 119 | ); 120 | 121 | await windowManager.setSize(newFixedSize.rounded); 122 | } 123 | 124 | Future onPanEnd() async { 125 | _initialPanPosition = null; 126 | _initialSize = null; 127 | } 128 | 129 | @override 130 | Widget build(BuildContext context) { 131 | return MouseRegion( 132 | cursor: FlutterDesktopCursors.resizeUpLeftDownRight, 133 | hitTestBehavior: HitTestBehavior.deferToChild, 134 | child: GestureDetector( 135 | behavior: HitTestBehavior.deferToChild, 136 | onPanStart: onPanStart, 137 | onPanUpdate: onPanUpdate, 138 | onPanEnd: (_) => onPanEnd(), 139 | onPanCancel: onPanEnd, 140 | child: widget.child, 141 | ), 142 | ); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_simulator 2 | description: A new Flutter package project. 3 | version: 0.0.1 4 | 5 | environment: 6 | sdk: '>=2.19.6 <3.0.0' 7 | flutter: ">=1.17.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | flutter_desktop_cursor: ^0.0.1 13 | matrix4_transform: ^2.0.1 14 | path_provider: ^2.0.14 15 | image: ^4.0.15 16 | url_launcher: ^6.1.10 17 | vector_math: ^2.1.4 18 | window_manager: 19 | git: 20 | url: https://github.com/kekland/window_manager 21 | ref: 37ae2cf 22 | 23 | dev_dependencies: 24 | flutter_test: 25 | sdk: flutter 26 | flutter_lints: ^2.0.0 27 | --------------------------------------------------------------------------------