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

PlatformAndroid

A Flutter plugin to get Android's firstInstallTime.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:install_time_plugin/install_time_plugin.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 installTime = 'Unknown'; // 用於顯示的字串

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

  Future<void> _loadInstallTime() async {
    try {
      // 查詢自己
      final int? myInstallTime = await InstallTimePlugin.getFirstInstallTime();

      // 查詢指定 package
      final int? settingsInstallTime =
          await InstallTimePlugin.getFirstInstallTime(
            packageName: "com.android.settings",
          );

      if (!mounted) return;

      setState(() {
        installTime =
            (myInstallTime != null)
                ? "My App Installed: ${DateTime.fromMillisecondsSinceEpoch(myInstallTime)}\n"
                : "Failed to get my app install time.";

        installTime +=
            (settingsInstallTime != null)
                ? "\nSettings Installed: ${DateTime.fromMillisecondsSinceEpoch(settingsInstallTime)}"
                : "\nFailed to get Settings app install time.";
      });
    } catch (e) {
      if (!mounted) return;
      setState(() {
        installTime = 'Failed to get install time: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(child: Text('Installed on: $installTime\n')),
      ),
    );
  }
}
0
likes
160
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to get Android's firstInstallTime.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on install_time_plugin

Packages that implement install_time_plugin