apptics_flutter 0.0.2
apptics_flutter: ^0.0.2 copied to clipboard
Flutter plugin for Apptics, wrapper around Apptics Native iOS and Android SDK. Supports features likes in-app updates, in-app events, screens and sessions.
example/lib/main.dart
import 'package:apptics_flutter/apptics_flutter.dart';
import 'package:apptics_flutter/apptics_flutter_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _platformVersion = 'Unknown';
final _appticsFlutterPlugin = AppticsFlutter();
@override
void initState() {
super.initState();
setDefaultLanguage();
screenAttached();
isUserLoggedIn();
showLastSessionCrashedPopup();
// initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion = "";
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
// try {
// platformVersion =
// await _appticsFlutterPlugin.getPlatformVersion() ?? 'Unknown platform version';
// } on PlatformException {
// platformVersion = 'Failed to get platform version.';
// }
// 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;
setState(() {
_platformVersion = platformVersion;
});
}
sampleFunction() async {
print('Function on Click Event Called sampleFunction');
dynamic status = await _appticsFlutterPlugin.getTrackingState() ??
TrackingState.noTracking;
print('privacy_status $status');
Map<String, dynamic> _portaInfoMap = {
"name": "Vitalflux.com",
"domains": ["Data Science", "Mobile", "Web"],
"noOfArticles": [
{"type": "data science", "count": 50},
{"type": "web", "count": 75}
]
};
_appticsFlutterPlugin.setUser("ssaravanan@zoho.com");
_appticsFlutterPlugin.setCrashCustomProperty(_portaInfoMap);
// _appticsFlutterPlugin.setTrackingState(TrackingState.getByValue(1));
// _appticsFlutterPlugin.getPrivacyStatus().then((value){
// print('privacy_status ' + value.toString());
// });
// (_appticsFlutterPlugin.getPrivacyStatus() == true) ? print("true") : print("false");
// Put your code here, which you want to execute on onPress event.
}
openEventsViewController() async {}
openCrashViewController() async {}
openNonFatalViewController() async {}
openFeedback() async {}
checkForUpdate() async {
_appticsFlutterPlugin.checkAndUpdateAlert(context);
}
openAPITrackerViewController() async {}
trackLogin() async {
_appticsFlutterPlugin.presentPrivacyReviewPopup();
_appticsFlutterPlugin.setUser('ssaravanan@zoho.com');
}
trackLogout() async {
// _appticsFlutterPlugin.trackLogout('ssaravanan@zoho.com');
// _appticsFlutterPlugin.showLastSessionCrashedPopup();
}
openSettingsViewController() async {
_appticsFlutterPlugin.openPrivacySettings();
}
moreApps() async {
const channel = MethodChannel('crashy-custom-channel');
await channel.invokeMethod('blah');
}
// Android
crashMaker() async {
// int k = (1 / 0) as int;
}
isUserLoggedIn() async {
bool? check = await _appticsFlutterPlugin.isUserLoggedIn();
print("Check user present $check");
}
setTrackingState() async {
await _appticsFlutterPlugin.setTrackingState(TrackingState.getByValue(1));
}
addEvent() async {
//"Filters-mode_switched", "2113415048041-2113415017169" "mode_switched", "Filters"
await _appticsFlutterPlugin.addEvent(
"mode_switched", "Filters", {"title": "Test", "mapEvent": "Test Two"});
}
setDefaultLanguage() async {
_appticsFlutterPlugin.setDefaultLanguage("es-ES");
}
screenAttached() async {
_appticsFlutterPlugin.screenAttached("MainScreenIn");
}
screenDetached() async {
_appticsFlutterPlugin.screenDetached("MainScreenIn");
}
showLastSessionCrashedPopup() async {
_appticsFlutterPlugin.showLastSessionCrashedPopup();
}
setCustomProperties() async {
Map<String, dynamic> _portaInfoMap = {
"name": "Vitalflux.com",
"domains": ["Data Science", "Mobile", "Web"],
"noOfArticles": [
{"type": "data science", "count": 50},
{"type": "web", "count": 75}
]
};
await _appticsFlutterPlugin.setCrashCustomProperty(_portaInfoMap);
}
Widget building(BuildContext context) {
return MaterialApp(
builder: (context, widget) {
Widget error = const Text('...rendering error...');
if (widget is Scaffold || widget is Navigator) {
error = Scaffold(body: Center(child: error));
}
ErrorWidget.builder = (errorDetails) => error;
if (widget != null) return widget;
throw ('widget is null');
},
);
}
@override
Widget build(BuildContext context) {
final navigatorKey = GlobalKey<NavigatorState>();
final ButtonStyle style = ElevatedButton.styleFrom(
minimumSize: const Size(300, 40),
alignment: Alignment.center,
textStyle: const TextStyle(fontSize: 20));
return MaterialApp(
navigatorKey: navigatorKey,
home: Scaffold(
appBar: AppBar(
title: const Text('Apptics Plugin example app'),
),
// body: const MyStatelessWidget(),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
style: style,
onPressed: setCustomProperties,
child: const Text("Events"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: crashMaker,
child: const Text("Crash"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: sampleFunction,
child: const Text("Add Non-fatal"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: sampleFunction,
child: const Text("Open Feedback"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: checkForUpdate,
child: const Text("Check for update"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: sampleFunction,
child: const Text("API tracking"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: trackLogin,
child: const Text("Login"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: () => {},
child: const Text("Logout"),
),
const SizedBox(height: 30),
ElevatedButton(
style: style,
onPressed: openSettingsViewController,
child: const Text("Open Analytics Settings"),
),
const SizedBox(height: 30)
],
),
))),
);
}
}