import 'package:flutter/material.dart';
import 'package:readwritegfg/credpage.dart';
import 'package:readwritegfg/readwrite.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
String username = "Username saved by user will be visible here";
String userPass = "Password saved by user will be visible here";
String readName = "";
String readPass = "";
Future<void> getCred() async {
ReadWrite read = ReadWrite();
readName = await read.readTextFile('username.txt');
readPass = await read.readTextFile('userPass.txt');
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightBlue,
title: const Text(
"Saved Credentials",
style: TextStyle(fontSize: 40),
),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Text(
"Username",
style: TextStyle(fontSize: 30, color: Colors.green.shade900),
),
Text(
username,
style: TextStyle(fontSize: 30, color: Colors.orange.shade900),
),
const SizedBox(
height: 50,
),
Text(
"Password",
style: TextStyle(fontSize: 30, color: Colors.green.shade900),
),
Text(
userPass,
style: TextStyle(fontSize: 30, color: Colors.orange.shade900),
),
const SizedBox(
height: 50,
),
ElevatedButton(
onPressed: () async {
await getCred();
setState(() {
if (readName.isNotEmpty && readPass.isNotEmpty) {
username = readName;
userPass = readPass;
}
});
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.blue),
child: const Text(
"Click here to See Credentials",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
SizedBox(
height: 50,
),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const CredPage()));
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.blue),
child: const Text(
"Click here to Change Credentials",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
],
),
),
));
}
}