Skip to content

Commit

Permalink
Revert "null safety migration" for stable release
Browse files Browse the repository at this point in the history
This reverts commit e739c20.
pmundt committed May 29, 2021
1 parent 235f9cb commit 3740e6a
Showing 8 changed files with 47 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.4+1

- Revert null-safety changes from stable release to satisfy SDK constraints

## 0.1.4

- Support VINs with 2-character manufacturer IDs in their WMI (reported by @huangkaichang, issue #7)
2 changes: 1 addition & 1 deletion example/vin_decoder_example.dart
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ void main() async {
print("Model year is " + vin.modelYear());
print("Serial number is " + vin.serialNumber());
print("Assembly plant is " + vin.assemblyPlant());
print("Manufacturer is " + vin.getManufacturer()!);
print("Manufacturer is " + vin.getManufacturer());
print("Year is " + vin.getYear().toString());
print("Region is " + vin.getRegion());
print("VIN string is " + vin.toString());
38 changes: 19 additions & 19 deletions lib/src/nhtsa_model.dart
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ import 'package:http/http.dart' as http;
import 'dart:convert';

class NHTSAResult {
String? value;
String? valueId;
String? variable;
int? variableId;
String value;
String valueId;
String variable;
int variableId;

NHTSAResult({this.value, this.valueId, this.variable, this.variableId});

@@ -24,10 +24,10 @@ class NHTSAResult {
}

class NHTSAVehicleInfo {
int? count;
String? message;
String? searchCriteria;
List<NHTSAResult>? results;
int count;
String message;
String searchCriteria;
List<NHTSAResult> results;

NHTSAVehicleInfo(
{this.count, this.message, this.searchCriteria, this.results});
@@ -37,10 +37,10 @@ class NHTSAVehicleInfo {
message = json['Message'];
searchCriteria = json['SearchCriteria'];
if (json['Results'] != null) {
results = [];
results = List<NHTSAResult>();
json['Results'].forEach((v) {
if (v['Value'] != null) {
results!.add(NHTSAResult.fromJson(v));
results.add(NHTSAResult.fromJson(v));
}
});
}
@@ -54,16 +54,16 @@ class NHTSAVehicleInfo {
ExtendedVehicleInfo toExtendedVehicleInfo() {
final ExtendedVehicleInfo info = ExtendedVehicleInfo();

results!.forEach((f) {
results.forEach((f) {
switch (f.variable) {
case "Vehicle Type":
info.vehicleType = normalizeStringValue(f.value!);
info.vehicleType = normalizeStringValue(f.value);
break;
case "Make":
info.make = normalizeStringValue(f.value!);
info.make = normalizeStringValue(f.value);
break;
case "Model":
info.model = normalizeStringValue(f.value!);
info.model = normalizeStringValue(f.value);
break;
}
});
@@ -78,12 +78,12 @@ class NHTSAVehicleInfo {
}

class ExtendedVehicleInfo {
String? make;
String? model;
String? vehicleType;
String make;
String model;
String vehicleType;

static Future<ExtendedVehicleInfo?> getExtendedVehicleInfo(String vin) async {
var path = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVin/' +
static Future<ExtendedVehicleInfo> getExtendedVehicleInfo(String vin) async {
var path = 'https://vpic.nhtsa.dot.gov/api//vehicles/DecodeVin/' +
vin +
'?format=json';
final response = await http.get(Uri.parse(path));
20 changes: 11 additions & 9 deletions lib/src/vin_decoder_base.dart
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import 'manufacturers.dart';
import 'nhtsa_model.dart';
import 'year_map.dart';

import 'package:meta/meta.dart';

class VIN {
/// The VIN that the class was instantiated with.
final String number;
@@ -17,16 +19,16 @@ class VIN {

/// Try to obtain extended information for the VIN from the NHTSA database.
final bool extended;
ExtendedVehicleInfo? _info;
ExtendedVehicleInfo _info;

VIN({required this.number, this.extended = false})
VIN({@required this.number, this.extended = false})
: wmi = normalize(number).substring(0, 3),
vds = normalize(number).substring(3, 9),
vis = normalize(number).substring(9, 17);

/// Carry out VIN validation. A valid [number] must be 17 characters long
/// and contain only valid alphanumeric characters.
bool valid([String? number]) {
bool valid([String number]) {
String value = normalize(number != null ? number : this.number);
return RegExp(r"^[a-zA-Z0-9]+$").hasMatch(value) && value.length == 17;
}
@@ -36,7 +38,7 @@ class VIN {
number.toUpperCase().replaceAll('-', '');

/// Obtain the encoded manufacturing year in YYYY format.
int? getYear() {
int getYear() {
return yearMap[modelYear()];
}

@@ -64,7 +66,7 @@ class VIN {
}

/// Get the full name of the vehicle manufacturer as defined by the [wmi].
String? getManufacturer() {
String getManufacturer() {
// Check for the standard case - a 3 character WMI
if (manufacturers.containsKey(this.wmi)) {
return manufacturers[this.wmi];
@@ -83,7 +85,7 @@ class VIN {
/// Returns the checksum for the VIN. Note that in the case of the EU region
/// checksums are not implemented, so this becomes a no-op. More information
/// is provided in ISO 3779:2009.
String? getChecksum() {
String getChecksum() {
return (getRegion() != "EU") ? normalize(this.number)[8] : null;
}

@@ -105,21 +107,21 @@ class VIN {

/// Get the Make of the vehicle from the NHTSA database if [extended] mode
/// is enabled.
Future<String?> getMakeAsync() async {
Future<String> getMakeAsync() async {
await _fetchExtendedVehicleInfo();
return this._info?.make;
}

/// Get the Model of the vehicle from the NHTSA database if [extended] mode
/// is enabled.
Future<String?> getModelAsync() async {
Future<String> getModelAsync() async {
await _fetchExtendedVehicleInfo();
return this._info?.model;
}

/// Get the Vehicle Type from the NHTSA database if [extended] mode is
/// enabled.
Future<String?> getVehicleTypeAsync() async {
Future<String> getVehicleTypeAsync() async {
await _fetchExtendedVehicleInfo();
return this._info?.vehicleType;
}
1 change: 1 addition & 0 deletions lib/vin_decoder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// Support for VIN parsing, validation, and generation.
// @dart=2.9

library vin_decoder;

9 changes: 5 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -3,17 +3,18 @@ description:
Dart library for working with Vehicle Identification Numbers (VINs) based on ISO 3779:2009 and
World Manufacturer Identifiers (WMIs) based on ISO 3780:2009, enriched by NHTSA data.

version: 0.1.4
version: 0.1.4+1
repository: https://github.com/adaptant-labs/vin-decoder-dart
issue_tracker: https://github.com/adaptant-labs/vin-decoder-dart/issues

environment:
sdk: '>=2.1.0 <3.0.0'

dependencies:
basic_utils: ^3.1.0
http: ^0.13.3
meta: ^1.4.0
basic_utils: ^2.7.1
http: ^0.12.2
random_string: ^2.1.0

dev_dependencies:
test: ^1.17.5
test: ^1.15.7
22 changes: 5 additions & 17 deletions test/vin_decoder_test.dart
Original file line number Diff line number Diff line change
@@ -3,11 +3,7 @@ import 'package:test/test.dart';

void main() {
group('EU VIN Test', () {
late VIN vin;

setUp(() {
vin = VIN(number: 'WP0ZZZ99ZTS392124');
});
final vin = VIN(number: 'WP0ZZZ99ZTS392124');

test('Validity Test', () {
expect(vin.valid(), isTrue);
@@ -23,11 +19,7 @@ void main() {
});

group('AS VIN Test', () {
late VIN vin;

setUp(() {
vin = VIN(number: 'JS1VX51L7X2175460');
});
final vin = VIN(number: 'JS1VX51L7X2175460');

test('Validity Test', () {
expect(vin.valid(), isTrue);
@@ -39,13 +31,9 @@ void main() {
});

group('2-character WMI Manufacturer Test', () {
late VIN vin;

setUp(() {
// Here the first 2 characters refer to the manufacturer, with the 3rd
// representing the class of vehicle specific to that manufacturer.
vin = VIN(number: '5TENL42N94Z436445');
});
// Here the first 2 characters refer to the manufacturer, with the 3rd
// representing the class of vehicle specific to that manufacturer.
final vin = VIN(number: '5TENL42N94Z436445');

test('Validity Test', () {
expect(vin.valid(), isTrue);
2 changes: 1 addition & 1 deletion test/vin_generator_test.dart
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import 'package:test/test.dart';
void main() {
group('VIN Generator Test', () {
VINGenerator generator;
late VIN vin;
VIN vin;

setUp(() {
generator = VINGenerator();

0 comments on commit 3740e6a

Please sign in to comment.