Flutter Config toJson/fromJson (#1893)
This commit is contained in:
committed by
GitHub
parent
808587accd
commit
70742b69ec
@@ -11,11 +11,27 @@ class OfflinePunctuationModelConfig {
|
||||
this.provider = 'cpu',
|
||||
this.debug = true});
|
||||
|
||||
factory OfflinePunctuationModelConfig.fromJson(Map<String, dynamic> json) {
|
||||
return OfflinePunctuationModelConfig(
|
||||
ctTransformer: json['ctTransformer'] as String,
|
||||
numThreads: json['numThreads'] as int? ?? 1,
|
||||
provider: json['provider'] as String? ?? 'cpu',
|
||||
debug: json['debug'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OfflinePunctuationModelConfig(ctTransformer: $ctTransformer, numThreads: $numThreads, provider: $provider, debug: $debug)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'ctTransformer': ctTransformer,
|
||||
'numThreads': numThreads,
|
||||
'provider': provider,
|
||||
'debug': debug,
|
||||
};
|
||||
|
||||
final String ctTransformer;
|
||||
final int numThreads;
|
||||
final String provider;
|
||||
@@ -27,11 +43,22 @@ class OfflinePunctuationConfig {
|
||||
required this.model,
|
||||
});
|
||||
|
||||
factory OfflinePunctuationConfig.fromJson(Map<String, dynamic> json) {
|
||||
return OfflinePunctuationConfig(
|
||||
model: OfflinePunctuationModelConfig.fromJson(
|
||||
json['model'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OfflinePunctuationConfig(model: $model)';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'model': model.toJson(),
|
||||
};
|
||||
|
||||
final OfflinePunctuationModelConfig model;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user