Open arnleal09 opened 6 days ago
You don't actually use the index.html
file you attached in the NextJs app, correct?
I see flutter initialization in the file.
Also, do you have the complete code I can play with? It would be nice to have a minimal reproducible sample.
There shouldn't be limitations in displaying multiple views at the same time, but of course it could be possible that you've found a bug or something is wrong with your setup. I also have a deployed version of the react app from the repo where multiple views are displayed correctly: https://p-mazhnik.github.io/flutter-embedding/react/
@p-mazhnik Hi, thanks for the quick reply. In the Next.js document, I call the flutter.js file. Unfortunately, I can’t share the full code because it’s not my property. I see that in your deployment it works fine, so could it be related to the use of the Next.js framework?
On the React side, I removed the ViewWrapper, but I don’t think that should be causing the problem, as at least one view is being rendered. I’m using simple views like a circular loading indicator or a container with a color, but it’s always the second view that gets displayed. If I change the second widget call to a container, it shows, but adding another view does the same only the last one is rendered. The build is in release mode, and I see that the example uses profile mode. I tried that as well, but I’m getting the same result.
class MyDocument extends Document {
render() {
return (
<Html dir="ltr" lang={countryLanguage}>
<Head>
<link rel="preconnect" href="https://fonts.googleapis.com/" />
<link rel="icon" href={`/${THEME}/favicon.ico`} sizes="32x32" type="image/x-icon" />
<link rel="apple-touch-icon" href={`/${THEME}/favicon.ico`} />
<script src="https://url/flutter.js" defer></script>
export default function mainPage({ Component, pageProps }) {
return (
<FlutterAppProvider>
<Component {...pageProps} />
</FlutterAppProvider>
);
}
export default function LayoutMain({ flutterApp }: TypeProps) {
const [screen, setScreen] = useState('container')
const [screen2, setScreen2] = useState('loading')
const [clicks, setClicks] = useState(0)
const [text, setText] = useState('')
return (
<Box className={style.layout} data-testid="LayoutMain">
<Box as="section" className={style.section}>
<Box className={style.container}>
<FlutterView
key={'1'}
className={'loading1'}
flutterApp={flutterApp}
onClicksChange={setClicks}
onScreenChange={setScreen}
onTextChange={setText}
removeView={() => { }}
text={text}
clicks={clicks}
screen={screen}
/>
</Box>
</Box>
<Box className={style.container}>
<FlutterView
key={'2'}
className={'loading2'}
flutterApp={flutterApp}
onClicksChange={setClicks}
onScreenChange={setScreen2}
onTextChange={setText}
removeView={() => { }}
text={text}
clicks={clicks}
screen={screen2}
/>
</Box>
</Box>
)
}
so could it be related to the use of the Next.js framework?
I don't think so, it is still React
I can’t share the full code because it’s not my property
In such case, you should provide a minimal reproducible sample, which you can create using a fresh Next JS app.
I just tried multiple FlutterView
components in a fresh NextJS app. Everything is working as expected:
https://github.com/p-mazhnik/flutter-embedding/tree/nextjs
cd nextjs-flutter && yarn run prebuild && yarn run dev
I am using the example of rendering Flutter widgets in a React web page with NextJs. When I add two components on the same page, only one of the views renders. Using print, I can see that the flutter ViewCollection does indeed contain both views, and the target has two different elements with distinct IDs. However, the second view is always the one that gets displayed. There is any limitation to these use? I am using flutter version 3.24.2
other elements
I am making the flutter init in this way and passing the context to the root of all components. When i do navigation for another page the widgets render ok, the only problem is when are two in the same page.