Initial version.

This commit is contained in:
Aloïs Deniel
2018-01-04 19:36:18 +01:00
parent e6c43ec60b
commit ef4257e2f1
81 changed files with 1852 additions and 179 deletions
+44 -14
View File
@@ -1,6 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appcenter/appcenter.dart';
import 'package:appcenter_analytics/appcenter_analytics.dart';
import 'package:appcenter_crashes/appcenter_crashes.dart';
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/foundation.dart' show TargetPlatform;
void main() => runApp(new MyApp());
@@ -10,7 +14,15 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _app_secret;
String _installId = 'Unknown';
bool _areAnalyticsEnabled = false, _areCrashesEnabled = false;
_MyAppState() {
final ios = defaultTargetPlatform == TargetPlatform.iOS;
_app_secret = ios ? "a8a33033-ef2f-4911-a664-a7d118287ce7" : "3f1f3b0e-24ff-436a-b42d-3c08b117d46a";
}
@override
initState() {
@@ -20,22 +32,20 @@ class _MyAppState extends State<MyApp> {
// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Appcenter.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
await AppCenter.start(_app_secret, [AppCenterAnalytics.id, AppCenterCrashes.id]);
// 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;
var installId = await AppCenter.installId;
var areAnalyticsEnabled = await AppCenterAnalytics.isEnabled;
var areCrashesEnabled = await AppCenterCrashes.isEnabled;
setState(() {
_platformVersion = platformVersion;
_installId = installId;
_areAnalyticsEnabled = areAnalyticsEnabled;
_areCrashesEnabled = areCrashesEnabled;
});
}
@@ -46,8 +56,28 @@ class _MyAppState extends State<MyApp> {
appBar: new AppBar(
title: new Text('Plugin example app'),
),
body: new Center(
child: new Text('Running on: $_platformVersion\n'),
body: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new Text('Install identifier: $_installId'),
new Text('Analytics: $_areAnalyticsEnabled'),
new Text('Crashes: $_areCrashesEnabled'),
new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new Text('Send events'),
new IconButton(
icon: new Icon(Icons.map),
tooltip: 'map',
onPressed: () { AppcenterAnalytics.trackEvent("map"); },
),
new IconButton(
icon: new Icon(Icons.casino),
tooltip: 'casino',
onPressed: () { AppcenterAnalytics.trackEvent("casino", { "dollars" : "10" }); },
),
])
]
),
),
);