login_with_amazon 0.2.0 copy "login_with_amazon: ^0.2.0" to clipboard
login_with_amazon: ^0.2.0 copied to clipboard

outdated

A flutter plugin built to use Amazon's official Login With Amazon platform packages. With few other dependencies.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:login_with_amazon/login_with_amazon.dart';

void main() => runApp(MyApp());

/// @nodoc
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

const _scopes = {
  'profile': null,
  'alexa:all': {
    'productID': 'SomeProductId',
    'productInstanceAttributes': {
      'deviceSerialNumber': 'serialNumberHere',
    },
  },
  'dash:replenish': {
    'device_model': 'SomeDeviceModel',
    'serial': 'serialNumberHere',
    'is_test_device': true
  },
};

/// @nodoc
class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  List<Widget> _authRespose = [];
  String _accessToken = '';
  String _authCode = '';
  String _logResult = '';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              RaisedButton(
                onPressed: () async {
                  try {
                    final result = await LoginWithAmazon.login(_scopes);
                    setState(() {
                      _logResult = result.containsKey("accessToken")
                          ? "Logged In"
                          : "Cancelled";
                      _authRespose = result.entries.map((entry) {
                        return Text("${entry.key}: ${entry.value}");
                      }).toList();
                    });
                  } catch (e) {
                    setState(() {
                      _logResult = "Cancelled";
                    });
                  }
                },
                child: Text("Login"),
              ),
              RaisedButton(
                onPressed: () async {
                  final result = await LoginWithAmazon.getAuthCode(
                    "code_generated_by_the_dash_device_for_LWA_verification",
                    {
                      'profile': null,
                      'dash:replenish': {
                        'device_model': 'SomeDeviceModel',
                        'serial': 'serialNumberHere',
                        'is_test_device': true
                      },
                    },
                  );
                  setState(() {
                    _authCode = result.containsKey("authorizationCode")
                        ? result["authorizationCode"]
                        : "None";
                    _authRespose = result.entries.map((entry) {
                      return Text("${entry.key}: ${entry.value}");
                    }).toList();
                  });
                },
                child: Text("Get Auth Code"),
              ),
              RaisedButton(
                onPressed: () async {
                  final result = await LoginWithAmazon.getAccessToken(_scopes);
                  setState(() {
                    _accessToken = result;
                  });
                },
                child: Text("Get Access Token"),
              ),
              RaisedButton(
                onPressed: () async {
                  await LoginWithAmazon.logout();
                  setState(() {
                    _logResult = 'Logged Out';
                  });
                },
                child: Text("Logout"),
              ),
              Text('LogResult: $_logResult'),
              Text('AccessToken: $_accessToken'),
              Text('AuthCode: $_authCode'),
              ..._authRespose
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
0
pub points
0%
popularity

Publisher

verified publisherweplenish.com

A flutter plugin built to use Amazon's official Login With Amazon platform packages. With few other dependencies.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on login_with_amazon