From ccf38f7ba78c9f5e00e83d70b13ae42aa33d28e7 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:19:19 +0300 Subject: [PATCH] Document AppInfo Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .../plugin_integration_test.dart | 2 +- example/lib/main.dart | 4 +- lib/app_info.dart | 60 ++++++++----------- lib/apps_list.dart | 2 +- lib/apps_list_method_channel.dart | 6 +- lib/apps_list_platform_interface.dart | 2 +- test/apps_list_test.dart | 4 +- 7 files changed, 34 insertions(+), 46 deletions(-) diff --git a/example/integration_test/plugin_integration_test.dart b/example/integration_test/plugin_integration_test.dart index f7cec37..d40ccfa 100644 --- a/example/integration_test/plugin_integration_test.dart +++ b/example/integration_test/plugin_integration_test.dart @@ -17,7 +17,7 @@ void main() { testWidgets('getPlatformVersion test', (WidgetTester tester) async { final AppsList plugin = AppsList(); - final List apps = await plugin.getInstalledApps(); + final List apps = await plugin.getInstalledApps(); expect(apps, isNotNull); }); } diff --git a/example/lib/main.dart b/example/lib/main.dart index 0c60967..5b49cbf 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -18,7 +18,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { final _appsListPlugin = AppsList(); - List _apps = []; + List _apps = []; @override void initState() { @@ -27,7 +27,7 @@ class _MyAppState extends State { } Future initPlatformState() async { - List apps = []; + List apps = []; try { apps = await _appsListPlugin.getInstalledApps(); } on PlatformException { diff --git a/lib/app_info.dart b/lib/app_info.dart index eaceb68..1704e39 100644 --- a/lib/app_info.dart +++ b/lib/app_info.dart @@ -1,62 +1,50 @@ +/// Dart package for handling app information. import 'dart:typed_data'; -// enum AppProfile { -// Work, -// Personal - -// // from string -// } - +/// Class representing information about an app. class AppInfo { + /// The name of the app. String name; + + /// The icon of the app as a list of unsigned 8-bit integers. Uint8List icon; + + /// The package name of the app. String packageName; + + /// A boolean value indicating whether the app is a system app. bool isSystemApp; - AppInfo(this.name, this.icon, this.packageName, this.isSystemApp); + /// The profile associated with the app. + String profile; + + /// The serial number of the app. + int serialNumber; + /// Constructor for the AppInfo class. + AppInfo(this.name, this.icon, this.packageName, this.isSystemApp, + this.profile, this.serialNumber); + + /// Factory constructor for creating an instance of AppInfo from dynamic data. factory AppInfo.create(dynamic data) { return AppInfo( data["name"], data["icon"], data["package_name"], data["is_system_app"], + data["profile"], + data["serial_number"], ); } + /// Method for comparing this AppInfo instance with another based on name. int compareTo(AppInfo other) { return name.compareTo(other.name); } + /// Method for converting this AppInfo instance to a string. @override String toString() { - return "AppInfo{name=$name, packageName=$packageName, isSystemApp=$isSystemApp"; - } -} - -class AppInfoByProfile extends AppInfo { - // profile can only be personal or work - String profile; - int serialNumber; - - AppInfoByProfile(String name, Uint8List icon, String packageName, - bool isSystemApp, this.profile, this.serialNumber) - : super(name, icon, packageName, isSystemApp); - - factory AppInfoByProfile.create(dynamic data) { - // AppProfile profile = AppProfile.values[data["profile"]]; - return AppInfoByProfile( - data["name"], - data["icon"], - data["package_name"], - data["is_system_app"], - data["profile"], - data["serial_number"], - ); - } - - @override - String toString() { - return "AppInfoByProfile{name=$name, packageName=$packageName, isSystemApp=$isSystemApp, profile=$profile"; + return "AppInfo{name=$name, packageName=$packageName, isSystemApp=$isSystemApp, profile=$profile, serialNumber=$serialNumber"; } } diff --git a/lib/apps_list.dart b/lib/apps_list.dart index 850edfd..74af47a 100644 --- a/lib/apps_list.dart +++ b/lib/apps_list.dart @@ -7,7 +7,7 @@ class AppsList { return AppsListPlatform.instance.launchApp(packageName, serialNumber); } - Future> getInstalledApps() async { + Future> getInstalledApps() async { return AppsListPlatform.instance.getInstalledApps(); } } diff --git a/lib/apps_list_method_channel.dart b/lib/apps_list_method_channel.dart index 31f8116..3e3a1ee 100644 --- a/lib/apps_list_method_channel.dart +++ b/lib/apps_list_method_channel.dart @@ -27,11 +27,11 @@ class MethodChannelAppsList extends AppsListPlatform { // get installed apps @override - Future> getInstalledApps() async { + Future> getInstalledApps() async { try { List apps = await methodChannel.invokeMethod('getInstalledApps'); - List appInfoList = - apps.map((app) => AppInfoByProfile.create(app)).toList(); + List appInfoList = + apps.map((app) => AppInfo.create(app)).toList(); return Future.value(appInfoList); } on PlatformException { debugPrint("APPS ERROR"); diff --git a/lib/apps_list_platform_interface.dart b/lib/apps_list_platform_interface.dart index 0639e9c..3cb1589 100644 --- a/lib/apps_list_platform_interface.dart +++ b/lib/apps_list_platform_interface.dart @@ -28,7 +28,7 @@ abstract class AppsListPlatform extends PlatformInterface { throw UnimplementedError('launchApp() has not been implemented.'); } - Future> getInstalledApps() async { + Future> getInstalledApps() async { throw UnimplementedError( 'getInstalledAppsByProfile() has not been implemented.'); } diff --git a/test/apps_list_test.dart b/test/apps_list_test.dart index 77263d5..e7182fb 100644 --- a/test/apps_list_test.dart +++ b/test/apps_list_test.dart @@ -11,7 +11,7 @@ class MockAppsListPlatform Future getPlatformVersion() => Future.value('42'); @override - Future> getInstalledApps() { + Future> getInstalledApps() { return Future.value([]); } @@ -33,7 +33,7 @@ void main() { MockAppsListPlatform fakePlatform = MockAppsListPlatform(); AppsListPlatform.instance = fakePlatform; - List apps = await appsListPlugin.getInstalledApps(); + List apps = await appsListPlugin.getInstalledApps(); expect(apps, isNotNull); }); }