Skip to content

Commit

Permalink
Merge pull request #9 from anthonychwong/feature/#8-null-safety
Browse files Browse the repository at this point in the history
Feature/#8 null safety
  • Loading branch information
anthonychwong authored Jul 4, 2021
2 parents 28026e7 + f21333d commit d81048b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [0.0.1-alpha.6] - 2021-07-04

## Changed

- minimum dart SDK version from `2.7.0` to `2.12.0` for null safety
- drop deprecated `RaisedButton` and switch to`ElevatedButton`

# [0.0.1-alpha.5] - 2021-05-05

## Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A wrapper for Auth0 SPA SDK to use Auth0 in Flutter Web.

> ⚠ The latest is [`0.0.1-alpha.5`](https://pub.dev/packages/auth0_flutter_web/versions/0.0.1-alpha.5) but not serve by `pub.dev` by default.
> ⚠ The latest is [`0.0.1-alpha.6`](https://pub.dev/packages/auth0_flutter_web/versions/0.0.1-alpha.6) but not serve by `pub.dev` by default.
[![](https://img.shields.io/pub/v/auth0_flutter_web)](https://pub.dev/packages/auth0_flutter_web)

Expand Down
12 changes: 6 additions & 6 deletions auth0_flutter_web/lib/src/auth0_js_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ class Auth0 {

Auth0._(this._auth0js);

Future<void> loginWithPopup({PopupLoginOptions options = null, PopupConfigOptions config = null}) {
Future<void> loginWithPopup({PopupLoginOptions? options = null, PopupConfigOptions? config = null}) {
return promiseToFuture(_auth0js.loginWithPopup(options ?? jsify({}), config ?? jsify({})));
}

void logout({LogoutOptions options = null}) => _auth0js.logout(options ?? jsify({}));
void logout({LogoutOptions? options = null}) => _auth0js.logout(options ?? jsify({}));

Future<String> getTokenWithPopup({GetTokenWithPopupOptions options = null, PopupConfigOptions config = null}){
Future<String> getTokenWithPopup({GetTokenWithPopupOptions? options = null,PopupConfigOptions? config = null}) {
return promiseToFuture(_auth0js.getTokenWithPopup(options ?? jsify({}), config ?? jsify({})));
}

Future<String> getTokenSilently({GetTokenSilentlyOptions options = null}){
Future<String> getTokenSilently({GetTokenSilentlyOptions? options = null}) {
return promiseToFuture(_auth0js.getTokenSilently(options ?? jsify({})));
}

Future<Map<String, dynamic>> getUser({GetUserOptions options = null}) => promiseToFutureAsMap(_auth0js.getUser(options ?? jsify({})));
Future<Map<String, dynamic>> getIdTokenClaims({GetIdTokenClaimsOptions options = null}) => promiseToFutureAsMap(_auth0js.getIdTokenClaims(options ?? jsify({})));
Future<Map<String, dynamic>?> getUser({GetUserOptions? options = null}) => promiseToFutureAsMap(_auth0js.getUser(options ?? jsify({})));
Future<Map<String, dynamic>?> getIdTokenClaims({GetIdTokenClaimsOptions? options = null}) => promiseToFutureAsMap(_auth0js.getIdTokenClaims(options ?? jsify({})));

Future<bool> isAuthenticated() => promiseToFuture(_auth0js.isAuthenticated());
}
18 changes: 9 additions & 9 deletions auth0_flutter_web/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BaseLoginOptions {
external String get acr_values;
external String get scope;
external String get audience;
external String get connection;
external String? get connection;

external factory BaseLoginOptions({
String display,
Expand All @@ -28,17 +28,17 @@ class BaseLoginOptions {
String acr_values,
String scope,
String audience,
String connection
String? connection
});
}

@JS()
@anonymous
class AdvancedOptions {
external String get defaultScope;
external String? get defaultScope;

external factory AdvancedOptions({
String defaultScope
String? defaultScope
});
}

Expand Down Expand Up @@ -68,7 +68,7 @@ class Auth0ClientOptions extends BaseLoginOptions {
String acr_values,
String scope,
String audience,
String connection,
String? connection,
@required String domain,
String issuer,
@required String client_id,
Expand Down Expand Up @@ -97,7 +97,7 @@ class PopupLoginOptions extends BaseLoginOptions{
String acr_values,
String scope,
String audience,
String connection
String? connection
});
}

Expand All @@ -114,7 +114,7 @@ class GetTokenWithPopupOptions extends PopupLoginOptions {
String acr_values,
String scope,
String audience,
String connection
String? connection
});
}

Expand All @@ -140,13 +140,13 @@ class GetTokenSilentlyOptions {
@anonymous
class LogoutOptions {
external String get returnTo;
external String get client_id;
external String? get client_id;
external bool get federated;
external bool get localOnly;

external factory LogoutOptions({
String returnTo,
String client_id,
String? client_id,
bool federated,
bool localOnly,
});
Expand Down
4 changes: 2 additions & 2 deletions auth0_flutter_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: auth0_flutter_web
version: 0.0.1-alpha.5
version: 0.0.1-alpha.6
description: Wrapper of Auth0 SPA SDK for Flutter Web
homepage: https://anthonychwong.netlify.app/
repository: https://github.com/anthonychwong/auth0-flutter-web

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
js: ^0.6.2
Expand Down
24 changes: 12 additions & 12 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:auth0_flutter_web/auth0_flutter_web.dart';

Auth0 auth0;
late Auth0 auth0;

void main() async {
auth0 = await createAuth0Client(
Expand All @@ -27,18 +27,18 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, this.title}) : super(key: key);

final String title;
final String? title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
bool _loggedIn = false;
String _name = "";
String _avatarUrl = "";
String? _name = "";
String? _avatarUrl = "";

@override
void initState() {
Expand All @@ -53,9 +53,9 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() => _loggedIn = false);
} else {
auth0.getUser()
.then((Map<String, dynamic> user) => setState((){
.then((Map<String, dynamic>? user) => setState((){
_loggedIn = true;
_name = user["name"];
_name = user!["name"];
_avatarUrl = user["picture"];
}));
}
Expand All @@ -65,7 +65,7 @@ class _MyHomePageState extends State<MyHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
title: Text(widget.title!),
),
body: Center(
child: Column(
Expand All @@ -74,9 +74,9 @@ class _MyHomePageState extends State<MyHomePage> {
_loggedIn ?
Column(
children:[
Image.network(_avatarUrl),
Text(_name),
RaisedButton(
Image.network(_avatarUrl!),
Text(_name!),
ElevatedButton(
child: Text('Logout'),
onPressed: () async {
auth0.logout();
Expand All @@ -86,7 +86,7 @@ class _MyHomePageState extends State<MyHomePage> {
},)
]
):
RaisedButton(child: Text('Login'),onPressed: () async {
ElevatedButton(child: Text('Login'),onPressed: () async {
await auth0.loginWithPopup(options: PopupLoginOptions(scope: "email"));
_onAuthenticationChanged(await auth0.isAuthenticated());
},),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down

0 comments on commit d81048b

Please sign in to comment.