amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

[RFC]: Amplify Flutter

Open Amplifiyer opened this issue 6 years ago • 73 comments

This issue is a Request For Comments (RFC). It is intended to elicit community feedback regarding support for Amplify library in Flutter platform. Please feel free to post comments or questions here.

Purpose

Currently there is no official support for integrating with Amplify libraries in Flutter apps. This RFC goes over a proposal to build and release Amplify libraries in pub.dev that can be used in cross platform flutter apps.

Goals

  • Amplify iOS and Amplify Android parity: We would like to support all the use cases supported by these platforms in Amplify Flutter, including the following categories
    • Analytics
    • API (Rest/GraphQL)
    • Authentication (including Hosted UI)
    • DataStore
    • Predictions
    • Storage
    • Hub Events (Listening to the Amplify events)
  • Consistency with other platforms: Keep the public interface and API behavior consistent with Amplify iOS and Android libraries.
  • Pluggability: Customers should be able to implement/add their own cloud provider plugins for a given category.
  • UI Components: Provide a set of UI components intended to help developers leverage Amplify categories such as API, Auth, Storage etc.

Definitions

Categories: Use case driven abstractions such as Auth, Analytics, Storage that provide easy to use interfaces. Providers: A cloud provider or a service provider such as Cognito, Auth0 in Auth category; Kinesis, Pinpoint and Firehose in Analytics Category; Rekognition, Textract in Predictions Category. Plugins: Also called Amplify Plugins, bind providers to categories. They implement provider functionalities adhering to categories easy-to-use interfaces. Amplify Plugins already exist in native platforms (iOS/Android), this RFC explores creation of similar plugins in Flutter. Flutter Plugins/Platform Plugins/Federated Plugins: These are native platform code and modules that is called from flutter apps or libraries over a method channel.

Proposed Solution

High Level Overview

Amplify flutter will be architected as a pluggable interface across all the categories listed in the Goals. The pluggable interface will allow plugging in different cloud providers (e.g. Auth0 or Cognito for Auth category) which can be written either entirely in Dart or using Flutter's Platform Plugins to reuse native (iOS and/or android) modules.

The core of Amplify Flutter will be written in Dart which provides the pluggable interface and out of the box AWS cloud provider plugins will utilize existing Amplify Android and Amplify iOS libraries as Flutter's federated plugins. This means that we will not be implementing a Dart aws-sdk right away as AWS service calls will be made by Amplify Android/iOS libraries.

The Amplify flutter library will be compatible with Amplify CLI to create and provision your cloud providers' resources. Amplify CLI will generate a configuration file to easily configure your Flutter app to use these resources.

Pros

  1. We can reuse most of the existing Amplify native libraries' AWS providers and ship to customers faster.
  2. Some initial bench-marking proves that executing native platform code is generally faster than dart code.
  3. New features introduced in native libraries can be made available in Flutter with very minimal to no change.
  4. Provides flexibility to write providers' (AWS or others) implementation entirely in Dart if needed in the future.

Amplify Flutter(2)

Developer Experience

  • Creating and provisioning resources will remain the same with amplify CLI https://docs.amplify.aws/cli/start/workflows
  • Integrating with Amplify Flutter
    • Flutter Apps will import AmplifyCore and the plugins they want to use in the app.
    • In the app, developers will be required to call Amplify.addPlugin() for each plugin they import e.g. Amplify.addPlugin(CognitoAuthPlugin())
    • Developers will call Amplify.Category.<API> to use installed plugins, e.g. Amplify.Auth.signIn()
  • Developing and debugging Amplify Flutter
    • Refer official flutter guide to learn how to debug provider plugins that are written entirely in Dart and the ones that use platform federated plugins.
  • Using Amplify UI components for Flutter - Coming Soon

FAQs

Q. Which versions of Android and iOS are supported? Same versions as supported by Amplify Android and Amplify iOS libraries.

Q. How will escape hatches work with Amplify plugins that use native libraries? Coming Soon.

Q. How will events that are emitted in native libraries reach Flutter apps. We will use Flutter's event channels to subscribe events on the native platform and transmit them over to Dart end.

Q. Will web and Desktop platform be supported? Not right away, our goal with this design is to keep the architecture flexible such that more platforms can be supported in the future.

Q. Can I migrate my Amplify CLI generated config from Android, iOS or JS platform to flutter? Not right now. We will look into the feasibility of supporting this in the future.

Amplifiyer avatar Jul 21 '20 07:07 Amplifiyer

Glad to hear that Amplify support is coming.

Can I please request that this supports custom authentication flows?

The current Amplify documentation pages for Android and iOS suggest initiating auth with username and dummy password and then changing the Cognito Define Auth Challenge to override the SRP_A challenge with a custom challenge. This effectively means you can't have both flows for a single Cognito user pool.

We have two applications which use the same user pool but have different sign in methods - one is custom and one is SRP_A. I am unable to use Amplify because I'm forced to do this hacky override in the Cognito trigger so we've resorted to using the Cognito SDK (non-amplify) directly.

I believe custom flow may already be implemented in the JavaScript library because the password parameter is optional on the signIn function: https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#signin but this is not the case for Android or iOS so I'm not sure if this is in scope for this project or not. I can raise this as an issue in the Android and iOS repos too if necessary.

andyfurniss4 avatar Aug 19 '20 18:08 andyfurniss4

Can I please request that this supports custom authentication flows?

@andyfurniss4 Thanks for your feedback - we will definetely investigate this feature request!

haverchuck avatar Aug 20 '20 15:08 haverchuck

Are there any plans to actually implement the client libraries in native dart code? Would be nice not to rely on platform messages to just bridge everything to the android/iOS libraries, this would make it work on all platforms (ie. also on desktop platforms macos, windows, linux). It gets really great when you can use the same code for mobile and desktop ;-)

hpoul avatar Aug 20 '20 18:08 hpoul

In future can we expect Amazon SNS wrapper as part this package ? This will give us the ecosystem of various AWS features in single package.

vmadupu9 avatar Aug 21 '20 08:08 vmadupu9

At the moment there is no federate sign in methods. Did I missed something or is actually still to be implemented?

e-dedecube avatar Aug 21 '20 11:08 e-dedecube

Honestly, we are not that bothered with auth as it is something easy to do without AWS. What we want to have is DataStore sync like Google Firestore.

joekendal avatar Aug 21 '20 21:08 joekendal

I'm looking forward to the feature Datastore..

devorso avatar Aug 22 '20 14:08 devorso

@Dedecube OAuth authentication is definitely on the roadmap!

haverchuck avatar Aug 23 '20 17:08 haverchuck

DataStore and API would be great to have

devcshort avatar Sep 11 '20 19:09 devcshort

DataStore and API (Rest and GraphQL) asap please. I am in love with flutter and want to use AWS as my backend for the project I am designing. I don't want to give in and use firebase. Any idea what the timeline will look like. Even preview will work!

m11gt avatar Sep 12 '20 22:09 m11gt

Agree. Can't wait to switch from firebase to amplify.

dariotrombello avatar Sep 13 '20 12:09 dariotrombello

DataStore and API (Rest and GraphQL) are definitely a big need. Is there a time table for when we can see these added?

rlee1990 avatar Sep 13 '20 16:09 rlee1990

We need AppSync!

guoguoguilai avatar Sep 13 '20 16:09 guoguoguilai

As you can see, we're all pretty desperate for DataStore. If we could do anything to help I would gladly open pull requests but is there a list of things TODO ? 🥴

joekendal avatar Sep 15 '20 15:09 joekendal

Hi all, we are currently working on the design for the datastore and will put it here or in another RFC to gather feedback. Please stay tuned.

Amplifiyer avatar Sep 15 '20 18:09 Amplifiyer

Hi all, we are currently working on the design for the datastore and will put it here or in another RFC to gather feedback. Please stay tuned.

Edit (2021-02-16): Flutter SDK now supports DataStore so no need for the following hack.

~~If you are impatient like I am 😏, or your product release schedule can't be adapted to wait for DataStore support in this library, then you can write your own Flutter DataStore platform plugin that lives alongside this library.~~

~~I've created an example Flutter plugin and app to demonstrate a way to do this. That code can be found here: https://github.com/kjones/flutter-datastore-example~~

~~This is not a generic solution that will work with any GraphQL schema. It has to be targeted specifically to match your schema. Dart model classes have to be hand rolled since the Amplify codgen tools don't yet support Dart.~~

~~While this solution is far from perfect, it should give you a head start on using DataStore in your Flutter app while we wait for official support.~~

kjones avatar Sep 17 '20 22:09 kjones

Is there a timeline for supporting Flutter Web with AWS? I can get it working great on the iOS simulator but it can't configure amplify when running on web. Would be great to have the web app running too!

matthickey709 avatar Sep 23 '20 15:09 matthickey709

hate to ask a question like this, but I am wondering about the timeline for "production-grade" authentication. Currently, I am working on a big project with about a year-long timeline. Our stack is built primarily with flutter and aws services and we have tested "hello world" auth via amplify and it works great. However, because these features are labeled as "previews" and explicitly recommended not to be used in production, I was wondering when there would be reasonable certainty in the viability of flutter auth with amplify. Thank you!

nautsimon avatar Sep 28 '20 05:09 nautsimon

@simonmahns I hear if you email your concerns to [email protected] enough times he forwards it to the right person to resolve 😅

joekendal avatar Oct 01 '20 20:10 joekendal

Is there a weekly or bi-weekly progress report so we can know what to expect?

rlee1990 avatar Oct 06 '20 23:10 rlee1990