flutter_app_checker 0.0.1 flutter_app_checker: ^0.0.1 copied to clipboard
A new flutter plugin project.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_app_checker/flutter_app_checker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isInstalled = false;
String appName = "instagram";
// Android needs package's name
// String appName = "com.instagram.android";
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
bool isInstalled;
try {
isInstalled = await FlutterAppChecker.isAppInstalled(appName: appName);
} on PlatformException {
isInstalled = false;
}
// 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(() {
_isInstalled = isInstalled;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('$appName ${_isInstalled ? "is installed" : "is not installed"}\n'),
),
),
);
}
}