amplify_flutter 0.5.0 amplify_flutter: ^0.5.0 copied to clipboard
The top level Flutter package for the AWS Amplify libraries.
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
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({Key? key}) : super(key: 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));
}
}