From 2fce1aa0ce2dc93afe33b7553365cebffd3c37ad Mon Sep 17 00:00:00 2001 From: qyy Date: Wed, 30 Nov 2022 11:38:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=BA=93=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImageGallerySaverPlugin.kt | 9 --------- example/android/app/build.gradle | 4 ++++ example/android/settings.gradle | 18 +++++++----------- example/lib/main.dart | 15 +++++++-------- example/test/widget_test.dart | 4 ++-- pubspec.yaml | 2 +- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/android/src/main/kotlin/com/example/imagegallerysaver/ImageGallerySaverPlugin.kt b/android/src/main/kotlin/com/example/imagegallerysaver/ImageGallerySaverPlugin.kt index 18ae02c..49e6a5d 100644 --- a/android/src/main/kotlin/com/example/imagegallerysaver/ImageGallerySaverPlugin.kt +++ b/android/src/main/kotlin/com/example/imagegallerysaver/ImageGallerySaverPlugin.kt @@ -27,15 +27,6 @@ class ImageGallerySaverPlugin : FlutterPlugin, MethodCallHandler { private var applicationContext: Context? = null private var methodChannel: MethodChannel? = null - - companion object { - @JvmStatic - fun registerWith(registrar: Registrar) { - val instance = ImageGallerySaverPlugin() - instance.onAttachedToEngine(registrar.context(), registrar.messenger()) - } - } - override fun onMethodCall(call: MethodCall, result: Result): Unit { when { call.method == "saveImageToGallery" -> { diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index f5ee76a..52f5373 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -28,6 +28,10 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 31 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } sourceSets { main.java.srcDirs += 'src/main/kotlin' } diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14f..f860b76 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,11 @@ include ':app' -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } -} +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -} +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 29f0779..1d8bd29 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:typed_data'; import 'dart:ui' as ui; @@ -38,7 +37,6 @@ class _MyHomePageState extends State { super.initState(); _requestPermission(); - } @override @@ -60,7 +58,7 @@ class _MyHomePageState extends State { ), Container( padding: EdgeInsets.only(top: 15), - child: RaisedButton( + child: ElevatedButton( onPressed: _saveScreen, child: Text("Save Local Image"), ), @@ -69,7 +67,7 @@ class _MyHomePageState extends State { ), Container( padding: EdgeInsets.only(top: 15), - child: RaisedButton( + child: ElevatedButton( onPressed: _getHttp, child: Text("Save network image"), ), @@ -78,7 +76,7 @@ class _MyHomePageState extends State { ), Container( padding: EdgeInsets.only(top: 15), - child: RaisedButton( + child: ElevatedButton( onPressed: _saveVideo, child: Text("Save network video"), ), @@ -87,7 +85,7 @@ class _MyHomePageState extends State { ), Container( padding: EdgeInsets.only(top: 15), - child: RaisedButton( + child: ElevatedButton( onPressed: _saveGif, child: Text("Save Gif to gallery"), ), @@ -113,10 +111,11 @@ class _MyHomePageState extends State { RenderRepaintBoundary boundary = _globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary; ui.Image image = await boundary.toImage(); - ByteData? byteData = await (image.toByteData(format: ui.ImageByteFormat.png)); + ByteData? byteData = + await (image.toByteData(format: ui.ImageByteFormat.png)); if (byteData != null) { final result = - await ImageGallerySaver.saveImage(byteData.buffer.asUint8List()); + await ImageGallerySaver.saveImage(byteData.buffer.asUint8List()); print(result); _toastInfo(result.toString()); } diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 628b972..95fbd2f 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -6,7 +6,7 @@ void main() { testWidgets('Verify Widgets', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(new MyApp()); - final Finder flatButtonPass = find.widgetWithText(RaisedButton, '保存屏幕截图'); + final Finder flatButtonPass = find.widgetWithText(ElevatedButton, '保存屏幕截图'); expect(flatButtonPass, findsOneWidget); }); -} \ No newline at end of file +} diff --git a/pubspec.yaml b/pubspec.yaml index e0206f1..330f3d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: image_gallery_saver description: A new flutter plugin project for save image to gallery, iOS need to add the following keys to your Info.plist file. -version: 1.7.1 +version: 2.0.0 homepage: https://github.com/hui-z/image_gallery_saver environment: