igrasso
Hello everyone, I’m a totally new to phoenix, LiveView and in general frontend/backend development. But I think that starting with Phoenix LiveView is already a good step
.
Just to make things a bit more spicy, I need to take a self contained flutter web app and display it with LiveView. I’m following the guideline flutter_embedding. After reading enough about JS and how to work with LiveView I decided to create a hook. I moved all the generate flutter web files in the js/vendor/flutter_web folder. The hook is mounting correctly but I have no idea how to proceed. I’m not able to display anything in my flutter_targer div.
I’m sure that I’m missing something trivial but my inexperience with the web world is not helping me. Can somebody please point me in the correct direction?
import "../vendor/flutter_web/flutter.js"
let Hooks = {}
Hooks.Video = {
mounted(){
console.log("Hook Mounted!", this.el);
window.addEventListener("phx:page-loading-start", function (ev) {
// Embed flutter into div#flutter_target
let target = document.querySelector("#flutter_target");
_flutter.loader.loadEntrypoint({
onEntrypointLoaded: async function (engineInitializer) {
let appRunner = await engineInitializer.initializeEngine({
hostElement: target,
});
await appRunner.runApp();
},
});
});
}
}
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 7 of 7 Posts
KristerV
did you figure out how to run this hook? as in you need some HTML to make this code run: JavaScript interoperability — Phoenix LiveView v1.2.5
igrasso
I’m using some html in the defmodule. This is how I defined it.
During the loading of the page, if I put a breakpoint, it seems that the line
is never reached.
ndrean
I imagine you exported your hook and imported it in “app.js” and passed it to the Liveview socket.
igrasso
This is the code that I wrote in app.js:
And in the console, I receive the message:
“Hook Mounted!”
Zurga
Instead of the document.querySelector you can use
this.el. And then I would addphx-update="ignore"to the element with the Hook on it in the template. Or, if you want to receive updates, implement anupdate()function in the Hook.ndrean
Did you try without the “phx:page-loading-start” listener?
In case you want dynamic import, check this
igrasso
@ndrean thank you for the reading, for sure the dynamic import could be useful in the future.
If I drop the listener I get an error on the _flutter.loader… telling me “Uncaught ReferenceError: _flutter is not defined”
Now I don’t know if this is expected because something is not loaded, or there is an issue with my import flutter.js. The path is correct and at the end of the flutter.js file I can read _flutter.loader = new FlutterLoader();