amplify_flutter 1.0.0-next.5+1 amplify_flutter: ^1.0.0-next.5+1 copied to clipboard
The top level Flutter package for the AWS Amplify libraries.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _amplifyConfigured = false;
var amplifyConfig = '''{"foo": "bar"}''';
@override
void initState() {
super.initState();
configureAmplify();
}
// Platform messages are asynchronous, so we initialize in an async method.
void configureAmplify() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
await Amplify.configure(amplifyConfig);
try {
setState(() {
_amplifyConfigured = true;
});
} on Exception catch (e) {
safePrint(e);
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Amplify Core example app'),
),
body: Center(
child: Text('Is Amplify Configured?: $_amplifyConfigured\n'),
),
),
);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(StringProperty('amplifyConfig', amplifyConfig));
}
}