Skip to content

Commit

Permalink
图片库升级
Browse files Browse the repository at this point in the history
  • Loading branch information
qyy committed Nov 30, 2022
1 parent 7d99271 commit 2fce1aa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" -> {
Expand Down
4 changes: 4 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
18 changes: 7 additions & 11 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 7 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

Expand Down Expand Up @@ -38,7 +37,6 @@ class _MyHomePageState extends State<MyHomePage> {
super.initState();

_requestPermission();

}

@override
Expand All @@ -60,7 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.only(top: 15),
child: RaisedButton(
child: ElevatedButton(
onPressed: _saveScreen,
child: Text("Save Local Image"),
),
Expand All @@ -69,7 +67,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.only(top: 15),
child: RaisedButton(
child: ElevatedButton(
onPressed: _getHttp,
child: Text("Save network image"),
),
Expand All @@ -78,7 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.only(top: 15),
child: RaisedButton(
child: ElevatedButton(
onPressed: _saveVideo,
child: Text("Save network video"),
),
Expand All @@ -87,7 +85,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.only(top: 15),
child: RaisedButton(
child: ElevatedButton(
onPressed: _saveGif,
child: Text("Save Gif to gallery"),
),
Expand All @@ -113,10 +111,11 @@ class _MyHomePageState extends State<MyHomePage> {
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());
}
Expand Down
4 changes: 2 additions & 2 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 2fce1aa

Please sign in to comment.