From 7c5bcd22f01dda690b989a1894e74aa7f6089c9d Mon Sep 17 00:00:00 2001 From: lxh2875931338 Date: Fri, 31 Jul 2026 21:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8E=E9=A1=B5=E7=A1=AE=E5=AE=9A?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle.kts.bak | 44 ----------- android/app/build.gradle.kts.txt | 73 ------------------- android/app/src/main/AndroidManifest.xml | 8 ++ .../com/lxh/battery_health/MainActivity.kt | 3 +- lib/pages/about_page.dart | 31 ++++---- pubspec.lock | 8 ++ pubspec.yaml | 3 +- 7 files changed, 37 insertions(+), 133 deletions(-) delete mode 100644 android/app/build.gradle.kts.bak delete mode 100644 android/app/build.gradle.kts.txt diff --git a/android/app/build.gradle.kts.bak b/android/app/build.gradle.kts.bak deleted file mode 100644 index 9d01d81..0000000 --- a/android/app/build.gradle.kts.bak +++ /dev/null @@ -1,44 +0,0 @@ -plugins { - id("com.android.application") - id("kotlin-android") - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. - id("dev.flutter.flutter-gradle-plugin") -} - -android { - namespace = "com.lxh.battery_health" - compileSdk = flutter.compileSdkVersion - ndkVersion = flutter.ndkVersion - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11.toString() - } - - defaultConfig { - // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId = "com.lxh.battery_health" - // You can update the following values to match your application needs. - // For more information, see: https://flutter.dev/to/review-gradle-config. - minSdk = flutter.minSdkVersion - targetSdk = flutter.targetSdkVersion - versionCode = flutter.versionCode - versionName = flutter.versionName - } - - buildTypes { - release { - // TODO: Add your own signing config for the release build. - // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig = signingConfigs.getByName("debug") - } - } -} - -flutter { - source = "../.." -} diff --git a/android/app/build.gradle.kts.txt b/android/app/build.gradle.kts.txt deleted file mode 100644 index cdca13c..0000000 --- a/android/app/build.gradle.kts.txt +++ /dev/null @@ -1,73 +0,0 @@ -plugins { - id("com.android.application") - id("kotlin-android") - id("dev.flutter.flutter-gradle-plugin") -} - -android { - namespace = "com.lxh.battery_health" - compileSdk = 34 - ndkVersion = flutter.ndkVersion - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = "17" - } - - defaultConfig { - applicationId = "com.lxh.battery_health" - minSdk = flutter.minSdkVersion - targetSdk = 34 - versionCode = flutter.versionCode - versionName = flutter.versionName - multiDexEnabled = true - } - - signingConfigs { - // 如果没有正式签名,可以用 debug 签名代替(测试用) - // 正式发布时请替换为自己的密钥 - getByName("debug") { - // debug 签名已经存在,无需额外配置 - } - create("release") { - // 如果有正式签名,在这里配置 - // keyAlias = "..." - // keyPassword = "..." - // storeFile = file("...") - // storePassword = "..." - } - } - - buildTypes { - debug { - // 🟢 关键:debug 版本包名加 .dev 后缀 - applicationIdSuffix = ".dev" - signingConfig = signingConfigs.getByName("debug") - isDebuggable = true - isMinifyEnabled = false - isShrinkResources = false - } - release { - // release 版本不加后缀,保持原包名 - signingConfig = signingConfigs.getByName("debug") // 若没有正式签名,先用 debug 签名 - isMinifyEnabled = true - isShrinkResources = true - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } -} - -flutter { - source = "../.." -} - -dependencies { - // 无需额外添加 Activity KTX,因为已改用 startActivityForResult -} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c76ece7..c91f718 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -45,6 +45,14 @@ + + + + + + + + diff --git a/android/app/src/main/kotlin/com/lxh/battery_health/MainActivity.kt b/android/app/src/main/kotlin/com/lxh/battery_health/MainActivity.kt index c677d9e..f232060 100644 --- a/android/app/src/main/kotlin/com/lxh/battery_health/MainActivity.kt +++ b/android/app/src/main/kotlin/com/lxh/battery_health/MainActivity.kt @@ -7,6 +7,7 @@ import android.content.IntentFilter import android.content.SharedPreferences import android.net.Uri import android.os.BatteryManager +import android.app.Activity import android.os.Build import android.os.Bundle import android.provider.DocumentsContract @@ -135,7 +136,7 @@ class MainActivity : FlutterActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - if (requestCode == FOLDER_PICKER_REQUEST && resultCode == ComponentActivity.RESULT_OK) { + if (requestCode == FOLDER_PICKER_REQUEST && resultCode == RESULT_OK) { val uri = data?.data if (uri != null) { try { diff --git a/lib/pages/about_page.dart b/lib/pages/about_page.dart index 69d1b8c..999259f 100644 --- a/lib/pages/about_page.dart +++ b/lib/pages/about_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:url_launcher/url_launcher.dart'; class AboutPage extends StatelessWidget { @@ -29,7 +30,7 @@ class AboutPage extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - // 🟢 Logo 图片(替换之前的 Icon) + // Logo Container( width: 120, height: 120, @@ -49,7 +50,6 @@ class AboutPage extends StatelessWidget { ), ), const SizedBox(height: 24), - // APP 名称 const Text( 'MEIZU Battery Healthy', style: TextStyle( @@ -59,7 +59,6 @@ class AboutPage extends StatelessWidget { ), ), const SizedBox(height: 8), - // 版本号 Text( '版本 1.7.0', style: TextStyle( @@ -70,7 +69,6 @@ class AboutPage extends StatelessWidget { ), ), const SizedBox(height: 16), - // 分隔线 Divider( color: Colors.grey.shade300, thickness: 0.5, @@ -78,7 +76,6 @@ class AboutPage extends StatelessWidget { endIndent: 40, ), const SizedBox(height: 16), - // 作者信息 const Text( '专机专配 · 仅针对魅族独家开发', style: TextStyle( @@ -97,9 +94,9 @@ class AboutPage extends StatelessWidget { ), ), const SizedBox(height: 24), - // Gitea 链接 + // 源码链接按钮 InkWell( - onTap: _launchUrl, + onTap: () => _launchUrl(context), // 注意这里传入了 context borderRadius: BorderRadius.circular(12), child: Container( padding: const EdgeInsets.symmetric( @@ -140,7 +137,6 @@ class AboutPage extends StatelessWidget { ), ), const SizedBox(height: 40), - // 底部版本信息 Text( 'Made with ❤️ in Flyme · 2026', style: TextStyle( @@ -156,18 +152,25 @@ class AboutPage extends StatelessWidget { ); } - Future _launchUrl() async { + Future _launchUrl(BuildContext context) async { const url = 'https://git.whitetop.xyz/lxh2875931338/MEIZU-Battery-Healthy'; final uri = Uri.parse(url); try { - if (await canLaunchUrl(uri)) { - await launchUrl(uri, mode: LaunchMode.externalApplication); - } else { - debugPrint('无法打开链接: $url'); - } + // ✅ 直接尝试打开,不再检查 canLaunchUrl + await launchUrl(uri, mode: LaunchMode.externalApplication); } catch (e) { + // 如果打开失败,复制链接并提示 debugPrint('打开链接失败: $e'); + await Clipboard.setData(ClipboardData(text: url)); + if (context.mounted) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('无法自动打开浏览器,链接已复制到剪贴板。'), + duration: Duration(seconds: 3), + ), + ); + } } } } diff --git a/pubspec.lock b/pubspec.lock index 5310969..6f0db42 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + android_intent_plus: + dependency: "direct main" + description: + name: android_intent_plus + sha256: "2329378af63f49b985cb2e110ac784d08374f1e2b1984be77ba9325b1c8cce11" + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.3.1" args: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0fa0cab..2dd2852 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,8 @@ dependencies: flutter_svg: ^2.0.10+1 shared_preferences: ^2.2.0 flutter_markdown: ^0.7.0 - url_launcher: ^6.3.2 + url_launcher: 6.3.2 + android_intent_plus: ^5.2.0 # The following adds the Cupertino Icons font to your application.