Skip to content

Commit 0ef4364

Browse files
gaetschwartzadsonpleal
authored andcommitted
[shared_preferences] Migrate main package to null-safety (flutter#3526)
Migrates shared_preferences to nnbd. Fixes flutter/flutter#74876. Note: also recreated the android and macos example applications because the macOS app was apparently a copy of the connectivity app and had connectivity_example as its name, the Android app was using the embedding v1.
1 parent 5b3c462 commit 0ef4364

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+436
-286
lines changed

packages/shared_preferences/shared_preferences/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.0.0-nullsafety
2+
3+
* Migrate to null-safety.
4+
5+
**Breaking changes**:
6+
7+
* Setters no longer accept null to mean removing values. If you were previously using `set*(key, null)` for removing, use `remove(key)` instead.
8+
19
## 0.5.13+2
210

311
* Fix outdated links across a number of markdown files ([#3276](https://github.com/flutter/plugins/pull/3276))

packages/shared_preferences/shared_preferences/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ Wraps platform-specific persistent storage for simple data
77
and there is no guarantee that writes will be persisted to disk after
88
returning, so this plugin must not be used for storing critical data.
99

10-
11-
**Please set your constraint to `shared_preferences: '>=0.5.y+x <2.0.0'`**
12-
13-
## Backward compatible 1.0.0 version is coming
14-
The plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.5.y+z`.
15-
Please use `shared_preferences: '>=0.5.y+x <2.0.0'` as your dependency constraint to allow a smoother ecosystem migration.
16-
For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
17-
1810
## Usage
1911
To use this plugin, add `shared_preferences` as a [dependency in your pubspec.yaml file](https://flutter.dev/docs/development/platform-integration/platform-channels).
2012

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 79b49b9e1057f90ebf797725233c6b311722de69
8+
channel: dev
9+
10+
project_type: app
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties

packages/shared_preferences/shared_preferences/example/android/app/build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ if (flutterVersionName == null) {
2222
}
2323

2424
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
2526
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2627

2728
android {
28-
compileSdkVersion 29
29+
compileSdkVersion 30
2930

30-
lintOptions {
31-
disable 'InvalidPackage'
31+
sourceSets {
32+
main.java.srcDirs += 'src/main/kotlin'
3233
}
3334

3435
defaultConfig {
35-
applicationId "io.flutter.plugins.sharedpreferencesexample"
36+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
37+
applicationId "io.flutter.plugins.example"
3638
minSdkVersion 16
37-
targetSdkVersion 28
39+
targetSdkVersion 30
3840
versionCode flutterVersionCode.toInteger()
3941
versionName flutterVersionName
40-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4142
}
4243

4344
buildTypes {
@@ -54,7 +55,5 @@ flutter {
5455
}
5556

5657
dependencies {
57-
testImplementation 'junit:junit:4.12'
58-
androidTestImplementation 'androidx.test:runner:1.1.1'
59-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
58+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
6059
}

packages/shared_preferences/shared_preferences/example/android/app/gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.example">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="io.flutter.plugins.sharedpreferencesexample">
3-
4-
<uses-permission android:name="android.permission.INTERNET"/>
5-
6-
<application android:name="io.flutter.app.FlutterApplication" android:label="shared_preferences_example" android:icon="@mipmap/ic_launcher">
7-
<activity android:name=".EmbeddingV1Activity"
8-
android:launchMode="singleTop"
9-
android:theme="@android:style/Theme.Black.NoTitleBar"
10-
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
11-
android:hardwareAccelerated="true"
12-
android:windowSoftInputMode="adjustResize">
13-
</activity>
14-
<activity android:name="io.flutter.embedding.android.FlutterActivity"
15-
android:theme="@android:style/Theme.Black.NoTitleBar"
16-
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
2+
package="io.flutter.plugins.example">
3+
<application
4+
android:label="example"
5+
android:icon="@mipmap/ic_launcher">
6+
<activity
7+
android:name=".MainActivity"
8+
android:launchMode="singleTop"
9+
android:theme="@style/LaunchTheme"
10+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1711
android:hardwareAccelerated="true"
1812
android:windowSoftInputMode="adjustResize">
13+
<!-- Specifies an Android theme to apply to this Activity as soon as
14+
the Android process has started. This theme is visible to the user
15+
while the Flutter UI initializes. After that, this theme continues
16+
to determine the Window background behind the Flutter UI. -->
17+
<meta-data
18+
android:name="io.flutter.embedding.android.NormalTheme"
19+
android:resource="@style/NormalTheme"
20+
/>
21+
<!-- Displays an Android View that continues showing the launch screen
22+
Drawable until Flutter paints its first frame, then this splash
23+
screen fades out. A splash screen is useful to avoid any visual
24+
gap between the end of Android's launch screen and the painting of
25+
Flutter's first frame. -->
26+
<meta-data
27+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
28+
android:resource="@drawable/launch_background"
29+
/>
1930
<intent-filter>
2031
<action android:name="android.intent.action.MAIN"/>
2132
<category android:name="android.intent.category.LAUNCHER"/>
2233
</intent-filter>
2334
</activity>
24-
<meta-data android:name="flutterEmbedding" android:value="2"/>
35+
<!-- Don't delete the meta-data below.
36+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
37+
<meta-data
38+
android:name="flutterEmbedding"
39+
android:value="2" />
2540
</application>
2641
</manifest>

packages/shared_preferences/shared_preferences/example/android/app/src/main/java/io/flutter/plugins/sharedpreferencesexample/EmbeddingV1Activity.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/shared_preferences/shared_preferences/example/android/app/src/main/java/io/flutter/plugins/sharedpreferencesexample/EmbeddingV1ActivityTest.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/shared_preferences/shared_preferences/example/android/app/src/main/java/io/flutter/plugins/sharedpreferencesexample/FlutterActivityTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.flutter.plugins.example
2+
3+
import io.flutter.embedding.android.FlutterActivity
4+
5+
class MainActivity: FlutterActivity() {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
5+
<!-- Show a splash screen on the activity. Automatically removed when
6+
Flutter draws its first frame -->
7+
<item name="android:windowBackground">@drawable/launch_background</item>
8+
</style>
9+
<!-- Theme applied to the Android Window as soon as the process has started.
10+
This theme determines the color of the Android Window while your
11+
Flutter UI initializes, as well as behind your Flutter UI while its
12+
running.
13+
14+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
15+
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
16+
<item name="android:windowBackground">?android:colorBackground</item>
17+
</style>
18+
</resources>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.example">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>

packages/shared_preferences/shared_preferences/example/android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
buildscript {
2+
ext.kotlin_version = '1.3.50'
23
repositories {
34
google()
45
jcenter()
56
}
67

78
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.4.0'
9+
classpath 'com.android.tools.build:gradle:4.1.0'
10+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
911
}
1012
}
1113

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.useAndroidX=true
33
android.enableJetifier=true
4-
android.enableR8=true
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Fri Jun 23 08:50:38 CEST 2017
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
include ':app'
22

3-
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
3+
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4+
def properties = new Properties()
45

5-
def plugins = new Properties()
6-
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
7-
if (pluginsFile.exists()) {
8-
pluginsFile.withInputStream { stream -> plugins.load(stream) }
9-
}
6+
assert localPropertiesFile.exists()
7+
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
108

11-
plugins.each { name, path ->
12-
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
13-
include ":$name"
14-
project(":$name").projectDir = pluginDirectory
15-
}
9+
def flutterSdkPath = properties.getProperty("flutter.sdk")
10+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11+
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

0 commit comments

Comments
 (0)