Skip to content

Commit

Permalink
feat: Refactor to work with flutter web (#79)
Browse files Browse the repository at this point in the history
* feat: Refactor to work with flutter web
  • Loading branch information
littleGnAl authored Sep 4, 2023
1 parent bfdaa63 commit bfbb3c8
Show file tree
Hide file tree
Showing 52 changed files with 2,796 additions and 1,744 deletions.
44 changes: 42 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ jobs:
run: flutter build apk
working-directory: example

build_web_ubuntu:
name: Build Web on Ubuntu
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }}
strategy:
matrix:
version: ['2.10.5', '3.0.0', '3.3.9', '3.7.3', '3.10.0']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.version }}
cache: true
- run: flutter pub get
- name: Run flutter build web
run: flutter build web
working-directory: example

run_flutter_unit_test:
name: Run flutter unit test
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }}
Expand All @@ -175,6 +196,25 @@ jobs:
- run: flutter packages get
- run: flutter test

run_flutter_unit_test_web:
name: Run flutter unit test web
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }}
strategy:
matrix:
version: ['2.10.5', '3.0.0', '3.3.9', '3.7.3', '3.10.0']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '11'
- uses: subosito/flutter-action@v1
with:
flutter-version: ${{ matrix.version }}
cache: true
- run: flutter packages get
- run: flutter test -d chrome

integration_test_windows:
name: windows integration test
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci:skip') }}
Expand All @@ -191,7 +231,7 @@ jobs:
- name: windows integration test
run: |
flutter packages get
flutter test integration_test
flutter test integration_test -d windows
working-directory: example

integration_test_ios:
Expand Down Expand Up @@ -234,7 +274,7 @@ jobs:
- name: run macos integration test
run: |
flutter packages get
flutter test integration_test/iris_event_smoke_test.dart
flutter test integration_test/iris_event_smoke_test.dart -d macos
working-directory: example

integration_test_android:
Expand Down
21 changes: 12 additions & 9 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled.

version:
revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
revision: 796c8ef79279f9c774545b3771238c3098dbefab
channel: stable

project_type: plugin
Expand All @@ -13,17 +13,20 @@ project_type: plugin
migration:
platforms:
- platform: root
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: android
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: ios
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: macos
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: web
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: windows
create_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
base_revision: fb57da5f945d02ef4f98dfd9409a72b7cce74268
Expand Down
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ migrate_working_dir/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
26 changes: 12 additions & 14 deletions example/integration_test/iris_event_smoke_test.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@

import 'dart:isolate';

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:iris_method_channel/iris_method_channel.dart';
import 'package:iris_method_channel/src/platform/io/iris_event_io.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('IrisEvent smoke test',
(tester) async {
await tester.pumpAndSettle();
testWidgets('IrisEvent smoke test', (tester) async {
await tester.pumpAndSettle();

IrisEvent irisEvent = IrisEvent();
irisEvent.initialize();
final testPort = ReceivePort();
irisEvent.registerEventHandler(testPort.sendPort);
irisEvent.unregisterEventHandler(testPort.sendPort);
irisEvent.onEventPtr;
irisEvent.dispose();
});
}
IrisEventIO irisEvent = IrisEventIO();
irisEvent.initialize();
final testPort = ReceivePort();
irisEvent.registerEventHandler(testPort.sendPort);
irisEvent.unregisterEventHandler(testPort.sendPort);
irisEvent.onEventPtr;
irisEvent.dispose();
});
}
59 changes: 48 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
import 'package:flutter/material.dart';
import 'package:iris_method_channel/iris_method_channel.dart';

void main() {
runApp(const MyApp());
}

class _FakePlatformBindingsDelegateInterface
implements PlatformBindingsDelegateInterface {
@override
int callApi(IrisMethodCall methodCall, IrisApiEngineHandle apiEnginePtr,
IrisApiParamHandle param) {
return 0;
}

@override
Future<CallApiResult> callApiAsync(IrisMethodCall methodCall,
IrisApiEngineHandle apiEnginePtr, IrisApiParamHandle param) async {
return CallApiResult(irisReturnCode: 0, data: {});
}

@override
CreateApiEngineResult createApiEngine(List<Object> args) {
return const CreateApiEngineResult(IrisApiEngineHandle(0));
}

@override
IrisEventHandlerHandle createIrisEventHandler(
IrisCEventHandlerHandle eventHandler) {
return const IrisEventHandlerHandle(0);
}

@override
void destroyIrisEventHandler(IrisEventHandlerHandle handler) {}

@override
void destroyNativeApiEngine(IrisApiEngineHandle apiEnginePtr) {}

@override
void initialize() {}
}

class _FakePlatformBindingsProvider extends PlatformBindingsProvider {
@override
PlatformBindingsDelegateInterface provideNativeBindingDelegate() {
return _FakePlatformBindingsDelegateInterface();
}
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

Expand All @@ -12,7 +55,7 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final String _platformVersion = 'Unknown';

@override
void initState() {
Expand All @@ -22,16 +65,10 @@ class _MyAppState extends State<MyApp> {

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion = '';

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;

setState(() {
_platformVersion = platformVersion;
});
IrisMethodChannel irisMethodChannel =
IrisMethodChannel(_FakePlatformBindingsProvider());
await irisMethodChannel.initilize([]);
await irisMethodChannel.dispose();
}

@override
Expand Down
Binary file added example/web/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="Demonstrates how to use the iris_method_channel plugin.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="iris_method_channel_example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>

<title>iris_method_channel_example</title>
<link rel="manifest" href="manifest.json">

<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
</head>
<body>
<script>
window.addEventListener('load', function(ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
});
</script>
</body>
</html>
35 changes: 35 additions & 0 deletions example/web/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "iris_method_channel_example",
"short_name": "iris_method_channel_example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "Demonstrates how to use the iris_method_channel plugin.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
{
"src": "icons/Icon-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
8 changes: 5 additions & 3 deletions lib/iris_method_channel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export 'src/bindings/native_iris_api_common_bindings.dart';
export 'src/iris_event.dart';
export 'src/iris_handles.dart';
export 'src/iris_method_channel.dart';
export 'src/native_bindings_delegate.dart';
export 'src/platform/iris_event_interface.dart';
export 'src/platform/iris_method_channel_interface.dart';
export 'src/platform/platform_bindings_delegate_interface.dart';
export 'src/platform/utils.dart';
export 'src/scoped_objects.dart';
3 changes: 3 additions & 0 deletions lib/iris_method_channel_bindings_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Export the common bindings of iris of `dart:io`
export 'src/platform/io/bindings/native_iris_api_common_bindings.dart';
3 changes: 3 additions & 0 deletions lib/iris_method_channel_bindings_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// Export the common bindings of iris of web
export 'src/platform/web/bindings/iris_api_common_bindings_js.dart';
17 changes: 17 additions & 0 deletions lib/iris_method_channel_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 'package:flutter_web_plugins/flutter_web_plugins.dart';

/// A web implementation of the IrisMethodChannelPlatform of the IrisMethodChannel plugin.
class IrisMethodChannelWeb {
/// Constructs a IrisMethodChannelWeb
IrisMethodChannelWeb();

// ignore: public_member_api_docs
static void registerWith(Registrar registrar) {
// do nothing
}
}
Loading

0 comments on commit bfbb3c8

Please sign in to comment.