Closed walsha2 closed 1 year ago
What exactly do you want to achieve with this? the file openid_client_browser.dart
is only intended to be used in a browser environment.
If you want to use it in a flutter application for both web and other platforms you should use conditional imports.
What exactly do you want to achieve with this? the file
openid_client_browser.dart
is only intended to be used in a browser environment.
Yes, the resulting application (in my fork) uses the following logic:
import 'package:openid_client/openid_client_browser.dart' as oidc_browser;
import 'package:openid_client/openid_client_io.dart' as oidc_io;
Then later on:
if (kIsWeb) {
// Do something with oidc_browser
}
else {
// Do something with oidc_io
}
This is only possible with the use of universal_html
which removes the need to have conditional imports and allows for cross-platform imports like this without breaking desktop/web.
If you want to use it in a flutter application for both web and other platforms you should use conditional imports.
Conditional imports will not work in this repo. There is no implemented stub for Authenticator
. Since there is no stub
the Authenticator
class is not recognized so something like the following will not work:
import 'package:openid_client/openid_client.dart'
if (dart.library.js) 'package:openid_client/openid_client_browser.dart'
if (dart.library.io) 'package:openid_client/openid_client_io.dart';
In summary, universal_html
is a drop in replacement that removes the need for conditional imports and solves this problem. Have been using this solution in my fork with zero issues in a cross-platform app. The use of html
in openid_client
is very light and using universal_html
works great to resolve the issue stated above.
Unless you want to implement an Authenticator stub.
@Rb
No, you should implement your own stub for whatever you want to do and a browser and non-browser version that respectively imports the openid_client_browser.dart and openid_client_io.dart file.
Use of
universal_html
instead ofdart:html
in order to allow forFlutter
applications that are intended to run on multiple targets, e.g. Desktop and Web.Otherwise, the web related imports will cause errors during the flutter build for non-web platforms indicating the
html
related packages are not allowed to be used on those targets. Sincedart
does not support conditional imports, theuniversal_html
package gets around this limitation and is intended for this type of use case.https://pub.dev/packages/universal_html
This PR also relaxes the
http
package requirements to support the later versions which are still backwards compatible.