flutter_lwa 2.1.0 copy "flutter_lwa: ^2.1.0" to clipboard
flutter_lwa: ^2.1.0 copied to clipboard

Login with Amazon Flutter plugin. Call Amazon APIs from your Flutter application.

flutter_lwa #

pub package Build Status Coverage Status

A Flutter plugin for using Login with Amazon on Android and iOS.

Installation #

In addition to adding a pubspec dependency, this plugin requires Login with Amazon setup which requires modification of the native Android and iOS code of your flutter application.

Add a dependency to your pubspec.yml file #

See the installation instructions on pub.

Login with Amazon #

Register for Login with Amazon access and create API keys for Android and iOS as described in the documentation.

Android #

  1. Create a Login with Amazon API key for Android.

  2. Create a text file located at {project_root}/android/app/src/main/assets/api_key.txt

  3. Copy-paste the contents of the API key from the Login with Amazon console into the file {project_root}/android/app/src/main/assets/api_key.txt

Done!

iOS #

  1. Create a Login with Amazon API key for iOS.

  2. Add the APIKey key to the iOS properties file located at {project_root}/ios/Runner/Info.plist. The {api_key} should be the API key copy-pasted from the Login with Amazon console.

	<key>APIKey</key>
	<string>{api_key}</string>
  1. Add the CFBundleURLTypes key to the iOS properties file located at {project_root}/ios/Runner/Info.plist. The {bundle_id} should be the bundle identifier of your application. (Example of a bundle id: com.github.ayvazj.example)
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLName</key>
			<string>{bundle_id}</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>amzn-{bundle_id}</string>
			</array>
		</dict>
	</array>
  1. Update {project_root}/ios/Runner/AppDelegate.m to add the #import <LoginWithAmazon/LoginWithAmazon.h> import statement as well as the (BOOL)application:(UIApplication *)application openURL:(NSURL *) url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options method.

#import <LoginWithAmazon/LoginWithAmazon.h>

@implementation AppDelegate

...

- (BOOL)application:(UIApplication *)application openURL:(NSURL *) url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    
    return [AMZNAuthorizationManager handleOpenURL:url
                                 sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
}

...

@end

A sample of a complete Info.plist file can be found here.

Done!

How do I use it? #

The plugin follows the same patterns as the Google Signin API to make integration simple. For a complete sample see the example application.

import 'package:flutter_lwa/lwa.dart';

LoginWithAmazon _loginWithAmazon = LoginWithAmazon(
  scopes: <Scope>[ProfileScope.profile(), ProfileScope.postalCode()],
);

class _MyAppState extends State<MyApp> {
  LwaAuthorizeResult _lwaAuth;

  @override
  void initState() {
    super.initState();
    _loginWithAmazon.onLwaAuthorizeChanged.listen((LwaAuthorizeResult auth) {
      setState(() {
        _lwaAuth = auth;
      });
    });
    _loginWithAmazon.signInSilently();
  }

  Future<void> _handleSignIn(BuildContext context) async {
    try {
      await _loginWithAmazon.signin();
    } catch (error) {
      if (error is PlatformException) {
        Scaffold.of(context).showSnackBar(SnackBar(
          content: Text("${error.message}"),
        ));
      } else {
        Scaffold.of(context).showSnackBar(SnackBar(
          content: Text(error.toString()),
        ));
      }
    }
  }

  Future<void> _handleSignOut() => _loginWithAmazon.signOut();
}

4
likes
130
pub points
83%
popularity

Publisher

unverified uploader

Login with Amazon Flutter plugin. Call Amazon APIs from your Flutter application.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, flutter_lwa_platform_interface, logging, matcher

More

Packages that depend on flutter_lwa