Skip to content

Commit c9be554

Browse files
authored
fix: use js_interop_unsafe jsify() to convert dart object to JSObject rather than DIY mapToJSObj method (#229)
1 parent d781f2e commit c9be554

File tree

7 files changed

+82
-171
lines changed

7 files changed

+82
-171
lines changed

example/.metadata

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@
44
# This file should be version controlled and should not be manually edited.
55

66
version:
7-
revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713
8-
channel: beta
7+
revision: "c519ee916eaeb88923e67befb89c0f1dabfa83e6"
8+
channel: "stable"
99

1010
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6
17+
base_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6
18+
- platform: web
19+
create_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6
20+
base_revision: c519ee916eaeb88923e67befb89c0f1dabfa83e6
21+
22+
# User provided section
23+
24+
# List of Local paths (relative to this file) that should be
25+
# ignored by the migrate tool.
26+
#
27+
# Files that are not part of the templates will be ignored by default.
28+
unmanaged_files:
29+
- 'lib/main.dart'
30+
- 'ios/Runner.xcodeproj/project.pbxproj'

example/lib/generated_plugin_registrant.dart

Lines changed: 0 additions & 17 deletions
This file was deleted.

example/pubspec.lock

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ packages:
1212
dependency: transitive
1313
description:
1414
name: async
15-
sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63
15+
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
1616
url: "https://pub.dev"
1717
source: hosted
18-
version: "2.12.0"
18+
version: "2.11.0"
1919
boolean_selector:
2020
dependency: transitive
2121
description:
2222
name: boolean_selector
23-
sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea"
23+
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
2424
url: "https://pub.dev"
2525
source: hosted
26-
version: "2.1.2"
26+
version: "2.1.1"
2727
characters:
2828
dependency: transitive
2929
description:
3030
name: characters
31-
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
31+
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
3232
url: "https://pub.dev"
3333
source: hosted
34-
version: "1.4.0"
34+
version: "1.3.0"
3535
clock:
3636
dependency: transitive
3737
description:
3838
name: clock
39-
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
39+
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
4040
url: "https://pub.dev"
4141
source: hosted
42-
version: "1.1.2"
42+
version: "1.1.1"
4343
collection:
4444
dependency: transitive
4545
description:
4646
name: collection
47-
sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76"
47+
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
4848
url: "https://pub.dev"
4949
source: hosted
50-
version: "1.19.1"
50+
version: "1.19.0"
5151
cupertino_icons:
5252
dependency: "direct main"
5353
description:
@@ -60,10 +60,10 @@ packages:
6060
dependency: transitive
6161
description:
6262
name: fake_async
63-
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
63+
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
6464
url: "https://pub.dev"
6565
source: hosted
66-
version: "1.3.2"
66+
version: "1.3.1"
6767
flutter:
6868
dependency: "direct main"
6969
description: flutter
@@ -79,30 +79,22 @@ packages:
7979
description: flutter
8080
source: sdk
8181
version: "0.0.0"
82-
js:
83-
dependency: transitive
84-
description:
85-
name: js
86-
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
87-
url: "https://pub.dev"
88-
source: hosted
89-
version: "0.6.5"
9082
leak_tracker:
9183
dependency: transitive
9284
description:
9385
name: leak_tracker
94-
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
86+
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
9587
url: "https://pub.dev"
9688
source: hosted
97-
version: "10.0.8"
89+
version: "10.0.7"
9890
leak_tracker_flutter_testing:
9991
dependency: transitive
10092
description:
10193
name: leak_tracker_flutter_testing
102-
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
94+
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
10395
url: "https://pub.dev"
10496
source: hosted
105-
version: "3.0.9"
97+
version: "3.0.8"
10698
leak_tracker_testing:
10799
dependency: transitive
108100
description:
@@ -115,10 +107,10 @@ packages:
115107
dependency: transitive
116108
description:
117109
name: matcher
118-
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
110+
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
119111
url: "https://pub.dev"
120112
source: hosted
121-
version: "0.12.17"
113+
version: "0.12.16+1"
122114
material_color_utilities:
123115
dependency: transitive
124116
description:
@@ -131,18 +123,18 @@ packages:
131123
dependency: transitive
132124
description:
133125
name: meta
134-
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
126+
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
135127
url: "https://pub.dev"
136128
source: hosted
137-
version: "1.16.0"
129+
version: "1.15.0"
138130
path:
139131
dependency: transitive
140132
description:
141133
name: path
142-
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
134+
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
143135
url: "https://pub.dev"
144136
source: hosted
145-
version: "1.9.1"
137+
version: "1.9.0"
146138
sky_engine:
147139
dependency: transitive
148140
description: flutter
@@ -152,50 +144,50 @@ packages:
152144
dependency: transitive
153145
description:
154146
name: source_span
155-
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
147+
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
156148
url: "https://pub.dev"
157149
source: hosted
158-
version: "1.10.1"
150+
version: "1.10.0"
159151
stack_trace:
160152
dependency: transitive
161153
description:
162154
name: stack_trace
163-
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
155+
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
164156
url: "https://pub.dev"
165157
source: hosted
166-
version: "1.12.1"
158+
version: "1.12.0"
167159
stream_channel:
168160
dependency: transitive
169161
description:
170162
name: stream_channel
171-
sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d"
163+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
172164
url: "https://pub.dev"
173165
source: hosted
174-
version: "2.1.4"
166+
version: "2.1.2"
175167
string_scanner:
176168
dependency: transitive
177169
description:
178170
name: string_scanner
179-
sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43"
171+
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
180172
url: "https://pub.dev"
181173
source: hosted
182-
version: "1.4.1"
174+
version: "1.3.0"
183175
term_glyph:
184176
dependency: transitive
185177
description:
186178
name: term_glyph
187-
sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e"
179+
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
188180
url: "https://pub.dev"
189181
source: hosted
190-
version: "1.2.2"
182+
version: "1.2.1"
191183
test_api:
192184
dependency: transitive
193185
description:
194186
name: test_api
195-
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
187+
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
196188
url: "https://pub.dev"
197189
source: hosted
198-
version: "0.7.4"
190+
version: "0.7.3"
199191
vector_math:
200192
dependency: transitive
201193
description:
@@ -208,10 +200,10 @@ packages:
208200
dependency: transitive
209201
description:
210202
name: vm_service
211-
sha256: "0968250880a6c5fe7edc067ed0a13d4bae1577fe2771dcf3010d52c4a9d3ca14"
203+
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
212204
url: "https://pub.dev"
213205
source: hosted
214-
version: "14.3.1"
206+
version: "14.3.0"
215207
sdks:
216-
dart: ">=3.7.0-0 <4.0.0"
208+
dart: ">=3.4.0 <4.0.0"
217209
flutter: ">=3.18.0-18.0.pre.54"

example/web/index.html

Lines changed: 12 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,86 +18,23 @@
1818

1919
<meta charset="UTF-8">
2020
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
21-
<meta name="description" content="An Amplitude Flutter Web project.">
21+
<meta name="description" content="A new Flutter project.">
2222

23-
<!-- iOS meta tags -->
24-
<meta name="apple-mobile-web-app-capable" content="yes">
23+
<!-- iOS meta tags & icons -->
24+
<meta name="mobile-web-app-capable" content="yes">
2525
<meta name="apple-mobile-web-app-status-bar-style" content="black">
26-
<meta name="apple-mobile-web-app-title" content="amplitude-example">
26+
<meta name="apple-mobile-web-app-title" content="amplitude_flutter_example">
27+
<link rel="apple-touch-icon" href="icons/Icon-192.png">
2728

28-
<title>Amplitude Example</title>
29+
<!-- Favicon -->
30+
<link rel="icon" type="image/png" href="favicon.png"/>
31+
32+
<title>amplitude_flutter_example</title>
2933
</head>
3034
<body>
31-
32-
<script type="text/javascript">
33-
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})},i=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};o(e,t,Array.prototype.slice.call(arguments))}},a=function(e){for(var t=0;t<g.length;t++)i(e,g[t],!1);for(var r=0;r<m.length;r++)i(e,m[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-R0H1kXlk6r2aEQMtwVcPolpk0NAuIqM/8NlxAv24Gr3/PBJPl+9elu0bc3o/FDjR",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.11.10-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var l=t.getElementsByTagName("script")[0];l.parentNode.insertBefore(c,l);for(var u=function(){return this._q=[],this},p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<p.length;d++)n(u,p[d]);r.Identify=u;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<v.length;y++)n(f,v[y]);r.Revenue=f;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];a(r),r.createInstance=function(e){return r._iq[e]={_q:[]},a(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
34-
</script>
35-
<!-- This script installs service_worker.js to provide PWA functionality to
36-
application. For more information, see:
37-
https://developers.google.com/web/fundamentals/primers/service-workers -->
38-
<script>
39-
var serviceWorkerVersion = null;
40-
var scriptLoaded = false;
41-
function loadMainDartJs() {
42-
if (scriptLoaded) {
43-
return;
44-
}
45-
scriptLoaded = true;
46-
var scriptTag = document.createElement('script');
47-
scriptTag.src = 'main.dart.js';
48-
scriptTag.type = 'application/javascript';
49-
document.body.append(scriptTag);
50-
}
51-
52-
if ('serviceWorker' in navigator) {
53-
// Service workers are supported. Use them.
54-
window.addEventListener('load', function () {
55-
// Wait for registration to finish before dropping the <script> tag.
56-
// Otherwise, the browser will load the script multiple times,
57-
// potentially different versions.
58-
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
59-
navigator.serviceWorker.register(serviceWorkerUrl)
60-
.then((reg) => {
61-
function waitForActivation(serviceWorker) {
62-
serviceWorker.addEventListener('statechange', () => {
63-
if (serviceWorker.state == 'activated') {
64-
console.log('Installed new service worker.');
65-
loadMainDartJs();
66-
}
67-
});
68-
}
69-
if (!reg.active && (reg.installing || reg.waiting)) {
70-
// No active web worker and we have installed or are installing
71-
// one for the first time. Simply wait for it to activate.
72-
waitForActivation(reg.installing || reg.waiting);
73-
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
74-
// When the app updates the serviceWorkerVersion changes, so we
75-
// need to ask the service worker to update.
76-
console.log('New service worker available.');
77-
reg.update();
78-
waitForActivation(reg.installing);
79-
} else {
80-
// Existing service worker is still good.
81-
console.log('Loading app from service worker.');
82-
loadMainDartJs();
83-
}
84-
});
85-
86-
// If service worker doesn't succeed in a reasonable amount of time,
87-
// fallback to plaint <script> tag.
88-
setTimeout(() => {
89-
if (!scriptLoaded) {
90-
console.warn(
91-
'[Amplitude] Failed to load app from service worker. Falling back to plain <script> tag.',
92-
);
93-
loadMainDartJs();
94-
}
95-
}, 4000);
96-
});
97-
} else {
98-
// Service workers not supported. Just drop the <script> tag.
99-
loadMainDartJs();
100-
}
35+
<script src="flutter_bootstrap.js" async></script>
36+
<script type="text/javascript">
37+
!function(){"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:{}};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},o=function(e,t,r){e._q.push({name:t,args:Array.prototype.slice.call(r,0)})},i=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))};o(e,t,Array.prototype.slice.call(arguments))}},a=function(e){for(var t=0;t<g.length;t++)i(e,g[t],!1);for(var r=0;r<m.length;r++)i(e,m[r],!0)};r.invoked=!0;var c=t.createElement("script");c.type="text/javascript",c.integrity="sha384-R0H1kXlk6r2aEQMtwVcPolpk0NAuIqM/8NlxAv24Gr3/PBJPl+9elu0bc3o/FDjR",c.crossOrigin="anonymous",c.async=!0,c.src="https://cdn.amplitude.com/libs/analytics-browser-2.11.10-min.js.gz",c.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var l=t.getElementsByTagName("script")[0];l.parentNode.insertBefore(c,l);for(var u=function(){return this._q=[],this},p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<p.length;d++)n(u,p[d]);r.Identify=u;for(var f=function(){return this._q=[],this},v=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<v.length;y++)n(f,v[y]);r.Revenue=f;var g=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];a(r),r.createInstance=function(e){return r._iq[e]={_q:[]},a(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document)}();
10138
</script>
10239
</body>
10340
</html>

0 commit comments

Comments
 (0)