otpless_flutter_web 0.0.3 otpless_flutter_web: ^0.0.3 copied to clipboard
Otpless Flutter Web support
This package supports the otpless_flutter web support. For more info please Visit OTPless
otpless_flutter_web #
Installation #
In your web
folder, add the custom.js file and add this code:
const OtplessLoginPageVisibility = (visibility) => {
const OtplessLoginPage = document.getElementById("otpless-login-page");
OtplessLoginPage.style.display = visibility;
};
const SetOtplessCallback = () => {
window.otpless = (otplessUser) => {
console.log(`SetOtplessCallback-${JSON.stringify(otplessUser)}`);
window.callDartFunction(JSON.stringify(otplessUser));
OtplessLoginPageVisibility("none");
};
};
function openLoginPage() {
SetOtplessCallback();
const script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://otpless.com/auth.js";
document.head.appendChild(script);
}
const OtplessLoginPageInit = () => {
const getURLParameter = (paramName, URLString = window.location.href) => {
const regex = new RegExp("[\\?&]" + paramName + "=([^&#]*)");
const results = regex.exec(URLString);
if (results && results.length > 0) {
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
return "";
};
if (getURLParameter("code")) {
console.log(window.location.href);
openLoginPage("ef0kpz5g");
}
};
OtplessLoginPageInit();
In your index.html
file, add the following code:
<div id="otpless-login-page">
<script src="custom.js"></script>
<script defer src="main.dart.js"></script>
</div>
In your pubspec.yaml
file, add the following dependency:
dependencies:
otpless_flutter_web: ^0.0.3
In your SignIn/SignUp
dart file, add the following code:
import 'package:otpless_flutter_web/otpless_flutter_web.dart';
final _otplessFlutterPlugin = Otpless();
//To you on tap function
_otplessFlutterPlugin.openLoginPage();