Unverified Commit 96b49aae authored by Alex Wallen's avatar Alex Wallen Committed by GitHub

[macOS] Add `flutter_view` example. (#111326)

parent 5f9ad01e
......@@ -2502,6 +2502,16 @@ targets:
["devicelab", "hostonly"]
task_name: flutter_gallery_macos__start_up
- name: Mac flutter_view_macos__start_up
bringup: true # New target https://github.com/flutter/flutter/issues/109633
presubmit: false
recipe: devicelab/devicelab_drone
timeout: 60
properties:
tags: >
["devicelab", "hostonly"]
task_name: flutter_view_macos__start_up
- name: Mac framework_tests_libraries
recipe: flutter/flutter_drone
timeout: 60
......
......@@ -249,6 +249,9 @@
/dev/devicelab/bin/tasks/web_benchmarks_html.dart @yjbanov @flutter/web
/dev/devicelab/bin/tasks/windows_home_scroll_perf__timeline_summary.dart @jonahwilliams @flutter/engine
/dev/devicelab/bin/tasks/windows_startup_test.dart @loic-sharma @flutter/desktop
/dev/devicelab/bin/tasks/complex_layout_macos__compile.dart @a-wallen @flutter/desktop
/dev/devicelab/bin/tasks/flutter_gallery_macos__compile.dart @a-wallen @flutter/desktop
/dev/devicelab/bin/tasks/flutter_view_macos__start_up.dart @a-wallen @flutter/desktop
## Host only framework tests
# Linux analyze
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_devicelab/framework/devices.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/tasks/perf_tests.dart';
Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.macos;
await task(createFlutterViewStartupTest());
}
#include "ephemeral/Flutter-Generated.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "flutter_view.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "flutter_view.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "flutter_view.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Profile"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "33CC10EC2044A3C60003C045"
BuildableName = "flutter_view.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Cocoa
import FlutterMacOS
@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
}
This diff is collapsed.
// Application-level settings for the Runner target.
//
// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
// future. If not, the values below would default to using the project name when this becomes a
// 'flutter create' template.
// The application's name. By default this is also the title of the Flutter window.
PRODUCT_NAME = flutter_view
// The application's bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = io.flutter.examples.flutterView
// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2022 io.flutter.examples. All rights reserved.
#include "../../Flutter/Flutter-Debug.xcconfig"
#include "Warnings.xcconfig"
#include "../../Flutter/Flutter-Release.xcconfig"
#include "Warnings.xcconfig"
WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
GCC_WARN_UNDECLARED_SELECTOR = YES
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
CLANG_WARN_PRAGMA_PACK = YES
CLANG_WARN_STRICT_PROTOTYPES = YES
CLANG_WARN_COMMA = YES
GCC_WARN_STRICT_SELECTOR_MATCH = YES
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
GCC_WARN_SHADOW = YES
CLANG_WARN_UNREACHABLE_CODE = YES
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>$(PRODUCT_COPYRIGHT)</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Cocoa
import FlutterMacOS
/**
The window that is automatically generated when `flutter create --target=macos`
on a project. `MainFlutterWindow` uses a FlutterViewController as it's content
view controller by default.
*/
class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
let windowFrame = self.frame
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: Bundle.main)
// `flutter create --target=macos` uses this class (`self`) as an entrypoint
// for drawing on a surface. The line below intercepts that and uses
// the storyboard from `Main.storyboard`.
self.contentViewController = storyboard.instantiateController(withIdentifier: "MainViewController") as! NSViewController
self.setFrame(windowFrame, display: true)
super.awakeFromNib()
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import AppKit
import FlutterMacOS
/**
The code behind a storyboard view which splits a flutter view and a macOS view.
*/
class MainViewController: NSViewController, NativeViewControllerDelegate {
static let emptyString: String = ""
static let ping: String = "ping"
static let channel: String = "increment"
var nativeViewController: NativeViewController?
var flutterViewController: FlutterViewController?
var messageChannel: FlutterBasicMessageChannel?
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
if segue.identifier == "NativeViewControllerSegue" {
self.nativeViewController = segue.destinationController as? NativeViewController
// Since`MainViewController` owns the platform channel, but not the
// UI elements that trigger an action, those UI elements need a reference
// to this controller to send messages on the platform channel.
self.nativeViewController?.delegate = self
}
if segue.identifier == "FlutterViewControllerSegue" {
self.flutterViewController = segue.destinationController as? FlutterViewController
RegisterMethodChannel(registry: self.flutterViewController!)
weak var weakSelf = self
messageChannel?.setMessageHandler({ (message, reply) in
// Dispatch an event, incrementing the counter in this case, when *any*
// message is received.
// Depending on the order of initialization, the nativeViewController
// might not be initialized until this point.
weakSelf?.nativeViewController?.didReceiveIncrement()
reply(MainViewController.emptyString)
})
}
}
func RegisterMethodChannel(registry: FlutterPluginRegistry) {
let registrar = registry.registrar(forPlugin: "")
messageChannel = FlutterBasicMessageChannel(
name: MainViewController.channel,
binaryMessenger: registrar.messenger,
codec: FlutterStringCodec.sharedInstance())
}
// Call in any instance where `ping` is to be sent through the `increment`
// channel.
func didTapIncrementButton() {
self.messageChannel?.sendMessage(MainViewController.ping)
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import AppKit
protocol NativeViewControllerDelegate: NSObjectProtocol {
func didTapIncrementButton()
}
/**
The code behind a native view to be displayed in the `MainFlutterViewController`
as an embed segue. If any storyboard view inherits from this class definition,
it should contain a function to handle for `handleIncrement`
*/
class NativeViewController: NSViewController {
var count: Int?
var labelText: String {
get {
let count = self.count ?? 0
return "Flutter button tapped \(count) time\(count == 1 ? "" : "s")"
}
}
var delegate: NativeViewControllerDelegate?
@IBOutlet weak var incrementLabel: NSTextField!
@IBAction func handleIncrement(_ sender: Any) {
self.delegate?.didTapIncrementButton()
}
override func viewDidLoad() {
super.viewDidLoad()
setState(for: 0)
}
func didReceiveIncrement() {
setState(for: (self.count ?? 0) + 1)
}
func setState(for count: Int) {
self.count = count
self.incrementLabel.stringValue = labelText
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment