Skip to content

Commit aa10ce7

Browse files
fix(package_info_plus): data serialization converts installTime to String instead of DateTime (#3464)
Co-authored-by: Miguel Beltran <m@beltran.work>
1 parent dab9207 commit aa10ce7

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

packages/package_info_plus/package_info_plus/example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>11.0</string>
24+
<string>12.0</string>
2525
</dict>
2626
</plist>

packages/package_info_plus/package_info_plus/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
97C146E61CF9000F007C117D /* Project object */ = {
216216
isa = PBXProject;
217217
attributes = {
218-
LastUpgradeCheck = 1300;
218+
LastUpgradeCheck = 1510;
219219
ORGANIZATIONNAME = "";
220220
TargetAttributes = {
221221
331C8080294A63A400263BE5 = {

packages/package_info_plus/package_info_plus/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1300"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

packages/package_info_plus/package_info_plus/example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Flutter
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

packages/package_info_plus/package_info_plus/lib/package_info_plus.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class PackageInfo {
221221
'version': version,
222222
if (buildSignature.isNotEmpty) 'buildSignature': buildSignature,
223223
if (installerStore?.isNotEmpty ?? false) 'installerStore': installerStore,
224-
if (installTime != null) 'installTime': installTime
224+
if (installTime != null) 'installTime': installTime!.toIso8601String(),
225225
};
226226
}
227227

packages/package_info_plus/package_info_plus/test/package_info_test.dart

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
6+
57
import 'package:flutter/services.dart';
68
import 'package:flutter_test/flutter_test.dart';
79
import 'package:package_info_plus/package_info_plus.dart';
@@ -155,7 +157,7 @@ void main() {
155157
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
156158
'version': '1.1',
157159
'buildNumber': '2',
158-
'installTime': now,
160+
'installTime': now.toIso8601String(),
159161
});
160162

161163
final nextWeek = now.add(const Duration(days: 7));
@@ -176,7 +178,53 @@ void main() {
176178
'buildNumber': '2',
177179
'buildSignature': 'deadbeef',
178180
'installerStore': 'testflight',
179-
'installTime': nextWeek,
181+
'installTime': nextWeek.toIso8601String(),
182+
});
183+
});
184+
185+
test('data supports null values', () async {
186+
PackageInfo.setMockInitialValues(
187+
appName: 'mock_package_info_example',
188+
packageName: 'io.flutter.plugins.mockpackageinfoexample',
189+
version: '1.1',
190+
buildNumber: '2',
191+
buildSignature: '',
192+
installerStore: null,
193+
installTime: null,
194+
);
195+
final info1 = await PackageInfo.fromPlatform();
196+
expect(info1.data, {
197+
'appName': 'mock_package_info_example',
198+
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
199+
'version': '1.1',
200+
'buildNumber': '2',
201+
});
202+
});
203+
204+
test('data can be converted to JSON and back', () async {
205+
PackageInfo.setMockInitialValues(
206+
appName: 'mock_package_info_example',
207+
packageName: 'io.flutter.plugins.mockpackageinfoexample',
208+
version: '1.1',
209+
buildNumber: '2',
210+
buildSignature: 'signature',
211+
installerStore: 'store',
212+
installTime: now,
213+
);
214+
final info1 = await PackageInfo.fromPlatform();
215+
216+
// Convert to Json and back to Map
217+
final jsonData = jsonEncode(info1.data);
218+
final parsedData = jsonDecode(jsonData);
219+
220+
expect(parsedData, {
221+
'appName': 'mock_package_info_example',
222+
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
223+
'version': '1.1',
224+
'buildNumber': '2',
225+
'buildSignature': 'signature',
226+
'installerStore': 'store',
227+
'installTime': now.toIso8601String(),
180228
});
181229
});
182230
}

0 commit comments

Comments
 (0)