blob: c74edca8ccd45731d346a1fd27f72cd933abf05e [file] [log] [blame]
// Copyright 2017 The Fuchsia 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:fidl_fuchsia_sys/fidl_async.dart';
import 'package:fidl_fuchsia_ui_app/fidl_async.dart' show ViewProviderProxy;
import 'package:fidl_fuchsia_ui_views/fidl_async.dart'
show ViewToken, ViewHolderToken;
import 'package:flutter/widgets.dart';
import 'package:fuchsia_scenic_flutter/child_view.dart' show ChildView;
import 'package:fuchsia_scenic_flutter/child_view_connection.dart'
show ChildViewConnection;
import '';
import 'package:meta/meta.dart';
import 'package:zircon/zircon.dart';
/// A [Widget] that displays the view of the application it launches.
class ApplicationWidget extends StatefulWidget {
/// The application to launch.
final String url;
/// The [Launcher] used to launch the application.
final Launcher launcher;
/// Called if the application terminates.
final VoidCallback onDone;
/// Child can be hit tested.
final bool hitTestable;
/// Child can be focused.
final bool focusable;
/// Constructor.
const ApplicationWidget({
@required this.url,
@required this.launcher,
Key key,
this.hitTestable = true,
this.focusable = true,
}) : super(key: key);
_ApplicationWidgetState createState() => new _ApplicationWidgetState();
class _ApplicationWidgetState extends State<ApplicationWidget> {
ComponentControllerProxy _applicationController;
ChildViewConnection _connection;
void initState() {
void didUpdateWidget(ApplicationWidget old) {
if (old.url == widget.url && old.launcher == widget.launcher) {
void dispose() {
Widget build(BuildContext context) => new ChildView(
connection: _connection,
hitTestable: widget.hitTestable,
focusable: widget.focusable,
void _cleanUp() {
_connection = null;
void _launchApp() {
_applicationController = new ComponentControllerProxy();
Services incomingServices = new Services();
new LaunchInfo(
url: widget.url, directoryRequest: incomingServices.request()),
_connection = ChildViewConnection(
onAvailable: (_) {},
onUnavailable: (_) => widget.onDone?.call(),
/// Creates a [ViewProviderProxy] from a [Services], closing it in the
/// process.
ViewProviderProxy _consumeServices(Services services) {
ViewProviderProxy viewProvider = ViewProviderProxy();
return viewProvider;
/// Creates a handle to a [ViewHolderToken] from a [ViewProviderProxy],
/// closing it in the process.
ViewHolderToken _consumeViewProvider(
ViewProviderProxy viewProvider,
) {
final viewTokens = EventPairPair();
assert(viewTokens.status == ZX.OK);
final viewHolderToken = ViewHolderToken(value: viewTokens.first);
final viewToken = ViewToken(value: viewTokens.second);
viewProvider.createView(viewToken.value, null, null);
return viewHolderToken;