json_serializable.dart
json_serializable.dart copied to clipboard
Feature request: FromJson format to local time
Due to the need to display local time in the application
Want to add an option in the configuration file to allow users to choose whether to use local time
Achievable:
- Avoid manually changing to local time every time you use it
- Avoid modifying automatically generated files
Thanks
config:
targets:
$default:
builders:
json_serializable:
options:
parse_local_time: true // default: false
from:
part of 'example.dart';
Person _$PersonFromJson(Map<String, dynamic> json) => Person(
firstName: json['firstName'] as String,
lastName: json['lastName'] as String,
dateOfBirth: json['dateOfBirth'] == null
? null
: DateTime.parse(json['dateOfBirth'] as String),
);
to:
part of 'example.dart';
Person _$PersonFromJson(Map<String, dynamic> json) => Person(
firstName: json['firstName'] as String,
lastName: json['lastName'] as String,
dateOfBirth: json['dateOfBirth'] == null
? null
: DateTime.parse(json['dateOfBirth'] as String).toLocal(),
);