-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ba05ba
commit 93b4697
Showing
4 changed files
with
89 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,68 @@ | ||
# Flutter Amplify Auth UI Example | ||
# Flutter Amplify Auth UI | ||
|
||
This example demonstrates how the flutter_amplify_auth_ui plugin uses an Amplify configuration | ||
to generate Authentication widgets. | ||
Execute the following command in your project's root folder in order to generate authentication widgets | ||
based on your Amplify configuration: | ||
|
||
By executing the command from [example.sh](example.sh) | ||
you generate Flutter widgets into the [target](target) folder that are based on the sample | ||
Amplify configuration in the [amplify](amplify) folder. | ||
``` | ||
flutter packages pub run flutter_amplify_auth_ui:main | ||
``` | ||
|
||
## Usage | ||
Easily integrate the generated authentication widgets in your project, e.g.: | ||
|
||
`./example.sh` | ||
``` dart | ||
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart'; | ||
import 'package:amplify_flutter/amplify.dart'; | ||
import 'package:flutter/material.dart'; | ||
or | ||
import 'generated_auth_classes/sign_in/sign_in_page.dart'; // <-- Import the generated widget | ||
``` | ||
flutter packages pub run flutter_amplify_auth_ui:main --amplifyDir=./example/amplify --targetDir=./example/target | ||
import 'amplifyconfiguration.dart'; | ||
class MyApp extends StatefulWidget { | ||
@override | ||
_MyAppState createState() => _MyAppState(); | ||
} | ||
class _MyAppState extends State<MyApp> { | ||
@override | ||
initState() { | ||
super.initState(); | ||
_configureAmplify(); | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Amplify Auth UI Demo', | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
debugShowCheckedModeBanner: false, | ||
home: SignInPage( // <-- Include the generated widget in your widget tree | ||
onSignIn: (context) => Navigator.push( //TODO Define what to do after sign in | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => | ||
const MyHomePage(title: 'Flutter Demo Home Page'), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
void _configureAmplify() async { | ||
if (!mounted) return; | ||
Amplify.addPlugins([ | ||
AmplifyAuthCognito(), | ||
]); | ||
try { | ||
await Amplify.configure(amplifyconfig); | ||
} on AmplifyAlreadyConfiguredException { | ||
print("Tried to reconfigure Amplify; this can occur when your app restarts on Android."); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters