61 lines
1.3 KiB
Dart
61 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:otp/otp.dart';
|
|
|
|
class UserServeGooglePage extends StatefulWidget {
|
|
const UserServeGooglePage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<UserServeGooglePage> createState() => _UserServeGooglePageState();
|
|
}
|
|
|
|
class _UserServeGooglePageState extends State<UserServeGooglePage> {
|
|
String code = '000000';
|
|
String secret = 'T4UM3VPYXPALF7M5';
|
|
int remaining = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getCode();
|
|
}
|
|
|
|
void getCode() {
|
|
setState(() {
|
|
remaining = OTP.remainingSeconds();
|
|
|
|
code = OTP.generateTOTPCodeString(
|
|
secret,
|
|
DateTime.now().millisecondsSinceEpoch,
|
|
algorithm: Algorithm.SHA1,
|
|
isGoogle: true,
|
|
);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('谷歌验证器'),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
Text(
|
|
code,
|
|
style: const TextStyle(
|
|
fontSize: 32,
|
|
),
|
|
),
|
|
Text(remaining.toString()),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
getCode();
|
|
},
|
|
child: const Text('刷新密码'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|