Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(package_info_plus): data serialization converts installTime to String instead of DateTime #3464

Merged
merged 8 commits into from
Feb 6, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class PackageInfo {
'version': version,
if (buildSignature.isNotEmpty) 'buildSignature': buildSignature,
if (installerStore?.isNotEmpty ?? false) 'installerStore': installerStore,
if (installTime != null) 'installTime': installTime
if (installTime != null) 'installTime': installTime!.toIso8601String(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -155,7 +157,7 @@ void main() {
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
'version': '1.1',
'buildNumber': '2',
'installTime': now,
'installTime': now.toIso8601String(),
});

final nextWeek = now.add(const Duration(days: 7));
Expand All @@ -176,7 +178,53 @@ void main() {
'buildNumber': '2',
'buildSignature': 'deadbeef',
'installerStore': 'testflight',
'installTime': nextWeek,
'installTime': nextWeek.toIso8601String(),
});
});

test('data supports null values', () async {
PackageInfo.setMockInitialValues(
appName: 'mock_package_info_example',
packageName: 'io.flutter.plugins.mockpackageinfoexample',
version: '1.1',
buildNumber: '2',
buildSignature: '',
installerStore: null,
installTime: null,
);
final info1 = await PackageInfo.fromPlatform();
expect(info1.data, {
'appName': 'mock_package_info_example',
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
'version': '1.1',
'buildNumber': '2',
});
});

test('data can be converted to JSON and back', () async {
PackageInfo.setMockInitialValues(
appName: 'mock_package_info_example',
packageName: 'io.flutter.plugins.mockpackageinfoexample',
version: '1.1',
buildNumber: '2',
buildSignature: 'signature',
installerStore: 'store',
installTime: now,
);
final info1 = await PackageInfo.fromPlatform();

// Convert to Json and back to Map
final jsonData = jsonEncode(info1.data);
final parsedData = jsonDecode(jsonData);

expect(parsedData, {
'appName': 'mock_package_info_example',
'packageName': 'io.flutter.plugins.mockpackageinfoexample',
'version': '1.1',
'buildNumber': '2',
'buildSignature': 'signature',
'installerStore': 'store',
'installTime': now.toIso8601String(),
});
});
}
Loading