Amplify Framework provides a declarative and easy-to-use

Amplify Flutter (Developer Preview)

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.

Amplify for Flutter is in developer preview and not yet recommended for production.

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

Supported Amplify Categories

  • Authentication: Create user authentication experiences with Amazon Cognito
[![](https://camo.githubusercontent.com/6c055052c649e774e5a8104fcca220a8aee6e763/68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f616d706c6966795f617574685f636f676e69746f2e737667)](https://pub.dev/packages/amplify_auth_cognito) 
  • Analytics: Collect analytics data with Amazon Pinpoint
[![](https://camo.githubusercontent.com/ee253903b2a5bca197a250b0befb440e01191813/68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f616d706c6966795f616e616c79746963735f70696e706f696e742e737667)](https://pub.dev/packages/amplify_analytics_pinpoint) 
  • Storage: Store user content with Amazon S3
[![](https://camo.githubusercontent.com/9177d516927542a842bc907f02537ddc3284c925/68747470733a2f2f696d672e736869656c64732e696f2f7075622f762f616d706c6966795f73746f726167655f73332e737667)](https://pub.dev/packages/amplify_storage_s3) 

To Be Implemented

  • [ ] API (REST/GraphQL)
  • [ ] Predictions
  • [ ] Datastore
  • [ ] Hub Events (Listening to the Amplify events)
  • [ ] iOS Error Events in Amplify Analytics

Amplify for Flutter is in preview, and is not recommended for production use at this time. During this phase, we are iterating on the code base, and looking for your feedback and collaboration. WE’D LOVE TO GET YOUR FEEDBACK! :-)..

Amplify for Flutter currently supports iOS and Android platforms.

Documentation

Flutter Development Guide

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

Prerequisites
Getting Started with Flutter app development and Amplify
  • Clone this repository
  • Install Amplify in a Flutter project
  • Add basic Amplify functionality to your project using one of the supported categories
  1. git clone git@github.com:aws-amplify/amplify-flutter.git

  2. 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.

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

See 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 helloAmplify
? Enter a name for the environment dev
? Choose your default editor: Visual Studio Code
? Choose the type of app that you\'re building flutter
Please tell us about your project
⚠️  Flutter project support in the Amplify CLI is in DEVELOPER PREVIEW status.
Only the following resource types are supported:
 * Auth
 * Analytics
 * Storage
? Where do you want to store your configuration file? ./lib/
  1. Add Amplify categories (choose defaults for this example):

    $ amplify add auth
    $ amplify add analytics
    
  2. 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:
  flutter:
    sdk: flutter
  amplify_core:
    path: /{path to your local amplify-flutter}/amplify-flutter/packages/amplify_core 
  amplify_analytics_pinpoint:
    path: /{path to your local amplify-flutter}/amplify-flutter/packages/amplify_analytics_pinpoint
  amplify_auth_cognito:
    path: /{path to your local amplify-flutter}/amplify-flutter/packages/amplify_auth_cognito
  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:flutter/material.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'amplifyconfiguration.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  bool _amplifyConfigured = false;

  // Instantiate Amplify
  Amplify amplifyInstance = new Amplify();

  @override
  void initState() {
    super.initState();
  }

  void _configureAmplify() async {
    if (!mounted) return;

    // Add Pinpoint and Cognito Plugins
    AmplifyAnalyticsPinpoint analyticsPlugin = AmplifyAnalyticsPinpoint();
    AmplifyAuthCognito authPlugin = AmplifyAuthCognito();
    amplifyInstance.addPlugin(authPlugins: [authPlugin]);
    amplifyInstance.addPlugin(analyticsPlugins: [analyticsPlugin]);

    // Once Plugins are added, configure Amplify
    await amplifyInstance.configure(amplifyconfig);
    try {
      setState(() {
        _amplifyConfigured = true;
      });
    } catch (e) {
      print(e);
    }

  }

  // Send an event to Pinpoint
  void _recordEvent() async {
    AnalyticsEvent event = AnalyticsEvent("test");
    event.properties.addBoolProperty("boolKey", true);
    event.properties.addDoubleProperty("doubleKey", 10.0);
    event.properties.addIntProperty("intKey", 10);
    event.properties.addStringProperty("stringKey", "stringValue");
    Amplify.Analytics.recordEvent(event: event);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Amplify Core example app'),
          ),
          body: ListView(padding: EdgeInsets.all(10.0), children: <Widget>[
            Center( 
              child: Column (
                children: [
                  const Padding(padding: EdgeInsets.all(5.0)),
                  RaisedButton(
                    onPressed: _amplifyConfigured ? null : _configureAmplify,
                    child: const Text('configure Amplify')
                  ),
                  RaisedButton(
                    onPressed: _amplifyConfigured ? _recordEvent : null,
                    child: const Text('record event')
                  )
                ]
              ),
            )
          ])
      )
    );
  }
}

For iOS builds complete the following steps (from the root of your project):

  • rm ios/Podfile
  • flutter build ios
  • Modify the ios/Podfile and replace the second line with: platform :ios, '11.0'.

This ensures that your Flutter project is running the same ios version that the Amplify plugins are built on.

  1. From the root of your project, execute flutter run in the terminal.

Make sure that an Android or iOS device is already running; this can be a virtual device started from Android Studio.

Click Configure Amplify, then Record Event. From the terminal (in the root of your project) 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.

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

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

Download Details:

Author: aws-amplify

Demo: https://docs.amplify.aws/

Source Code: https://github.com/aws-amplify/amplify-flutter

#flutter #dart #mobile-apps

Amplify Framework provides a declarative and easy-to-use
3.70 GEEK