Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4d3b51e2
Unverified
Commit
4d3b51e2
authored
May 09, 2019
by
Jonah Williams
Committed by
GitHub
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow flutter web to be compiled with flutter (#32360)
parent
e8c5c981
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
9 deletions
+54
-9
main_web.dart
examples/flutter_gallery/lib/main_web.dart
+16
-0
index.html
examples/flutter_gallery/web/index.html
+12
-0
platform.dart
packages/flutter/lib/src/foundation/platform.dart
+12
-6
web_device.dart
packages/flutter_tools/lib/src/web/web_device.dart
+14
-3
No files found.
examples/flutter_gallery/lib/main_web.dart
0 → 100644
View file @
4d3b51e2
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Thanks for checking out Flutter!
// Like what you see? Tweet us @FlutterDev
import
'dart:ui'
as
ui
;
import
'package:flutter/material.dart'
;
import
'gallery/app.dart'
;
Future
<
void
>
main
()
async
{
await
ui
.
webOnlyInitializePlatform
();
// ignore: undefined_function
runApp
(
const
GalleryApp
());
}
examples/flutter_gallery/web/index.html
0 → 100644
View file @
4d3b51e2
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!DOCTYPE html>
<html>
<head>
<title>
Flutter Gallery
</title>
</head>
<body>
<script
src=
"main.dart.js"
></script>
</body>
</html>
\ No newline at end of file
packages/flutter/lib/src/foundation/platform.dart
View file @
4d3b51e2
...
...
@@ -49,16 +49,22 @@ enum TargetPlatform {
// and we'd never be able to introduce dedicated behavior for that platform
// (since doing so would be a big breaking change).
TargetPlatform
get
defaultTargetPlatform
{
// TODO(jonahwilliams): consider where this constant should live.
const
bool
kIsWeb
=
identical
(
1
,
1.0
);
TargetPlatform
result
;
if
(
Platform
.
isIOS
)
{
result
=
TargetPlatform
.
iOS
;
}
else
if
(
Platform
.
isAndroid
)
{
if
(
kIsWeb
)
{
result
=
TargetPlatform
.
android
;
}
else
if
(
Platform
.
isFuchsia
)
{
result
=
TargetPlatform
.
fuchsia
;
}
else
{
if
(
Platform
.
isIOS
)
{
result
=
TargetPlatform
.
iOS
;
}
else
if
(
Platform
.
isAndroid
)
{
result
=
TargetPlatform
.
android
;
}
else
if
(
Platform
.
isFuchsia
)
{
result
=
TargetPlatform
.
fuchsia
;
}
}
assert
(()
{
if
(
Platform
.
environment
.
containsKey
(
'FLUTTER_TEST'
))
if
(
!
kIsWeb
&&
Platform
.
environment
.
containsKey
(
'FLUTTER_TEST'
))
result
=
TargetPlatform
.
android
;
return
true
;
}());
...
...
packages/flutter_tools/lib/src/web/web_device.dart
View file @
4d3b51e2
...
...
@@ -3,6 +3,8 @@
// found in the LICENSE file.
import
'../application_package.dart'
;
import
'../asset.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
...
...
@@ -10,6 +12,7 @@ import '../base/logger.dart';
import
'../base/platform.dart'
;
import
'../base/process_manager.dart'
;
import
'../build_info.dart'
;
import
'../bundle.dart'
;
import
'../device.dart'
;
import
'../globals.dart'
;
import
'../project.dart'
;
...
...
@@ -111,6 +114,13 @@ class WebDevice extends Device {
printError
(
'Failed to compile
${package.name}
to JavaScript'
);
return
LaunchResult
.
failed
();
}
final
AssetBundle
assetBundle
=
AssetBundleFactory
.
instance
.
createBundle
();
final
int
build
=
await
assetBundle
.
build
();
if
(
build
!=
0
)
{
throwToolExit
(
'Error: Failed to build asset bundle'
);
}
await
writeBundle
(
fs
.
directory
(
getAssetBuildDirectory
()),
assetBundle
.
entries
);
_package
=
package
;
_server
=
await
HttpServer
.
bind
(
InternetAddress
.
loopbackIPv4
,
0
);
_server
.
listen
(
_basicAssetServer
);
...
...
@@ -141,7 +151,7 @@ class WebDevice extends Device {
await
request
.
response
.
close
();
return
;
}
// Resolve all get requests to the build/web/
asset
directory.
// Resolve all get requests to the build/web/
or build/flutter_assets
directory.
final
Uri
uri
=
request
.
uri
;
File
file
;
String
contentType
;
...
...
@@ -152,8 +162,9 @@ class WebDevice extends Device {
file
=
fs
.
file
(
fs
.
path
.
join
(
getWebBuildDirectory
(),
'main.dart.js'
));
contentType
=
'text/javascript'
;
}
else
{
file
=
fs
.
file
(
fs
.
path
.
join
(
getAssetBuildDirectory
(),
uri
.
path
));
file
=
fs
.
file
(
fs
.
path
.
join
(
getAssetBuildDirectory
(),
uri
.
path
.
replaceFirst
(
'/assets/'
,
''
)
));
}
if
(!
file
.
existsSync
())
{
request
.
response
.
statusCode
=
HttpStatus
.
notFound
;
await
request
.
response
.
close
();
...
...
@@ -201,7 +212,7 @@ class ChromeLauncher {
Future
<
void
>
launch
(
String
host
)
async
{
if
(
platform
.
isMacOS
)
{
await
processManager
.
start
(<
String
>[
return
processManager
.
start
(<
String
>[
_kMacosLocation
,
host
,
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment