flutter_appstore_detection 0.0.2 copy "flutter_appstore_detection: ^0.0.2" to clipboard
flutter_appstore_detection: ^0.0.2 copied to clipboard

PlatformiOS

A Flutter plugin project for iOS. You can use it to get whether your app is probably installed from AppStore. Get your app's version on AppStore.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_appstore_detection/flutter_appstore_detection.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _flutterAppstoreDetectionPlugin = FlutterAppstoreDetection();
  bool _didProbablyInstallFromAppStore = true;
  String _latestAppVersionOnAppStore = "0.0.0";

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    bool didProbablyInstallFromAppStore = false;
    String latestAppVersionOnAppStore = "0.0.0";

    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _flutterAppstoreDetectionPlugin.getPlatformVersion() ??
              'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    try {
      didProbablyInstallFromAppStore = await _flutterAppstoreDetectionPlugin
              .didProbablyInstallFromAppStore() ??
          true;
    } on PlatformException {
      platformVersion = 'Failed to get did install from AppStore.';
    }

    latestAppVersionOnAppStore = await _flutterAppstoreDetectionPlugin
            .fetchLatestAppVersionOnAppStore("your_appId") ??
        '0.0.0';

    // 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;
      _didProbablyInstallFromAppStore = didProbablyInstallFromAppStore;
      _latestAppVersionOnAppStore = latestAppVersionOnAppStore;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                  'Did probably install from AppStore: $_didProbablyInstallFromAppStore\n'),
              Text('appVerson on AppStore: $_latestAppVersionOnAppStore\n'),
              Text('Running on: $_platformVersion\n'),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
140
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin project for iOS. You can use it to get whether your app is probably installed from AppStore. Get your app's version on AppStore.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

dio, flutter, plugin_platform_interface

More

Packages that depend on flutter_appstore_detection