-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ea67bf
commit 9ec8047
Showing
9 changed files
with
254 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright 2014 The Flutter Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
# windows_c_multi_window | ||
# Windows multi-window sample | ||
|
||
A new Flutter project. | ||
This repository contains an experimental Flutter Windows app that launches | ||
multiple windows. This sample requires | ||
[Flutter's `master` channel](https://docs.flutter.dev/release/upgrade#changing-channels). | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) | ||
|
||
For help getting started with Flutter development, view the | ||
[online documentation](https://docs.flutter.dev/), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. | ||
This sample is aspirational, may not actually work, may be outdated, and/or have | ||
other issues. This sample links against experimental Flutter Windows APIs that | ||
may break at any time. DO NOT DEPEND ON ANYTHING IN THIS REPOSITORY. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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 'dart:ui' show FlutterView; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
|
||
/// Calls [viewBuilder] for every view added to the app to obtain the widget to | ||
/// render into that view. The current view can be looked up with [View.of]. | ||
class MultiViewApp extends StatefulWidget { | ||
const MultiViewApp({super.key, required this.viewBuilder}); | ||
|
||
final WidgetBuilder viewBuilder; | ||
|
||
@override | ||
State<MultiViewApp> createState() => _MultiViewAppState(); | ||
} | ||
|
||
class _MultiViewAppState extends State<MultiViewApp> with WidgetsBindingObserver { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
WidgetsBinding.instance.addObserver(this); | ||
_updateViews(); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(MultiViewApp oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
// Need to re-evaluate the viewBuilder callback for all views. | ||
_views.clear(); | ||
_updateViews(); | ||
} | ||
|
||
@override | ||
void didChangeMetrics() { | ||
_updateViews(); | ||
} | ||
|
||
Map<Object, Widget> _views = <Object, Widget>{}; | ||
|
||
void _updateViews() { | ||
final Map<Object, Widget> newViews = <Object, Widget>{}; | ||
for (final FlutterView view in WidgetsBinding.instance.platformDispatcher.views) { | ||
final Widget viewWidget = _views[view.viewId] ?? _createViewWidget(view); | ||
newViews[view.viewId] = viewWidget; | ||
} | ||
setState(() { | ||
_views = newViews; | ||
}); | ||
} | ||
|
||
Widget _createViewWidget(FlutterView view) { | ||
return View( | ||
view: view, | ||
child: Builder( | ||
builder: widget.viewBuilder, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
WidgetsBinding.instance.removeObserver(this); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ViewCollection(views: _views.values.toList(growable: false)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.