diff --git a/CHANGELOG.md b/CHANGELOG.md index 69b4301..47d7a8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## [2.2.1] - 26th August 2025 + +* added android namespace + +## [2.2.0] - 25th November 2024 + +* fix compile error on ios + +## [2.1.0] - 25th November 2024 + +* fix pod not working + +## [2.0.0] - 26th October 2023 + +* *Breacking* Update to Dart 3 +* Fixed Android crash startup +* Fixed Android crash background + ## [1.0.2] - 23rd March 2020 * Fix: `asTorch` not working on iOS #4 diff --git a/README.md b/README.md index 901791e..a02fd9a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Torch compat -[![Pub](https://img.shields.io/pub/v/torch_compat.svg)](https://pub.dartlang.org/packages/torch_compat) +[![Pub](https://img.shields.io/pub/v/icapps_torch_compat.svg)](https://pub.dartlang.org/packages/icapps_torch_compat) A plugin to enable or disable the torch of a device that works both on Android (including Android 4.x) and ioS. @@ -25,13 +25,13 @@ This plugin by default only requests `android.permission.FLASHLIGHT`, but if you First import the library to your project in your `pubspec.yaml`: ```yaml -torch_compat: ^1.0.2 +icapps_torch_compat: ^2.0.0 ``` ### 2) Import the library in your Dart code ```dart -import 'package:torch_compat/torch_compat.dart'; +import 'package:icapps_torch_compat/icapps_torch_compat.dart'; ``` ### 3) Turn on or off the flash diff --git a/android/build.gradle b/android/build.gradle index cf370f8..b4cd404 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,8 +1,8 @@ -group 'fr.g123k.torch_compat' +group 'com.icapps.icapps_torch_compat' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.6.10' repositories { google() mavenCentral() @@ -25,6 +25,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { + namespace "com.icapps.icapps_torch_compat" compileSdkVersion 30 compileOptions { diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 76355c1..8cd30c8 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="com.icapps.icapps_torch_compat"> diff --git a/android/src/main/kotlin/fr/g123k/torch_compat/TorchCompatPlugin.kt b/android/src/main/kotlin/com/icapps/icapps_torch_compat/TorchCompatPlugin.kt similarity index 91% rename from android/src/main/kotlin/fr/g123k/torch_compat/TorchCompatPlugin.kt rename to android/src/main/kotlin/com/icapps/icapps_torch_compat/TorchCompatPlugin.kt index ca2f07a..731e124 100644 --- a/android/src/main/kotlin/fr/g123k/torch_compat/TorchCompatPlugin.kt +++ b/android/src/main/kotlin/com/icapps/icapps_torch_compat/TorchCompatPlugin.kt @@ -1,4 +1,4 @@ -package fr.g123k.torch_compat +package com.icapps.icapps_torch_compat import android.app.Activity import android.content.Context @@ -12,9 +12,9 @@ import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import fr.g123k.torch_compat.impl.BaseTorch -import fr.g123k.torch_compat.impl.TorchCamera2Impl -import fr.g123k.torch_compat.impl.TorchCamera1Impl +import com.icapps.icapps_torch_compat.impl.BaseTorch +import com.icapps.icapps_torch_compat.impl.TorchCamera2Impl +import com.icapps.icapps_torch_compat.impl.TorchCamera1Impl import io.flutter.embedding.engine.plugins.activity.ActivityAware import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding @@ -104,6 +104,10 @@ class TorchCompatPlugin: FlutterPlugin, MethodCallHandler, ActivityAware { override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) - torchImpl.dispose() + try { + torchImpl.dispose() + } catch (e: UninitializedPropertyAccessException) { + // ignore + } } } diff --git a/android/src/main/kotlin/fr/g123k/torch_compat/impl/BaseTorch.kt b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/BaseTorch.kt similarity index 77% rename from android/src/main/kotlin/fr/g123k/torch_compat/impl/BaseTorch.kt rename to android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/BaseTorch.kt index e4833a6..2b4ee2e 100644 --- a/android/src/main/kotlin/fr/g123k/torch_compat/impl/BaseTorch.kt +++ b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/BaseTorch.kt @@ -1,4 +1,4 @@ -package fr.g123k.torch_compat.impl +package com.icapps.icapps_torch_compat.impl abstract class BaseTorch { diff --git a/android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera1Impl.kt b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera1Impl.kt similarity index 96% rename from android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera1Impl.kt rename to android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera1Impl.kt index 3631d95..d987080 100644 --- a/android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera1Impl.kt +++ b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera1Impl.kt @@ -1,6 +1,6 @@ @file:Suppress("DEPRECATION") -package fr.g123k.torch_compat.impl +package com.icapps.icapps_torch_compat.impl import android.content.Context import android.content.pm.PackageManager diff --git a/android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera2Impl.kt b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera2Impl.kt similarity index 86% rename from android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera2Impl.kt rename to android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera2Impl.kt index 08feb2d..2d0821a 100644 --- a/android/src/main/kotlin/fr/g123k/torch_compat/impl/TorchCamera2Impl.kt +++ b/android/src/main/kotlin/com/icapps/icapps_torch_compat/impl/TorchCamera2Impl.kt @@ -1,4 +1,4 @@ -package fr.g123k.torch_compat.impl +package com.icapps.icapps_torch_compat.impl import android.content.Context import android.hardware.camera2.CameraCharacteristics @@ -10,9 +10,9 @@ import androidx.annotation.RequiresApi class TorchCamera2Impl(context: Context) : BaseTorch() { private val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager - private val cameraId = cameraManager.cameraIdList.first { cameraId -> + private val cameraId = cameraManager.cameraIdList.firstOrNull { cameraId -> cameraManager.getCameraCharacteristics(cameraId)[CameraCharacteristics.FLASH_INFO_AVAILABLE] != null - } ?: null + } override fun turnOn() { turn(on = true) diff --git a/example/.gitignore b/example/.gitignore index 0fa6b67..24476c5 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -8,6 +8,7 @@ .buildlog/ .history .svn/ +migrate_working_dir/ # IntelliJ related *.iml @@ -31,9 +32,6 @@ .pub/ /build/ -# Web related -lib/generated_plugin_registrant.dart - # Symbolication related app.*.symbols diff --git a/example/.metadata b/example/.metadata index 0f055bf..a778330 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,42 @@ # This file should be version controlled and should not be manually edited. version: - revision: ffb2ecea5223acdd139a5039be2f9c796962833d - channel: stable + revision: "d211f42860350d914a5ad8102f9ec32764dc6d06" + channel: "stable" project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: android + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: ios + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: linux + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: macos + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: web + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + - platform: windows + create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 61b6c4d..0d29021 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -13,8 +13,7 @@ linter: # The lint rules applied to this project can be customized in the # section below to disable rules from the `package:flutter_lints/flutter.yaml` # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. + # and their documentation is published at https://dart.dev/lints. # # Instead of disabling a lint rule for the entire project in the # section below, it can also be suppressed for a single line of code diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 14d2905..118ee1d 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,12 +22,10 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 30 + namespace "com.example.example" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -43,9 +42,11 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "fr.g123k.torch_compat_example" - minSdkVersion 16 - targetSdkVersion 30 + applicationId "com.example.example" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } @@ -63,6 +64,4 @@ flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +dependencies {} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 9d9d31f..399f698 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index b6f8765..19b862e 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,10 +1,11 @@ - - + - - diff --git a/example/android/app/src/main/kotlin/fr/g123k/torch_compat_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt similarity index 71% rename from example/android/app/src/main/kotlin/fr/g123k/torch_compat_example/MainActivity.kt rename to example/android/app/src/main/kotlin/com/example/example/MainActivity.kt index 6be2db5..e793a00 100644 --- a/example/android/app/src/main/kotlin/fr/g123k/torch_compat_example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt @@ -1,4 +1,4 @@ -package fr.g123k.torch_compat_example +package com.example.example import io.flutter.embedding.android.FlutterActivity diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml index 449a9f9..06952be 100644 --- a/example/android/app/src/main/res/values-night/styles.xml +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -3,14 +3,14 @@