amplify_flutter 0.0.2-dev.1 amplify_flutter: ^0.0.2-dev.1 copied to clipboard
The top level module for Amplify Flutter.
/*
* 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:flutter/material.dart';
import 'package:amplify_flutter/amplify.dart';
void main() {
runApp(MyApp());
}
// ignore: public_member_api_docs
class MyApp extends StatefulWidget {
@override
_MyAppState 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;
});
} catch (e) {
print(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'),
),
),
);
}
}