flutter_smartcar_auth 1.0.1 copy "flutter_smartcar_auth: ^1.0.1" to clipboard
flutter_smartcar_auth: ^1.0.1 copied to clipboard

SmartcarAuth for Flutter which integrates the native iOS & Android SDKs.

flutter_smartcar_auth #

A Flutter plugin for Smartcar Connect.

This plugin integrates the native SDKs:

Installation #

dart pub add flutter_smartcar_auth

Requirements #

1. Sign up for a Smartcar account #

Go to the developer dashboard to sign up with Smartcar.

2. Retrieve your API keys #

Once you have made your account, you will notice you already have an application with API keys.

3. Configure your Redirect URI #

Navigate to the Configuration section within the dashboard and add a redirect URI with the following format: “sc” + clientId + “://” + hostname.

Android #

Set the following constants in your app/src/main/res/values/strings.xml:

<resources>
    <string name="smartcar_auth_scheme">sc{YOUR_CLIENT_ID}</string>
    <string name="client_id">{YOUR_CLIENT_ID}</string>
    <string name="app_server">{YOUR_HOST}</string>
</resources>

Android applications use custom URI schemes to intercept calls and launch the relevant application. Add the following code snippet to your android/app/src/main/AndroidManifest.xml:

<activity android:name="com.smartcar.sdk.SmartcarCodeReceiver"
            android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="sc{YOUR_CLIENT_ID}"
            android:host="{YOUR_HOST}"/>
    </intent-filter>
</activity>

iOS #

The minimum iOS target version required is 11.

Usage #

Import package:flutter_smartcar_auth/flutter_smartcar_auth.dart and use the methods in Smartcar class.

Example:

import 'package:flutter/material.dart';
import 'package:flutter_smartcar_auth/flutter_smartcar_auth.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Smartcar.onSmartcarResponse.listen((event) {
      debugPrint(event.toString());
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Smartcar Auth',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Smartcar Auth'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              MaterialButton(
                onPressed: () async {
                  await Smartcar.setup(
                    configuration: const SmartcarConfig(
                      clientId: "{YOUR_CLIENT_ID}",
                      redirectUri: "sc{YOUR_CLIENT_ID}://{YOUR_HOST}",
                      scopes: [SmartcarPermission.readOdometer],
                      testMode: true,
                    ),
                  );
                },
                child: const Text("Setup"),
              ),
              MaterialButton(
                onPressed: () async {
                  await Smartcar.launchAuthFlow();
                },
                child: const Text("Launch Auth Flow"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

3
likes
0
points
608
downloads

Publisher

verified publishersmartcar.com

Weekly Downloads

SmartcarAuth for Flutter which integrates the native iOS & Android SDKs.

Repository
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_smartcar_auth