Skip to content

Federated plugin refactor #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,3 +7,5 @@
build/

.idea
*.iml
pubspec.lock
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions example/pubspec.lock → flutter_web_auth/example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -74,6 +74,13 @@ packages:
relative: true
source: path
version: "0.4.0"
flutter_web_auth_platform_interface:
dependency: "direct overridden"
description:
path: "../../flutter_web_auth_platform_interface"
relative: true
source: path
version: "0.1.0"
flutter_web_plugins:
dependency: transitive
description: flutter
@@ -107,6 +114,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
sky_engine:
dependency: transitive
description: flutter
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@ dev_dependencies:
flutter_web_auth:
path: ../

dependency_overrides:
flutter_web_auth_platform_interface:
path: ../../flutter_web_auth_platform_interface

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart' show MethodChannel;
import 'package:flutter_web_auth_platform_interface/flutter_web_auth_platform_interface.dart';

class _OnAppLifecycleResumeObserver extends WidgetsBindingObserver {
final Function onResumed;
@@ -17,8 +17,6 @@ class _OnAppLifecycleResumeObserver extends WidgetsBindingObserver {
}

class FlutterWebAuth {
static const MethodChannel _channel = const MethodChannel('flutter_web_auth');

static final _OnAppLifecycleResumeObserver _resumedObserver = _OnAppLifecycleResumeObserver(() {
_cleanUpDanglingCalls(); // unawaited
});
@@ -32,18 +30,15 @@ class FlutterWebAuth {
static Future<String> authenticate({required String url, required String callbackUrlScheme, bool? preferEphemeral}) async {
WidgetsBinding.instance?.removeObserver(_resumedObserver); // safety measure so we never add this observer twice
WidgetsBinding.instance?.addObserver(_resumedObserver);
return await _channel.invokeMethod('authenticate', <String, dynamic>{
'url': url,
'callbackUrlScheme': callbackUrlScheme,
'preferEphemeral': preferEphemeral ?? false,
}) as String;
return await FlutterWebAuthPlatformInterface.instance
.authenticate(url: url, callbackUrlScheme: callbackUrlScheme, preferEphemeral: preferEphemeral ?? false);
}

/// On Android, the plugin has to store the Result callbacks in order to pass the result back to the caller of
/// `authenticate`. But if that result never comes the callback will dangle around forever. This can be called to
/// terminate all `authenticate` calls with an error.
static Future<void> _cleanUpDanglingCalls() async {
await _channel.invokeMethod('cleanUpDanglingCalls');
await FlutterWebAuthPlatformInterface.instance.clearAllDanglingCalls();
WidgetsBinding.instance?.removeObserver(_resumedObserver);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions pubspec.yaml → flutter_web_auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ dependencies:
flutter_web_plugins:
sdk: flutter

flutter_web_auth_platform_interface: ^0.1.0

dev_dependencies:
flutter_test:
sdk: flutter
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
10 changes: 10 additions & 0 deletions flutter_web_auth_platform_interface/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 3595343e20a61ff16d14e8ecc25f364276bb1b8b
channel: stable

project_type: package
3 changes: 3 additions & 0 deletions flutter_web_auth_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release
3 changes: 3 additions & 0 deletions flutter_web_auth_platform_interface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# flutter_web_auth_platform_interface

A common platform interface for the `flutter web auth` plugin used by the different platform implementations.
4 changes: 4 additions & 0 deletions flutter_web_auth_platform_interface/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter_web_auth_platform_interface/method_channel_flutter_web_auth.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

/// The interface that implementations of FlutterWebAuth must implement.
///
/// Platform implementations should extend this class rather than implement it
/// because `implements` does not consider newly added methods to be breaking
/// changes. Extending this class (using `extends`) ensures that the subclass
/// will get the default implementation.
abstract class FlutterWebAuthPlatformInterface extends PlatformInterface {
FlutterWebAuthPlatformInterface() : super(token: _token);

static FlutterWebAuthPlatformInterface _instance = MethodChannelFlutterWebAuth();

static final Object _token = Object();

static FlutterWebAuthPlatformInterface get instance => _instance;

/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [UrlLauncherPlatform] when they register themselves.
static set instance(FlutterWebAuthPlatformInterface instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}

Future<String> authenticate({required String url, required String callbackUrlScheme, required bool preferEphemeral}) {
throw UnimplementedError('authenticate() has not been implemented.');
}

Future clearAllDanglingCalls() {
throw UnimplementedError('clearAllDanglingCalls() has not been implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/services.dart';
import 'package:flutter_web_auth_platform_interface/flutter_web_auth_platform_interface.dart';

const MethodChannel _kChannel = MethodChannel('flutter_web_auth');

/// Method channel implementation of the [WakelockPlatformInterface].
class MethodChannelFlutterWebAuth extends FlutterWebAuthPlatformInterface {
@override
Future<String> authenticate(
{required String url, required String callbackUrlScheme, required bool preferEphemeral}) async {
return await _kChannel.invokeMethod('authenticate', <String, dynamic>{
'url': url,
'callbackUrlScheme': callbackUrlScheme,
'preferEphemeral': preferEphemeral,
});
}

@override
Future clearAllDanglingCalls() async {
await _kChannel.invokeMethod('cleanUpDanglingCalls');
}
}
17 changes: 17 additions & 0 deletions flutter_web_auth_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: flutter_web_auth_platform_interface
description: A common platform interface for the flutter_web_auth plugin.
version: 0.1.0

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"

dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.0.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flutter_test/flutter_test.dart';

void main() {}
159 changes: 0 additions & 159 deletions pubspec.lock

This file was deleted.