import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_pwa_test/Content.dart'; class Login extends StatelessWidget { static const String _password = "SGVsbG9Xb3JsZCE="; Login({Key? key, required this.loginCallback}) : super(key: key); final VoidCallback loginCallback; final GlobalKey _formKey = GlobalKey(); @override Widget build(BuildContext context) { return Center( child: Form( key: _formKey, autovalidateMode: AutovalidateMode.disabled, child: Column( children: [ Container( constraints: const BoxConstraints(maxWidth: 500), child: TextFormField( decoration: const InputDecoration( labelText: "Password", hintText: "Password", alignLabelWithHint: true, border: OutlineInputBorder(), ), validator: (s) { if (s == null) { return "Please provide a value"; } var encoded = base64Encode(utf8.encode(s)); print(encoded); if (encoded != _password) { return "Password is wrong"; } return null; }, ), ), const SizedBox(height: 16.0), ElevatedButton( onPressed: () async { var result = _formKey.currentState?.validate(); if (result == null || !result) { print( "Could not validate password because of an internal error"); return; } loginCallback(); }, child: const Text("Ok"), ) ], ), ), ); } }