Skip to content

Commit

Permalink
fix: Better handling of durations. Fixes #4.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyost committed Oct 28, 2024
1 parent 5578a76 commit 61b58f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/model/totp/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension JsonTotp on Totp {
encryptedData: encryptedData,
algorithm: data[Totp.kAlgorithmKey] is! String ? null : Algorithm.fromString(data[Totp.kAlgorithmKey]),
digits: data[Totp.kDigitsKey] is! int ? null : data[Totp.kDigitsKey],
validity: data[Totp.kValidityKey] is! int ? null : data[Totp.kValidityKey],
validity: data[Totp.kValidityKey] is! int ? null : Duration(seconds: data[Totp.kValidityKey]),
);
}

Expand All @@ -27,7 +27,7 @@ extension JsonTotp on Totp {
...encryptedData.toJson(),
if (algorithm != null) Totp.kAlgorithmKey: algorithm!.name,
if (digits != null) Totp.kDigitsKey: digits,
if (validity != null) Totp.kValidityKey: validity,
if (validity != null) Totp.kValidityKey: validity!.inSeconds,
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/pages/totp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class _TotpPageState extends ConsumerState<TotpPage> with BrightnessListener {
),
ListTilePadding(
child: TextFormField(
initialValue: validity?.toString(),
initialValue: validity?.inSeconds.toString(),
onChanged: (value) {
int? validity = int.tryParse(value);
setState(() => this.validity = validity == null ? null : Duration(seconds: validity));
Expand All @@ -306,7 +306,7 @@ class _TotpPageState extends ConsumerState<TotpPage> with BrightnessListener {
decoration: FormLabelWithIcon(
icon: Icons.schedule,
text: translations.totp.page.validity,
hintText: Totp.kDefaultValidity.toString(),
hintText: Totp.kDefaultValidity.inSeconds.toString(),
),
validator: validateValidity,
enabled: enabled,
Expand Down

0 comments on commit 61b58f4

Please sign in to comment.