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
8fce4ce9
Unverified
Commit
8fce4ce9
authored
Jun 23, 2020
by
David Iglesias
Committed by
GitHub
Jun 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Add web support through MethodChannels. (#60116)
parent
30d97d89
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
0 deletions
+85
-0
projectName_web.dart.tmpl
...tter_tools/templates/plugin/lib/projectName_web.dart.tmpl
+45
-0
pubspec.yaml.tmpl
packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl
+9
-0
create_test.dart
...tter_tools/test/commands.shard/permeable/create_test.dart
+31
-0
No files found.
packages/flutter_tools/templates/plugin/lib/projectName_web.dart.tmpl
0 → 100644
View file @
8fce4ce9
import 'dart:async';
// In order to *not* need this ignore, consider extracting the "web" version
// of your plugin as a separate package, instead of inlining it in the same
// package as the core of your plugin.
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html show window;
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
/// A web implementation of the {{pluginDartClass}} plugin.
class {{pluginDartClass}}Web {
static void registerWith(Registrar registrar) {
final MethodChannel channel = MethodChannel(
'{{projectName}}',
const StandardMethodCodec(),
registrar.messenger,
);
final pluginInstance = {{pluginDartClass}}Web();
channel.setMethodCallHandler(pluginInstance.handleMethodCall);
}
/// Handles method calls over the MethodChannel of this plugin.
/// Note: Check the "federated" architecture for a new way of doing this:
/// https://flutter.dev/go/federated-plugins
Future<dynamic> handleMethodCall(MethodCall call) async {
switch (call.method) {
case 'getPlatformVersion':
return getPlatformVersion();
break;
default:
throw PlatformException(
code: 'Unimplemented',
details: '{{projectName}} for web doesn\'t implement \'${call.method}\'',
);
}
}
/// Returns a [String] containing the version of the platform.
Future<String> getPlatformVersion() {
final version = html.window.navigator.userAgent;
return Future.value(version);
}
}
packages/flutter_tools/templates/plugin/pubspec.yaml.tmpl
View file @
8fce4ce9
...
...
@@ -11,6 +11,10 @@ environment:
dependencies:
flutter:
sdk: flutter
{{#web}}
flutter_web_plugins:
sdk: flutter
{{/web}}
dev_dependencies:
flutter_test:
...
...
@@ -40,6 +44,11 @@ flutter:
macos:
pluginClass: {{pluginClass}}
{{/macos}}
{{#web}}
web:
pluginClass: {{pluginDartClass}}Web
fileName: {{projectName}}_web.dart
{{/web}}
# To add assets to your plugin package, add an assets section, like this:
# assets:
...
...
packages/flutter_tools/test/commands.shard/permeable/create_test.dart
View file @
8fce4ce9
...
...
@@ -391,6 +391,9 @@ void main() {
'ios/Classes/FlutterProjectPlugin.m'
,
'lib/flutter_project.dart'
,
],
unexpectedPaths:
<
String
>[
'lib/flutter_project_web.dart'
,
],
);
return
_runFlutterTest
(
projectDir
.
childDirectory
(
'example'
));
},
overrides:
<
Type
,
Generator
>{
...
...
@@ -404,6 +407,34 @@ void main() {
),
});
testUsingContext
(
'plugin project supports web'
,
()
async
{
await
_createAndAnalyzeProject
(
projectDir
,
<
String
>[
'--template=plugin'
],
<
String
>[
'lib/flutter_project.dart'
,
'lib/flutter_project_web.dart'
,
],
);
final
String
rawPubspec
=
await
projectDir
.
childFile
(
'pubspec.yaml'
).
readAsString
();
final
Pubspec
pubspec
=
Pubspec
.
parse
(
rawPubspec
);
// Expect the dependency on flutter_web_plugins exists
expect
(
pubspec
.
dependencies
,
contains
(
'flutter_web_plugins'
));
// The platform is correctly registered
expect
(
pubspec
.
flutter
[
'plugin'
][
'platforms'
][
'web'
][
'pluginClass'
],
'FlutterProjectWeb'
);
expect
(
pubspec
.
flutter
[
'plugin'
][
'platforms'
][
'web'
][
'fileName'
],
'flutter_project_web.dart'
);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
),
Pub:
()
=>
Pub
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
processManager:
globals
.
processManager
,
usage:
globals
.
flutterUsage
,
botDetector:
globals
.
botDetector
,
platform:
globals
.
platform
,
),
});
testUsingContext
(
'plugin example app depends on plugin'
,
()
async
{
await
_createProject
(
projectDir
,
...
...
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