apptics_flutter 0.0.8 copy "apptics_flutter: ^0.0.8" to clipboard
apptics_flutter: ^0.0.8 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:apptics_flutter/appupdate/apptics_in_app_update.dart';
import 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
import 'package:apptics_flutter/defined_events.dart';
import 'package:apptics_flutter/feedback/apptics_feedback.dart';
import 'package:apptics_flutter/feedback/apptics_log_type.dart';
import 'package:apptics_flutter/feedback/apptics_logs.dart';
import 'package:apptics_flutter/rateus/apptics_in_app_rating.dart';
import 'package:apptics_flutter/remoteconfig/apptics_remote_config.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.instance;




  @override
  void initState() {
    super.initState();
    setDefaultLanguage();
    screenAttached();
    isUserLoggedIn();
    showLastSessionCrashedPopup();
    AppticsInAppRating.instance.setShowStoreAlertOnFulFillingCriteria(false);
    // 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');

    dynamic crash = await AppticsCrashTracker.instance.getLastCrashInfo();

    print(crash);


    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");
    AppticsCrashTracker.instance.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 {
    AppticsLogs.instance.writeLog("Demo Feedback", Log.verbose);
    AppticsLogs.instance.addDiagnosticsInfo("heading", "Demo", "value");
    // final status = await AppticsFeedback.instance.sendFeedbackInstantlyWithoutRetries(TypeOfFeedback.feedback, "sendFeedbackInstantlyWithoutRetries - from FLUTTER", true, true);
    // print(status);
    // List of URL strings
  List<String> urlStrings = [
    'https://example.com/file1.png',
    'https://example.com/file2.png',
    'https://example.com/file3.png'
  ];
  // Convert URL strings to Uri objects
  List<Uri>? attachmentsUri = urlStrings.isNotEmpty
      ? urlStrings.map((url) => Uri.parse(url)).toList()
      : null; // Use null if the list is empty

    // AppticsFeedback.instance.sendFeedback("Send Feedback with URI", true, true, guestMailId:"someemail@gmail.com", forceToAnonymous: true, attachmentsUri:urlStrings);

    AppticsFeedback.instance.openFeedback();
    AppticsFeedback.instance.sendFeedback("This is feedback form flutter manual", false, false);
    AppticsFeedback.instance.sendBugReport("This is report bug from flutter manual.", false, false);
  }

  flush() async {
    _appticsFlutterPlugin.flush();
  }

  checkForUpdate() async {
    AppticsInAppUpdates.instance.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();
  }

  checkRating(BuildContext context) async {
    // await _appticsFlutterPlugin.addEvent("country_code_change", "bill", {'test': 1});
    AppticsFlutter().addEvent("country_code_change", "bill");
  }

  remoteConfig(BuildContext context) async {
    AppticsFeedback.instance.reportBug();

    String? stringValue = await AppticsRemoteConfig.instance.getStringValue(
        'TalkT3',
        coldFetch: true,
        fallbackWithOfflineValue: true);
    if (stringValue != null) {
      print("stringValue $stringValue");
      // Show popup
      // showDialog(context: context, builder: (context) =>{
      //   AlertDialog(title: Text(stringValue));
      // });
      showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text(stringValue),
            alignment: Alignment.center,
          );
        },
      );
    } else {
      print("No data available");
    }
  }

  moreApps() async {
    const channel = MethodChannel('crashy-custom-channel');
    await channel.invokeMethod('blah');
  }

  // Android
  crashMaker() async {
    int k = (1 / 0) as int;
  }
  addNonFatal() async{
    try {
      int k = (1 / 0) as int;
    }catch(e,s){
      AppticsCrashTracker.instance.sendNonFatalException(e, s);
    }
  }

  isUserLoggedIn() async {
    bool? check = await _appticsFlutterPlugin.isUserLoggedIn();
    print("Check user present $check");
  }

  setTrackingState() async {
    await _appticsFlutterPlugin.setTrackingState(TrackingState.getByValue(1));
  }

  addEvent() async {

    await _appticsFlutterPlugin.addEvent("TESTEVENT", "TESTGROUP");
    AppticsFlutter.instance.addEvent(DefinedEvents.AP_DEEP_LINK_FIRST_OPEN, DefinedEvents.AP_APPLICATION);

    AppticsFlutter().addEvent("update_install_event", "IN_APP_UPDATE",
        properties: {"name": "ABCD", "isCheck": true, "number": 121213});
  }

  setDefaultLanguage() async {
    _appticsFlutterPlugin.setDefaultLanguage("en");
  }

  screenAttached() async {
    _appticsFlutterPlugin.screenAttached("MainScreenIn");
  }

  screenDetached() async {
    _appticsFlutterPlugin.screenDetached("MainScreenIn");
  }

  showLastSessionCrashedPopup() async {
    AppticsCrashTracker.instance.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 AppticsCrashTracker.instance.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) {

    AppticsCrashTracker.instance.autoCrashTracker();

    // FlutterError.onError = AppticsCrashTracker.instance.sendFlutterException;

    final navigatorKey = GlobalKey<NavigatorState>();

    final ButtonStyle style = ElevatedButton.styleFrom(
        minimumSize: const Size(300, 40),
        alignment: Alignment.center,
        textStyle: const TextStyle(fontSize: 20));
    AppticsInAppRating.instance.checkForRatingPop(context);
    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: addEvent,
                  child: const Text("Events"),
                ),
                const SizedBox(height: 30),
                ElevatedButton(
                  style: style,
                  onPressed: crashMaker,
                  // onPressed: trackLogout,
                  child: const Text("Crash"),
                ),
                const SizedBox(height: 30),
                ElevatedButton(
                  style: style,
                  onPressed: addNonFatal,
                  child: const Text("Add Non-fatal"),
                ),
                const SizedBox(height: 30),
                ElevatedButton(
                  style: style,
                  onPressed: flush,
                  child: const Text("Flush"),
                ),
                const SizedBox(height: 30),
                ElevatedButton(
                  style: style,
                  onPressed: openFeedback,
                  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),
                ElevatedButton(
                  style: style,
                  onPressed: () => {checkRating(context)},
                  child: const Text("Rate Us"),
                ),
                const SizedBox(height: 30),
                ElevatedButton(
                  style: style,
                  onPressed: () => {remoteConfig(context)},
                  child: const Text("Remote Config"),
                ),
                const SizedBox(height: 30)
              ],
            ),
          ))),
    );
  }
}
5
likes
140
points
55
downloads

Publisher

verified publisherzoho.com

Weekly Downloads

Flutter plugin for Apptics, wrapper around Apptics Native iOS and Android SDK. Supports features likes in-app updates, in-app events, screens and sessions.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on apptics_flutter