Skip to content

aws-amplify/amplify-flutter

AWS Amplify

discord

Amplify Flutter

AWS Amplify provides a declarative and easy-to-use interface across different categories of cloud operations. Our default implementation works with Amazon Web Services (AWS), but AWS Amplify is designed to be open and pluggable for any custom backend or service. See AWS Amplify for further details about the Amplify Framework.

We are iterating and looking for feedback and collaboration, so please let us know your feedback on our direction and roadmap.

Getting Started Guide

⚠️ Amplify Flutter v0 is now in Maintenance Mode until July 19th, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v0.

Please use the latest version (v1) of Amplify Flutter. If you are currently using v0, follow these instructions to upgrade to v1.

Supported Amplify Libraries

Library pub.dev package Description
Authentication APIs and building blocks for developers who want to create user authentication experiences with Amazon Cognito.
Analytics Easily collect analytics data for your app with Pinpoint. Analytics data includes user sessions and other custom events that you want to track in your app.
Storage Provides a simple mechanism for managing user content for your app in public, protected or private storage buckets with Amazon S3.
DataStore A programming model for leveraging shared and distributed data without writing additional code for offline and online scenarios, which makes working with distributed, cross-user data just as simple as working with local-only data.
API (REST) Provides a simple solution when making HTTP requests. It provides an automatic, lightweight signing process which complies with AWS Signature Version 4.
API (GraphQL) Interact with your GraphQL server or AWS AppSync API with an easy-to-use & configured GraphQL client.
Notifications Trigger push notifications to your app and record metrics in Pinpoint when users receive or open notifications.
Authenticator The Amplify Flutter Authenticator simplifies the process of authenticating users by providing a fully-customizable flow which just works. Simply wrap your app's authenticated route in an Authenticator component and the process of authenticating users and managing login sessions is handled for you.

Semantic versioning

We follow semantic versioning for our releases.

Semantic versioning and enumeration cases

When Amplify adds a new enumeration entry or sealed class subtype, we will publish a new minor version of the library.

Applications that use a switch statement to evaluate all members of an enumerated type can add a default clause to prevent new cases from causing compile warnings or errors.

Semantic versioning and dependencies update

We follow semantic versioning for updating our dependencies. This includes updating the dart and flutter SDK version.

Category / Platform Support

Category Android iOS Web Windows MacOS Linux
Analytics
API (REST)
API (GraphQL)
Authentication
DataStore 🔴 🔴 🔴 🔴
Storage
Notifications 🔴 🔴 🔴 🔴

Documentation

Flutter Development Guide

Amplify for Flutter is an open-source project and welcomes contributions from the Flutter community, see Contributing.

Prerequisites

Getting Started Amplify Flutter

  1. Open your Flutter project. If you do not have an active Flutter project, you can create one after installing the Flutter development tooling and running flutter create <project-name> in your terminal.

  2. Using the Amplify CLI, run amplify init from the root of your project:

If you have not configured the Amplify CLI, check out our documentation at Amplify CLI Installation.

==> amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project <project-name>
The following configuration will be applied:

Project information
| Name: <project-name>
| Environment: dev
| Default editor: Visual Studio Code
| App type: flutter
| Configuration file location: ./lib/

? Initialize the project with the above configuration? Yes
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default
  1. Add Amplify categories (choose defaults for this example):

    $ amplify add auth  # Choose default configuration after entering this command in your terminal.
  2. Push changes to the cloud to provision the backend resources:

    $ amplify push
  3. In your pubspec.yaml file, add the following to dependencies:

Note: Do not include dependencies in your pubspec file that you are not using in your app. This can cause a configuration error in the underlying SDK.

dependencies:
  amplify_auth_cognito: ^1.0.0
  amplify_authenticator: ^1.0.0
  amplify_flutter: ^1.0.0
  flutter:
    sdk: flutter
  1. From the terminal run
flutter pub get
  1. In your main.dart file, add:
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';

import 'amplifyconfiguration.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();
    _configureAmplify();
  }

  Future<void> _configureAmplify() async {
    try {
      await Amplify.addPlugin(AmplifyAuthCognito());
      await Amplify.configure(amplifyconfig);
      safePrint('Successfully configured');
    } on Exception catch (e) {
      safePrint('Error configuring Amplify: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Authenticator(
      child: MaterialApp(
        builder: Authenticator.builder(),
        home: const Scaffold(
          body: Center(
            child: Text('You are logged in!'),
          ),
        ),
      ),
    );
  }
}
  1. Since Amplify Flutter supports 6 platforms with Flutter including iOS, Android, Web, and Desktop, some extra configuration may be required for each platform. Check out the Platform Setup guide to make sure you've completed the necessary steps.

  2. Run flutter run to launch your app on the connected device.

  3. Once the app is loaded, tap on Configure Amplify, then on Record Event a few times.

  4. To see the events you recoded, run amplify console analytics. This will open the Amazon Pinpoint console for your project in your default web browser. Within about a minute you should start seeing the events populating in the Events section of then Pinpoint console.

Congratulations, you've built your first Amplify app! 🎉

For further documentation and Amplify Category usage, see the documentation.


Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.