2024-02-07 17:25:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-02-07 20:40:56 +00:00
|
|
|
import 'package:goatagent/auth.dart';
|
|
|
|
import 'package:goatagent/widgets/name_card.dart';
|
2024-02-07 17:25:58 +00:00
|
|
|
|
2024-02-07 21:03:38 +00:00
|
|
|
class AccountScreen extends StatefulWidget {
|
2024-02-07 17:25:58 +00:00
|
|
|
const AccountScreen({super.key});
|
|
|
|
|
2024-02-07 21:03:38 +00:00
|
|
|
@override
|
|
|
|
State<AccountScreen> createState() => _AccountScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AccountScreenState extends State<AccountScreen> {
|
|
|
|
bool isAuthorized = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
AuthGuard().isAuthorized().then((value) {
|
|
|
|
setState(() {
|
|
|
|
isAuthorized = value;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-07 17:25:58 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-07 20:40:56 +00:00
|
|
|
return Scaffold(
|
|
|
|
body: SafeArea(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-02-08 07:19:37 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: NameCard(
|
|
|
|
onLogin: () async {
|
|
|
|
await AuthGuard().login(context);
|
|
|
|
var authorized = await AuthGuard().isAuthorized();
|
|
|
|
setState(() {
|
|
|
|
isAuthorized = authorized;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2024-02-07 21:03:38 +00:00
|
|
|
),
|
|
|
|
FutureBuilder(
|
|
|
|
future: AuthGuard().isAuthorized(),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
|
|
|
|
if (snapshot.hasData && snapshot.data == true) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 5),
|
|
|
|
child: Wrap(
|
|
|
|
spacing: 5,
|
|
|
|
children: [
|
|
|
|
Card(
|
|
|
|
elevation: 0,
|
|
|
|
child: InkWell(
|
|
|
|
splashColor: Colors.indigo.withAlpha(30),
|
|
|
|
onTap: () async {
|
|
|
|
AuthGuard().logout();
|
|
|
|
var authorized =
|
|
|
|
await AuthGuard().isAuthorized();
|
|
|
|
setState(() {
|
|
|
|
isAuthorized = authorized;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: const ListTile(
|
|
|
|
leading: Icon(Icons.logout),
|
|
|
|
title: Text('Logout'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Padding(padding: EdgeInsets.only(top: 5));
|
|
|
|
}
|
2024-02-07 20:40:56 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2024-02-07 17:25:58 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-02-07 20:40:56 +00:00
|
|
|
}
|