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 backgroundColor: Theme.of(context).primaryColor,
23 extendBodyBehindAppBar: true,
26 backgroundColor: Colors.transparent,
28 icon: Icon(Icons.close),
29 onPressed: () => Navigator.of(context).pop(),
33 alignment: Alignment.center,
35 SingleChildScrollView(
36 child: ConstrainedBox(
37 constraints: BoxConstraints.tightFor(
38 height: MediaQuery.of(context).size.height),
40 padding: const EdgeInsets.all(8.0),
42 mainAxisAlignment: MainAxisAlignment.start,
43 crossAxisAlignment: CrossAxisAlignment.center,
46 padding: const EdgeInsets.fromLTRB(0, 100.0, 0, 30.0),
57 fontWeight: FontWeight.bold),
60 'Check your second factor provider',
62 color: Colors.white38, fontWeight: FontWeight.bold),
65 padding: const EdgeInsets.fromLTRB(0, 50.0, 0, 8.0),
69 controller: _codeController,
70 textAlign: TextAlign.center,
71 decoration: InputDecoration(labelText: 'Code'),
73 onSubmitted: (value) => _submitTfaCode()),
78 alignment: Alignment.bottomCenter,
80 width: MediaQuery.of(context).size.width,
82 onPressed: () => _submitTfaCode(),
83 color: Color(0xFFE47225),
84 child: Text('Continue'),
85 disabledColor: Colors.grey,
96 ProxmoxProgressOverlay(
97 message: 'Verify One-Time password...',
105 Future<void> _submitTfaCode() async {
111 await widget.apiClient!.finishTfaChallenge(_codeController.text);
112 Navigator.of(context).pop(client);
113 } on ProxmoxApiException catch (e) {
116 builder: (context) => ProxmoxApiErrorDialog(
125 builder: (context) => AlertDialog(
126 title: Text('Connection error'),
127 content: Text('Could not establish connection.'),
130 onPressed: () => Navigator.of(context).pop(),
131 child: Text('Close'),