Skip to content

Commit 42c8734

Browse files
author
david
committed
feat: support two page
1 parent c1f9e3a commit 42c8734

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

demos/js_thread_mode/ios/Runner/AppDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ import UIKit
6262
private func destoryEngine(engineId: Int) {
6363
let flutterEngine = flutterEngines[engineId]
6464
flutterEngine?.destroyContext();
65+
flutterEngines.removeValue(forKey: engineId)
6566
}
6667
}

demos/js_thread_mode/lib/main.dart

+82
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,39 @@ class FirstPageState extends State<FirstPage> {
111111
},
112112
child: const Text('Same single thread'),
113113
),
114+
const SizedBox(height: 20),
115+
ElevatedButton(
116+
onPressed: () {
117+
Navigator.push(context, MaterialPageRoute(builder: (context) {
118+
return WebFDemoTwoPage(
119+
controller1: webFController(ThreadMode.differentDedicated),
120+
controller2: webFController(ThreadMode.differentDedicated));
121+
}));
122+
},
123+
child: const Text('Different dedicated thread (Two page)'),
124+
),
125+
const SizedBox(height: 20),
126+
ElevatedButton(
127+
onPressed: () {
128+
Navigator.push(context, MaterialPageRoute(builder: (context) {
129+
return WebFDemoTwoPage(
130+
controller1: webFController(ThreadMode.sameDedicated),
131+
controller2: webFController(ThreadMode.sameDedicated));
132+
}));
133+
},
134+
child: const Text('Same dedicated thread (Two page)'),
135+
),
136+
const SizedBox(height: 20),
137+
ElevatedButton(
138+
onPressed: () {
139+
Navigator.push(context, MaterialPageRoute(builder: (context) {
140+
return WebFDemoTwoPage(
141+
controller1: webFController(ThreadMode.sameSingle),
142+
controller2: webFController(ThreadMode.sameSingle));
143+
}));
144+
},
145+
child: const Text('Same single thread (Two page)'),
146+
),
114147
];
115148

116149
if (showNewEngineButton) {
@@ -181,3 +214,52 @@ class _WebFDemoState extends State<WebFDemo> {
181214
));
182215
}
183216
}
217+
218+
class WebFDemoTwoPage extends StatefulWidget {
219+
final WebFController controller1;
220+
final WebFController controller2;
221+
222+
const WebFDemoTwoPage({
223+
super.key,
224+
required this.controller1,
225+
required this.controller2,
226+
});
227+
228+
@override
229+
_WebFDemoTwoPageState createState() => _WebFDemoTwoPageState();
230+
}
231+
232+
class _WebFDemoTwoPageState extends State<WebFDemoTwoPage> {
233+
@override
234+
void dispose() {
235+
widget.controller1.dispose();
236+
widget.controller2.dispose();
237+
super.dispose();
238+
}
239+
240+
@override
241+
Widget build(BuildContext context) {
242+
return Scaffold(
243+
appBar: AppBar(
244+
title: const Text('WebF Demo'),
245+
),
246+
body: LayoutBuilder(
247+
builder: (BuildContext context, BoxConstraints constraints) {
248+
double halfHeight = constraints.maxHeight / 2;
249+
return Column(
250+
children: [
251+
SizedBox(
252+
height: halfHeight,
253+
child: WebF(controller: widget.controller1),
254+
),
255+
SizedBox(
256+
height: halfHeight,
257+
child: WebF(controller: widget.controller2),
258+
),
259+
],
260+
);
261+
},
262+
),
263+
);
264+
}
265+
}

0 commit comments

Comments
 (0)