1 import 'package:flutter/material.dart';
2 import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart';
3 import 'package:proxmox_login_manager/proxmox_login_form.dart';
5 class ProxmoxTfaForm extends StatefulWidget {
6 final ProxmoxApiClient apiClient;
8 const ProxmoxTfaForm({Key key, this.apiClient}) : super(key: key);
11 _ProxmoxTfaFormState createState() => _ProxmoxTfaFormState();
14 class _ProxmoxTfaFormState extends State<ProxmoxTfaForm> {
15 final TextEditingController _codeController = TextEditingController();
16 bool _isLoading = false;
18 Widget build(BuildContext context) {
20 data: ThemeData.dark().copyWith(accentColor: Color(0xFFE47225)),
22 color: Theme.of(context).primaryColor,
24 alignment: Alignment.center,
26 SingleChildScrollView(
27 child: ConstrainedBox(
28 constraints: BoxConstraints.tightFor(
29 height: MediaQuery.of(context).size.height),
31 padding: const EdgeInsets.all(8.0),
33 mainAxisAlignment: MainAxisAlignment.start,
34 crossAxisAlignment: CrossAxisAlignment.center,
37 padding: const EdgeInsets.fromLTRB(0, 100.0, 0, 30.0),
48 fontWeight: FontWeight.bold),
51 'Check your second factor provider',
53 color: Colors.white38, fontWeight: FontWeight.bold),
56 padding: const EdgeInsets.fromLTRB(0, 50.0, 0, 8.0),
60 controller: _codeController,
61 textAlign: TextAlign.center,
62 decoration: InputDecoration(labelText: 'Code'),
64 onSubmitted: (value) => _submitTfaCode()),
69 alignment: Alignment.bottomCenter,
71 width: MediaQuery.of(context).size.width,
73 onPressed: () => _submitTfaCode(),
74 color: Color(0xFFE47225),
75 child: Text('Continue'),
76 disabledColor: Colors.grey,
87 ProxmoxProgressOverlay(
88 message: 'Verify One-Time password...',
96 Future<void> _submitTfaCode() async {
102 await widget.apiClient.finishTfaChallenge(_codeController.text);
103 Navigator.of(context).pop(client);
104 } on ProxmoxApiException catch (e) {
107 builder: (context) => ProxmoxApiErrorDialog(
116 builder: (context) => AlertDialog(
117 title: Text('Connection error'),
118 content: Text('Could not establish connection.'),
121 onPressed: () => Navigator.of(context).pop(),
122 child: Text('Close'),