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

Migrate sharezone_utils package to null safety #313

Merged
merged 5 commits into from
Sep 30, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,32 @@
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:meta/meta.dart';

/// Version values of the current Android operating system build derived from
/// `android.os.Build.VERSION`.
///
/// See: https://developer.android.com/reference/android/os/Build.VERSION.html
class AndroidDeviceInformation {
AndroidDeviceInformation({
@required this.version,
@required this.board,
@required this.bootloader,
@required this.brand,
@required this.device,
@required this.display,
@required this.fingerprint,
@required this.hardware,
@required this.host,
@required this.id,
@required this.manufacturer,
@required this.model,
@required this.product,
@required List<String> supported32BitAbis,
@required List<String> supported64BitAbis,
@required List<String> supportedAbis,
@required this.tags,
@required this.type,
@required this.isPhysicalDevice,
@required this.androidId,
required this.version,
required this.board,
required this.bootloader,
required this.brand,
required this.device,
required this.display,
required this.fingerprint,
required this.hardware,
required this.host,
required this.id,
required this.manufacturer,
required this.model,
required this.product,
required List<String?> supported32BitAbis,
required List<String?> supported64BitAbis,
required List<String?> supportedAbis,
required this.tags,
required this.type,
required this.isPhysicalDevice,
required this.androidId,
}) : supported32BitAbis = List<String>.unmodifiable(supported32BitAbis),
supported64BitAbis = List<String>.unmodifiable(supported64BitAbis),
supportedAbis = List<String>.unmodifiable(supportedAbis);
Expand All @@ -42,40 +40,40 @@ class AndroidDeviceInformation {
final AndroidBuildVersion version;

/// The name of the underlying board, like "goldfish".
final String board;
final String? board;

/// The system bootloader version number.
final String bootloader;
final String? bootloader;

/// The consumer-visible brand with which the product/hardware will be associated, if any.
final String brand;
final String? brand;

/// The name of the industrial design.
final String device;
final String? device;

/// A build ID string meant for displaying to the user.
final String display;
final String? display;

/// A string that uniquely identifies this build.
final String fingerprint;
final String? fingerprint;

/// The name of the hardware (from the kernel command line or /proc).
final String hardware;
final String? hardware;

/// Hostname.
final String host;
final String? host;

/// Either a changelist number, or a label like "M4-rc20".
final String id;
final String? id;

/// The manufacturer of the product/hardware.
final String manufacturer;
final String? manufacturer;

/// The end-user-visible name for the end product.
final String model;
final String? model;

/// The name of the overall product.
final String product;
final String? product;

/// An ordered list of 32 bit ABIs supported by this device.
final List<String> supported32BitAbis;
Expand All @@ -87,16 +85,16 @@ class AndroidDeviceInformation {
final List<String> supportedAbis;

/// Comma-separated tags describing the build, like "unsigned,debug".
final String tags;
final String? tags;

/// The type of build, like "user" or "eng".
final String type;
final String? type;

/// `false` if the application is running in an emulator, `true` otherwise.
final bool isPhysicalDevice;
final bool? isPhysicalDevice;

/// The Android hardware device ID that is unique between the device + user and app signing.
final String androidId;
final String? androidId;
}

class AndroidBuildVersion {
Expand All @@ -111,25 +109,25 @@ class AndroidBuildVersion {
});

/// The base OS build the product is based on.
final String baseOS;
final String? baseOS;

/// The current development codename, or the string "REL" if this is a release build.
final String codename;
final String? codename;

/// The internal value used by the underlying source control to represent this build.
final String incremental;
final String? incremental;

/// The developer preview revision of a prerelease SDK.
final int previewSdkInt;
final int? previewSdkInt;

/// The user-visible version string.
final String release;
final String? release;

/// The user-visible SDK version of the framework.
///
/// Possible values are defined in: https://developer.android.com/reference/android/os/Build.VERSION_CODES.html
final int sdkInt;
final int? sdkInt;

/// The user-visible security patch level.
final String securityPatch;
final String? securityPatch;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,38 @@
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:meta/meta.dart';

/// Information derived from `UIDevice`.
///
/// See: https://developer.apple.com/documentation/uikit/uidevice
class IosDeviceInformation {
IosDeviceInformation({
@required this.name,
@required this.systemName,
@required this.systemVersion,
@required this.model,
@required this.localizedModel,
@required this.identifierForVendor,
@required this.isPhysicalDevice,
@required this.utsname,
required this.name,
required this.systemName,
required this.systemVersion,
required this.model,
required this.localizedModel,
required this.identifierForVendor,
required this.isPhysicalDevice,
required this.utsname,
});

/// Device name.
final String name;
final String? name;

/// The name of the current operating system.
final String systemName;
final String? systemName;

/// The current operating system version.
final String systemVersion;
final String? systemVersion;

/// Device model.
final String model;
final String? model;

/// Localized name of the device model.
final String localizedModel;
final String? localizedModel;

/// Unique UUID value identifying the current device.
final String identifierForVendor;
final String? identifierForVendor;

/// `false` if the application is running in a simulator, `true` otherwise.
final bool isPhysicalDevice;
Expand All @@ -52,25 +50,25 @@ class IosDeviceInformation {
/// See http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html for details.
class IosUtsname {
IosUtsname({
@required this.sysname,
@required this.nodename,
@required this.release,
@required this.version,
@required this.machine,
required this.sysname,
required this.nodename,
required this.release,
required this.version,
required this.machine,
});

/// Operating system name.
final String sysname;
final String? sysname;

/// Network node name.
final String nodename;
final String? nodename;

/// Release level.
final String release;
final String? release;

/// Version level.
final String version;
final String? version;

/// Hardware type (e.g. 'iPhone7,1' for iPhone 6 Plus).
final String machine;
final String? machine;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:device_info/device_info.dart'
import 'package:device_info_plus/device_info_plus.dart'
hide AndroidBuildVersion, IosUtsname;
import 'package:flutter/cupertino.dart';

Expand Down Expand Up @@ -86,7 +86,7 @@ class MobileDeviceInformationRetreiver extends DeviceInformationRetreiver {
/// 30 - v11 - Android11\
///
/// Source: https://source.android.com/setup/start/build-numbers
Future<int> androidSdkInt() async {
Future<int?> androidSdkInt() async {
final info = await androidInfo;
return info.version.sdkInt;
}
Expand Down Expand Up @@ -116,14 +116,14 @@ class MobileDeviceInformationRetreiver extends DeviceInformationRetreiver {
@visibleForTesting
class MockMobileDeviceInformationRetreiver
implements MobileDeviceInformationRetreiver {
int _androidSdkInt;
int? _androidSdkInt;

@override
Future<AndroidDeviceInformation> get androidInfo =>
throw UnimplementedError();

@override
Future<int> androidSdkInt() async {
Future<int?> androidSdkInt() async {
return _androidSdkInt;
}

Expand Down
30 changes: 14 additions & 16 deletions lib/sharezone_utils/lib/src/dimensions/dimensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class Dimensions {
}

EdgeInsets get dialogPaddingDimensions {
if (isDesktopModus == false)
if (isDesktopModus == false) {
return EdgeInsets.zero;
else {
return EdgeInsets.symmetric(
horizontal: 32,
vertical: sizeByPixels(
height,
min: 0,
max: 64,
));
}

return EdgeInsets.symmetric(
horizontal: 32,
vertical: _sizeByPixels(
height,
max: 64,
),
);
}

double get dialogBorderRadiusDimensions {
Expand All @@ -56,19 +56,17 @@ class Dimensions {
}
}

double sizeByPixels(
double _sizeByPixels(
double pixels, {
double min,
double max,
double factor,
double breakpoint,
required double max,
double min = 0,
}) {
double value = pow(100 * e, (pixels / 300) - 1);
final value = pow(100 * e, (pixels / 300) - 1);
if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
return value as double;
}
6 changes: 3 additions & 3 deletions lib/sharezone_utils/lib/src/platform/platform_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class PlatformCheck {
}

@visibleForTesting
static void setCurrentPlatformForTesting(Platform currentPlatform) {
static void setCurrentPlatformForTesting(Platform? currentPlatform) {
_mockedCurrentPlatformForTesting = currentPlatform;
}

static Platform _mockedCurrentPlatformForTesting;
static Platform? _mockedCurrentPlatformForTesting;

static bool get isAndroid => currentPlatform == Platform.android;
static bool get isIOS => currentPlatform == Platform.iOS;
Expand Down Expand Up @@ -131,7 +131,7 @@ class PlatformCheckVariant extends TestVariant<Platform> {

/// This method behaviour is copied from TargetPlatformVariant
@override
Future<void> tearDown(Platform value, Platform memento) async {
Future<void> tearDown(Platform value, Platform? memento) async {
// Why setting [memento] as current platform? See in [TestVariant.tearDown]
PlatformCheck.setCurrentPlatformForTesting(memento);
}
Expand Down
Loading