1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/web_embedding/ng-flutter
dependabot[bot] 10b21a4567 Bump @angular/animations from 18.2.12 to 19.0.0 in /web_embedding/ng-flutter (#2495)
Bumps [@angular/animations](https://github.com/angular/angular/tree/HEAD/packages/animations) from 18.2.12 to 19.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/angular/angular/releases"><code>@​angular/animations</code>'s releases</a>.</em></p>
<blockquote>
<h2>v19.0.0</h2>
<h1>19.0.0 (2024-11-19)</h1>
<p>Explore Angular v19 with a blog post from the Angular team: <a href="https://blog.angular.dev/meet-angular-v19-7b29dfd05b84">https://blog.angular.dev/meet-angular-v19-7b29dfd05b84</a></p>
<h2>Breaking Changes</h2>
<h3>compiler</h3>
<ul>
<li><code>this.foo</code> property reads no longer refer to template context variables. If you intended to read the template variable, do not use <code>this.</code>.</li>
</ul>
<h3>core</h3>
<ul>
<li>
<p>Angular directives, components and pipes are now standalone by default.</p>
<ul>
<li>Specify <code>standalone: false</code> for declarations that are currently declared in <code>@NgModule</code>s.</li>
<li><code>ng update</code> for v19 will take care of this automatically.</li>
</ul>
</li>
<li>
<p>TypeScript versions less than 5.5 are no longer supported.</p>
</li>
<li>
<p>Timing changes for <code>effect</code> API (in developer preview):</p>
<ul>
<li>
<p>effects which are triggered outside of change detection run as part of
the change detection process instead of as a microtask. Depending on the
specifics of application/test setup, this can result in them executing
earlier or later (or requiring additional test steps to trigger; see below
examples).</p>
</li>
<li>
<p>effects which are triggered during change detection (e.g. by input
signals) run <em>earlier</em>, before the component's template.</p>
</li>
</ul>
</li>
<li>
<p><code>ExperimentalPendingTasks</code> has been renamed to <code>PendingTasks</code>.</p>
</li>
<li>
<p>The <code>autoDetect</code> feature of <code>ComponentFixture</code> will now
attach the fixture to the <code>ApplicationRef</code>. As a result, errors during
automatic change detection of the fixture be reported to the <code>ErrorHandler</code>.
This change may cause custom error handlers to observe new failures that were previously unreported.</p>
</li>
<li>
<p><code>createComponent</code> will now render default fallback with empty <code>projectableNodes</code>.</p>
<ul>
<li>When passing an empty array to <code>projectableNodes</code> in the <code>createComponent</code> API, the default fallback content
of the <code>ng-content</code> will be rendered if present. To prevent rendering the default content, pass <code>document.createTextNode('')</code> as a <code>projectableNode</code>.</li>
</ul>
<pre lang="ts"><code>// The first ng-content will render the default fallback content if present
createComponent(MyComponent. { projectableNodes: [[], [secondNode]] });
<p>// To prevent projecting the default fallback content:
createComponent(MyComponent. { projectableNodes: [[document.createTextNode('')], [secondNode]] });</p>
<p></code></pre></p>
</li>
<li>
<p>Errors that are thrown during <code>ApplicationRef.tick</code>
will now be rethrown when using <code>TestBed</code>. These errors should be
resolved by ensuring the test environment is set up correctly to
complete change detection successfully. There are two alternatives to
catch the errors:</p>
<ul>
<li>Instead of waiting for automatic change detection to happen, trigger</li>
</ul>
</li>
</ul>
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/angular/angular/blob/main/CHANGELOG.md"><code>@​angular/animations</code>'s changelog</a>.</em></p>
<blockquote>
<h1>19.0.0 (2024-11-19)</h1>
<p>Blog post: <a href="https://blog.angular.dev/meet-angular-v19-7b29dfd05b84">https://blog.angular.dev/meet-angular-v19-7b29dfd05b84</a></p>
<h2>Breaking Changes</h2>
<h3>compiler</h3>
<ul>
<li><code>this.foo</code> property reads no longer refer to template context variables. If you intended to read the template variable, do not use <code>this.</code>.</li>
</ul>
<h3>core</h3>
<ul>
<li>
<p>Angular directives, components and pipes are now standalone by default.</p>
<ul>
<li>Specify <code>standalone: false</code> for declarations that are currently declared in <code>@NgModule</code>s.</li>
<li><code>ng update</code> for v19 will take care of this automatically.</li>
</ul>
</li>
<li>
<p>TypeScript versions less than 5.5 are no longer supported.</p>
</li>
<li>
<p>Timing changes for <code>effect</code> API (in developer preview):</p>
<ul>
<li>
<p>effects which are triggered outside of change detection run as part of
the change detection process instead of as a microtask. Depending on the
specifics of application/test setup, this can result in them executing
earlier or later (or requiring additional test steps to trigger; see below
examples).</p>
</li>
<li>
<p>effects which are triggered during change detection (e.g. by input
signals) run <em>earlier</em>, before the component's template.</p>
</li>
</ul>
</li>
<li>
<p><code>ExperimentalPendingTasks</code> has been renamed to <code>PendingTasks</code>.</p>
</li>
<li>
<p>The <code>autoDetect</code> feature of <code>ComponentFixture</code> will now
attach the fixture to the <code>ApplicationRef</code>. As a result, errors during
automatic change detection of the fixture be reported to the <code>ErrorHandler</code>.
This change may cause custom error handlers to observe new failures that were previously unreported.</p>
</li>
<li>
<p><code>createComponent</code> will now render default fallback with empty <code>projectableNodes</code>.</p>
<ul>
<li>When passing an empty array to <code>projectableNodes</code> in the <code>createComponent</code> API, the default fallback content
of the <code>ng-content</code> will be rendered if present. To prevent rendering the default content, pass <code>document.createTextNode('')</code> as a <code>projectableNode</code>.</li>
</ul>
<pre lang="ts"><code>// The first ng-content will render the default fallback content if present
createComponent(MyComponent. { projectableNodes: [[], [secondNode]] });
<p>// To prevent projecting the default fallback content:
createComponent(MyComponent. { projectableNodes: [[document.createTextNode('')], [secondNode]] });</p>
<p></code></pre></p>
</li>
<li>
<p>Errors that are thrown during <code>ApplicationRef.tick</code>
will now be rethrown when using <code>TestBed</code>. These errors should be
resolved by ensuring the test environment is set up correctly to
complete change detection successfully. There are two alternatives to
catch the errors:</p>
<ul>
<li>Instead of waiting for automatic change detection to happen, trigger
it synchronously and expect the error. For example, a jasmine test
could write <code>expect(() =&gt; TestBed.inject(ApplicationRef).tick()).toThrow()</code></li>
</ul>
</li>
</ul>
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="09df589e31"><code>09df589</code></a> refactor(core): Migrate all packages with the <code>explicit-standalone-flag</code> sche...</li>
<li><a href="84b6896956"><code>84b6896</code></a> refactor(platform-server): Add an ssr benchmark setup. (<a href="https://github.com/angular/angular/tree/HEAD/packages/animations/issues/57647">#57647</a>)</li>
<li><a href="9dbe6fc18b"><code>9dbe6fc</code></a> refactor: update license text to point to angular.dev (<a href="https://github.com/angular/angular/tree/HEAD/packages/animations/issues/57901">#57901</a>)</li>
<li>See full diff in <a href="https://github.com/angular/angular/commits/19.0.0/packages/animations">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@angular/animations&package-manager=npm_and_yarn&previous-version=18.2.12&new-version=19.0.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
2024-11-25 07:17:10 +00:00
..
2023-05-06 10:53:17 +10:00

ng-flutter

This Angular project is a simple example of how Angular and Flutter web apps could be integrated, and have them interop.

Points of Interest

Angular

This repository is a quite standard Angular app. The following changes were made to be able to use (and interop) with a Flutter web application:

  • package.json has a custom prebuild script that builds the Flutter web app, so Angular can find it later.
  • flutter.js is added as a "scripts" entry in angular.json. Angular takes care of minimizing and injecting it as any other script.
  • The rest of the flutter app flutter/build/web/ is registered as an "assets" entry in angular.json, and moved to /flutter.
  • The ng-flutter component takes care of embedding Flutter web, and yielding control to Angular through an appLoaded EventEmitter. The object yielded by this emitter is a state controller exposed by flutter via a JS custom event!

Flutter

The embedded Flutter application lives in the flutter directory of this repo. That application is a standard web app, that doesn't need to be aware that it's going to be embedded in another framework.

  • Flutter uses new @staticInterop methods to allow certain Dart functions to be called from JavaScript.
  • Look at how createDartExport and broadcastAppEvent work together to make the _state controller of the Flutter app available to Angular!

How to build the app

Requirements

If you want to build and run this demo on your machine, you'll need a moderately recent version of Angular:

$ ng version

Angular CLI: 17.0.0
Node: 20.9.0
Package Manager: npm 10.1.0
OS: linux x64

And Flutter:

$ flutter --version

Flutter 3.13.9 • channel stable
Framework • revision d211f42860 (2 weeks ago) • 2023-10-25 13:42:25 -0700
Engine • revision 0545f8705d
Tools • Dart 3.1.5 • DevTools 2.25.0

Ensure npm, ng and flutter are present in your $PATH.

Building the app

This repository is a moderately standard Angular app. It integrates Flutter web by making it part of the Angular assets.

In order to build this app, first fetch its npm dependencies:

$ npm install

added 963 packages, and audited 964 packages in 17s

93 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Then run the build script. It'll take care of building Flutter automatically:

$ npm run build

> ng-flutter@0.0.0 prebuild

... Flutter web build output ...

Compiling lib/main.dart for the Web...

> ng-flutter@0.0.0 build
> ng build

... Angular build output ...

✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Local Angular development

Once you've reached this point, you should be able to work with your Angular application normally, for example to run a local web server:

$ npm run start

> ng-flutter@0.0.0 start
> ng serve

✔ Browser application bundle generation complete.

Initial Chunk Files   | Names         |  Raw Size
vendor.js             | vendor        |   4.38 MB | 

... Angular build output...

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **


✔ Compiled successfully.

Navigate to http://localhost:4200/. The application will automatically reload if you change any of its Angular source files.

Local Flutter web development

The Flutter app lives inside the flutter directory, and can be developed independently. Just do any changes on Flutter web as you'd normally do. It even includes a small web/index.html so you can see changes to your app without running the whole Angular setup.

Note

For now, Angular does not auto-detect changes to your Flutter web app, so once you're happy with your Flutter web app, make sure to call npm run build so everything rebuilds and gets placed into its correct location.

Deploying the app

After npm run build, you should have a deployable Angular + Flutter web app in the dist directory of this Angular project.

Your built app can can be deployed anywhere, but do check Firebase hosting for a super-easy deployment experience!

Troubleshooting

Flutter

Ensure your flutter app is properly rebuilt after any changes.

  • Run npm run build to re-build the Flutter app.

If you encounter error messages like:

Error: Can't resolve 'flutter/build/web/flutter.js' in '/my/checkout/of/ng-flutter'

You definitely need to run npm run build!

Reach out to the team(s)!

Have you had any problem not covered in this README? Do you want to see other embedding examples?

Let us know by creating an issue or opening a new pull request.

Thanks!