Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
p-mazhnik
2023-02-03 14:35:34 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5e85a5c1ad3949d43d80207ed8db050f0e0890e0
5e85a5c1
1 parent
9e4e9a16
fix(web): fix loading js scripts in debug mode in flutter 3.7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
31 deletions
lib/src/web/utils.dart
lib/src/web/utils.dart
View file @
5e85a5c
import
'dart:async'
;
import
'dart:html'
as
html
;
import
'dart:js'
show
context
;
import
'dart:js'
show
context
,
JsObject
;
import
'package:js/js.dart'
;
import
'package:mobile_scanner/src/web/base.dart'
;
Future
<
void
>
loadScript
(
JsLibrary
library
)
async
{
dynamic
amd
;
dynamic
define
;
// ignore: avoid_dynamic_calls
if
(
library
.
usesRequireJs
&&
context
[
'define'
]?[
'amd'
]
!=
null
)
{
// In dev, requireJs is loaded in. Disable it here.
// see https://github.com/dart-lang/sdk/issues/33979
return
loadScriptUsingRequireJS
(
library
.
contextName
,
library
.
url
);
}
else
{
return
loadScriptUsingScriptTag
(
library
.
url
);
define
=
JsObject
.
fromBrowserObject
(
context
[
'define'
]
as
Object
);
// ignore: avoid_dynamic_calls
amd
=
define
[
'amd'
];
// ignore: avoid_dynamic_calls
define
[
'amd'
]
=
false
;
}
try
{
await
loadScriptUsingScriptTag
(
library
.
url
);
}
finally
{
if
(
amd
!=
null
)
{
// Re-enable requireJs
// ignore: avoid_dynamic_calls
define
[
'amd'
]
=
amd
;
}
}
}
...
...
@@ -29,32 +42,6 @@ Future<void> loadScriptUsingScriptTag(String url) {
return
script
.
onLoad
.
first
;
}
Future
<
void
>
loadScriptUsingRequireJS
(
String
packageName
,
String
url
)
{
final
Completer
completer
=
Completer
();
final
String
eventName
=
'_
${packageName}
Loaded'
;
context
.
callMethod
(
'addEventListener'
,
[
eventName
,
allowInterop
((
_
)
=>
completer
.
complete
())],
);
final
script
=
html
.
ScriptElement
()
..
type
=
'text/javascript'
..
async
=
false
..
defer
=
false
..
text
=
'''
require(["
$url
"], (package) => {
window.
$packageName
= package;
const event = new Event("
$eventName
");
dispatchEvent(event);
})
'''
;
html
.
document
.
head
!.
append
(
script
);
return
completer
.
future
;
}
/// Injects JS [libraries]
///
/// Returns a [Future] that resolves when all of the `script` tags `onLoad` events trigger.
...
...
Please
register
or
login
to post a comment