import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; class SettingsPage extends StatefulWidget { const SettingsPage({Key? key}) : super(key: key); @override State createState() => _SettingsPageState(); } class _SettingsPageState extends State { late TextEditingController _controllerHost; late TextEditingController _controllerUser; late TextEditingController _controllerPwd; @override void initState() { super.initState(); _controllerHost = TextEditingController(); _controllerUser = TextEditingController(); _controllerPwd = TextEditingController(); const storage = FlutterSecureStorage(); storage .read(key: "host") .then((value) => _controllerHost.text = value ?? ""); storage .read(key: "user") .then((value) => _controllerUser.text = value ?? ""); storage.read(key: "pwd").then((value) => _controllerPwd.text = value ?? ""); } @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(5), child: Column( children: [ const SizedBox( height: 10, ), TextField( decoration: const InputDecoration( border: OutlineInputBorder(), labelText: "host"), controller: _controllerHost, ), const SizedBox( height: 5, ), TextField( decoration: const InputDecoration( border: OutlineInputBorder(), labelText: "user"), controller: _controllerUser, ), const SizedBox( height: 5, ), TextField( obscureText: true, decoration: const InputDecoration( border: OutlineInputBorder(), labelText: "password"), controller: _controllerPwd, ), const SizedBox( height: 5, ), TextButton( onPressed: () { const storage = FlutterSecureStorage(); storage.write(key: "host", value: _controllerHost.value.text); storage.write(key: "user", value: _controllerUser.value.text); storage.write(key: "pwd", value: _controllerPwd.value.text); }, child: const Text("Save")) ], ), ); } }