Skip to content

(fix) quickstart: Fix Flutter Quickstart Guide #7684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/directory/directory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const directory = {
},
{
path: 'src/pages/[platform]/start/migrate-to-gen2/index.mdx'
},
{
path: 'src/pages/[platform]/start/platform-setup/index.mdx'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const meta = {
route: "/[platform]/build-a-backend/add-aws-services/in-app-messaging",
platforms: [
'angular',
'flutter',
'javascript',
'nextjs',
'react',
Expand Down
59 changes: 59 additions & 0 deletions src/pages/[platform]/start/platform-setup/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';

export const meta = {
title: 'Platform setup',
description: 'Instructions for platform-specific configurations needed for amplify-flutter',
platforms: [
'flutter',
]
};

export const getStaticPaths = async () => {
return getCustomStaticPath(meta.platforms);
};

export function getStaticProps(context) {
return {
props: {
platform: context.params.platform,
meta
}
};
}


### iOS
From your project root, navigate to the `ios/` directory and modify the `Podfile` using a text editor of your choice and update the target iOS platform to 11.0 or higher.

```bash
platform :ios, '11.0'
```

<Callout>

When preparing your application for deployment, you should also update your iOS Deployment Target to at least 11.0. See the [Flutter docs](https://docs.flutter.dev/deployment/ios) to learn more about building your iOS app for release.

</Callout>

### Android
From your project root, navigate to the `android/app/` directory and modify `build.gradle` using a text editor of your choice and update the target Android SDK version to 21 or higher:

```bash
minSdkVersion 21
```

<Callout warning>

If you are using Flutter 2.10 or above, you will need to ensure that your app supports an [up-to-date Kotlin version](https://docs.flutter.dev/release/breaking-changes/kotlin-version).
This will typically be version 1.5.31 or higher.
<br />
You can do this by updating the Kotlin version in your app's `android/build.gradle` file:

```yaml
buildscript {
ext.kotlin_version = '1.5.31'
...
}
```

</Callout>
107 changes: 70 additions & 37 deletions src/pages/[platform]/start/quickstart/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1263,17 +1263,26 @@ You can follow the [official documentation](https://flutter.dev/docs/get-started

Once you have installed Flutter, you can create a new Flutter project using the following command:

<Callout info>
n this Quickstart guide, you will build the application for Web. However, if you want to run the application on other platforms, be sure to follow the required setup [guide here](/[platform]/start/platform-setup/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

</Callout>

```bash title="Terminal" showLineNumbers={false}
flutter create my_amplify_app
```

## Create Backend

The easiest way to get started with AWS Amplify is through npm with `create-amplify` command. You can run it from your base project directory.
The easiest way to get started with AWS Amplify is through npm with `create-amplify` command. You can run it from your base project directory. First, go to the base project directory with the following command:

```bash title="Terminal" showLineNumbers={false}
npm create amplify@latest
? Where should we create your project? (.) # press enter
cd my_amplify_app
```

After that, run the following to create an Amplify project:

```bash title="Terminal" showLineNumbers={false}
npm create amplify@latest -y
```

Running this command will scaffold Amplify backend files in your current project with the following files added:
Expand Down Expand Up @@ -1316,7 +1325,7 @@ npx ampx sandbox --outputs-format dart --outputs-out-dir lib --outputs-version 0

## Adding Authentication

The initial scaffolding already has a pre-configured auth backend defined in the `amplify/auth/resource`.ts file. We've configured it to support email and password login but you can extend it to support a variety of login mechanisms, including Google, Amazon, Sign In With Apple, and Facebook.
The initial scaffolding already has a pre-configured auth backend defined in the `amplify/auth/resource.ts` file. We've configured it to support email and password login but you can extend it to support a variety of login mechanisms, including Google, Amazon, Sign In With Apple, and Facebook.

The fastest way to get your login experience up and running is to use our Authenticator UI component available in the Amplify UI library.

Expand Down Expand Up @@ -1364,7 +1373,7 @@ Future<void> main() async {
Future<void> _configureAmplify() async {
try {
await Amplify.addPlugin(AmplifyAuthCognito());
await Amplify.configure(outputs);
await Amplify.configure(amplifyConfig);
safePrint('Successfully configured');
} on Exception catch (e) {
safePrint('Error configuring Amplify: $e');
Expand Down Expand Up @@ -1457,18 +1466,22 @@ Future<void> _configureAmplify() async {
await Amplify.addPlugins(
[
AmplifyAuthCognito(),
AmplifyAPI(modelProvider: ModelProvider.instance),
AmplifyAPI(
options: APIPluginOptions(
modelProvider: ModelProvider.instance,
),
),
],
);
await Amplify.configure(outputs);
await Amplify.configure(amplifyConfig);
safePrint('Successfully configured');
} on Exception catch (e) {
safePrint('Error configuring Amplify: $e');
}
}
```

Next create a new widget called `TodoScreen` and add the following code:
Next create a new widget called `TodoScreen` and add the following code to the end of the **main.dart** file:

```dart title="main.dart"

Expand All @@ -1490,8 +1503,6 @@ class _TodoScreenState extends State<TodoScreen> {
id: uuid(),
content: "Random Todo ${DateTime.now().toIso8601String()}",
isDone: false,
createdAt: TemporalDateTime(DateTime.now()),
updatedAt: TemporalDateTime(DateTime.now()),
);
final request = ModelMutations.create(newTodo);
final response = await Amplify.API.mutate(request: request).response;
Expand All @@ -1500,7 +1511,6 @@ class _TodoScreenState extends State<TodoScreen> {
} else {
safePrint('Creating Todo successful.');
}
_refreshTodos();
},
),
body: const Placeholder(),
Expand Down Expand Up @@ -1572,36 +1582,59 @@ Future<void> _refreshTodos() async {
}
```

and update the body with the following code:
and update the `build` function like the following:

```dart title="main.dart"
body: _todos.isEmpty == true
? const Center(
child: Text(
"The list is empty.\nAdd some items by clicking the floating action button.",
textAlign: TextAlign.center,
),
)
: ListView.builder(
itemCount: _todos.length,
itemBuilder: (context, index) {
final todo = _todos[index];
return Dismissible(
key: UniqueKey(),
confirmDismiss: (direction) async {
return false;
},
child: CheckboxListTile.adaptive(
value: todo.isDone,
title: Text(todo.content!),
onChanged: (isChecked) async { },
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton.extended(
label: const Text('Add Random Todo'),
onPressed: () async {
final newTodo = Todo(
id: uuid(),
content: "Random Todo ${DateTime.now().toIso8601String()}",
isDone: false,
);
final request = ModelMutations.create(newTodo);
final response = await Amplify.API.mutate(request: request).response;
if (response.hasErrors) {
safePrint('Creating Todo failed.');
} else {
safePrint('Creating Todo successful.');
}
_refreshTodos();
},
),
body: _todos.isEmpty == true
? const Center(
child: Text(
"The list is empty.\nAdd some items by clicking the floating action button.",
textAlign: TextAlign.center,
),
);
},
),
)
: ListView.builder(
itemCount: _todos.length,
itemBuilder: (context, index) {
final todo = _todos[index];
return Dismissible(
key: UniqueKey(),
confirmDismiss: (direction) async {
return false;
},
child: CheckboxListTile.adaptive(
value: todo.isDone,
title: Text(todo.content!),
onChanged: (isChecked) async {},
),
);
},
),
);
}
```

Now let's add a update and delete functionality.
Now let's add the update and delete functionality.

For update, add the following code to the `onChanged` method of the `CheckboxListTile.adaptive` widget:

Expand Down Expand Up @@ -1647,7 +1680,7 @@ You can terminate the sandbox environment now to clean up the project.

### Publishing changes to cloud

For publishing the changes to cloud, you need to create a remote git repository. For a detailed guide, you can follow the link [here](/[platform]/start/quickstart/#publishing-changes-to-cloud).
For publishing the changes to cloud, you need to create a remote git repository. For a detailed guide, you can follow the link [here](/[platform]/deploy-and-host/fullstack-branching/branch-deployments).

</InlineFilter>

Expand Down
Loading