Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/desktop_drop/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.8.0

**BREAKING CHANGE**

* [Android] Migrate to built-in Kotlin. Android host apps must use Android Gradle Plugin 9 or later.

## 0.7.1

* update worksapce
Expand Down
11 changes: 6 additions & 5 deletions packages/desktop_drop/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

rootProject.allprojects {
repositories {
Expand All @@ -37,10 +36,6 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand All @@ -50,6 +45,12 @@ android {
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
13 changes: 7 additions & 6 deletions packages/desktop_drop/example/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
// The Flutter Gradle Plugin must be applied after the Android Gradle plugin.
id("dev.flutter.flutter-gradle-plugin")
}

Expand All @@ -15,10 +14,6 @@ android {
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.example.desktop_drop_example"
Expand All @@ -39,6 +34,12 @@ android {
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
}
}

flutter {
source = "../.."
}
4 changes: 4 additions & 0 deletions packages/desktop_drop/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
# Enable AGP 9 built-in Kotlin for this example.
android.builtInKotlin=true
# Keep Flutter's current legacy AGP DSL compatibility while it migrates.
android.newDsl=false
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
4 changes: 2 additions & 2 deletions packages/desktop_drop/example/android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pluginManagement {

plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.0" apply false
id("org.jetbrains.kotlin.android") version "1.8.22" apply false
id("com.android.application") version "9.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
}

include(":app")
98 changes: 52 additions & 46 deletions packages/desktop_drop/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class MyApp extends StatelessWidget {
bool grantedPermission = await DesktopDrop.instance
.startAccessingSecurityScopedResource(bookmark: appleBookmark);

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"file permission :" + grantedPermission.toString(),
)));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("file permission :" + grantedPermission.toString()),
),
);
}

var file = File(path);
Expand All @@ -45,12 +46,14 @@ class MyApp extends StatelessWidget {
var fileSize = contents.length;

if (bookmarkEnable) {
await DesktopDrop.instance
.stopAccessingSecurityScopedResource(bookmark: appleBookmark);
await DesktopDrop.instance.stopAccessingSecurityScopedResource(
bookmark: appleBookmark,
);
}

final snackBar =
SnackBar(content: Text('file size:' + fileSize.toString()));
final snackBar = SnackBar(
content: Text('file size:' + fileSize.toString()),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} catch (e) {
final snackBar = SnackBar(content: Text('error:' + e.toString()));
Expand All @@ -62,9 +65,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
appBar: AppBar(title: const Text('Plugin example app')),
body: Wrap(
direction: Axis.horizontal,
runSpacing: 8,
Expand All @@ -77,33 +78,31 @@ class MyApp extends StatelessWidget {
const ExampleDragTarget(),
const ExampleDragTarget(),
if (UniversalPlatform.isMacOS)
StatefulBuilder(builder: (context, setState) {
return Column(
children: [
const Text(
"Test Apple Bookmark\n1 drag file \n2 save the bookmark,\n3 restart app\n4 choice test button",
),
TextButton(
onPressed: () async {
loadFile(context, true);
return;
},
child: const Text(
"with applemark, suc",
StatefulBuilder(
builder: (context, setState) {
return Column(
children: [
const Text(
"Test Apple Bookmark\n1 drag file \n2 save the bookmark,\n3 restart app\n4 choice test button",
),
TextButton(
onPressed: () async {
loadFile(context, true);
return;
},
child: const Text("with applemark, suc"),
),
),
TextButton(
onPressed: () async {
loadFile(context, false);
return;
},
child: const Text(
"without applemark, err",
TextButton(
onPressed: () async {
loadFile(context, false);
return;
},
child: const Text("without applemark, err"),
),
),
],
);
}),
],
);
},
),
],
),
),
Expand All @@ -129,11 +128,13 @@ class _ExampleDragTargetState extends State<ExampleDragTarget> {
Future<void> printFiles(List<DropItem> files, [int depth = 0]) async {
debugPrint(' |' * depth);
for (final file in files) {
debugPrint(' |' * depth +
'> ${file.path} ${file.name}'
' ${await file.lastModified()}'
' ${await file.length()}'
' ${file.mimeType}');
debugPrint(
' |' * depth +
'> ${file.path} ${file.name}'
' ${await file.lastModified()}'
' ${await file.length()}'
' ${file.mimeType}',
);
if (file is DropItemDirectory) {
printFiles(file.children, depth + 1);
}
Expand Down Expand Up @@ -195,8 +196,9 @@ class _ExampleDragTargetState extends State<ExampleDragTarget> {
Map<String, String> data = {};
data["path"] = dropFiles[0].path;

String bookmark =
base64.encode(dropFiles[0].extraAppleBookmark!);
String bookmark = base64.encode(
dropFiles[0].extraAppleBookmark!,
);
data["apple-bookmark"] = bookmark;

String jsonStr = json.encode(data);
Expand All @@ -205,16 +207,20 @@ class _ExampleDragTargetState extends State<ExampleDragTarget> {
await SharedPreferences.getInstance();
prefs.setString("apple-bookmark", jsonStr);

ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Save Suc, restart app, and Test Apple Bookmark')));
'Save Suc, restart app, and Test Apple Bookmark',
),
),
);
},
child: const Text(
'save bookmark',
style: TextStyle(fontSize: 14),
),
),
)
),
],
),
),
Expand Down
12 changes: 6 additions & 6 deletions packages/desktop_drop/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.7.1"
version: "0.8.0"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -224,13 +224,13 @@ packages:
source: hosted
version: "2.5.2"
shared_preferences_android:
dependency: transitive
dependency: "direct main"
description:
name: shared_preferences_android
sha256: a768fc8ede5f0c8e6150476e14f38e2417c0864ca36bb4582be8e21925a03c22
sha256: "0634e64bd719f89c012f392938e173521f535d3ecaf66558fa94a056d22b5cc7"
url: "https://pub.dev"
source: hosted
version: "2.4.6"
version: "2.4.27"
shared_preferences_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -365,5 +365,5 @@ packages:
source: hosted
version: "1.1.0"
sdks:
dart: ">=3.10.0-0 <4.0.0"
flutter: ">=3.24.0"
dart: ">=3.12.0 <4.0.0"
flutter: ">=3.44.0"
5 changes: 3 additions & 2 deletions packages/desktop_drop/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ publish_to: 'none'
# sdk: ">=2.12.0 <3.0.0"

environment:
sdk: ">=2.13.0 <3.0.0"
flutter: ">=1.20.0"
sdk: ^3.12.0
flutter: ">=3.44.0"

dependencies:
flutter:
Expand All @@ -19,6 +19,7 @@ dependencies:
cross_file: ^0.3.2
cupertino_icons: ^1.0.2
shared_preferences: ^2.2.3
shared_preferences_android: ^2.4.27
universal_platform:

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop_drop/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: desktop_drop
resolution: workspace
description: A plugin which allows user dragging files to your flutter desktop applications.
version: 0.7.1
version: 0.8.0
homepage: https://github.com/MixinNetwork/flutter-plugins/tree/main/packages/desktop_drop

environment:
Expand Down
Loading