Trying to generate a QrImage
that uses a string generated using 'dart-otp'.
Here is my code.
FutureBuilder(
future: getUserAttribute(),
builder: (context, snapshot) {
if (snapshot.hasData) {
String secret = snapshot.data.toString();
final qrData = OTP.generateTOTPCodeString(
secret,
DateTime.now().millisecondsSinceEpoch,
interval: 30,
);
safePrint(qrData);
safePrint(OTP.remainingSeconds());
return QrImage(
data: qrData,
size: 300.0,
);
} else {
return const CircularProgressIndicator();
}
},
),
getUserAttribute()
is just an async function that returns the current user's email address.
Although the OTP/TOTP generator interval should default to 30 seconds, according to docs, I've explicitly passed the same as a parameter as this is where I am having my problem. Specifically, when I check the second safePrint()
on the console, it never starts at 30 seconds. It starts anywhere between 1~29 seconds and only after it counts down to 0 for the first time, it correctly resets to 30 seconds.
I've played around with the DateTime.now()
, but did not solve.
What am I doing wrong here?