2024-02-07 17:25:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-17 12:22:46 +00:00
|
|
|
import 'package:solaragent/auth.dart';
|
|
|
|
import 'package:solaragent/screens/about.dart';
|
|
|
|
import 'package:solaragent/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();
|
2024-03-17 12:22:46 +00:00
|
|
|
authClient.isAuthorized().then((value) {
|
2024-02-07 21:03:38 +00:00
|
|
|
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(
|
2024-03-23 15:05:04 +00:00
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20),
|
|
|
|
child: Column(children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: NameCard(
|
|
|
|
onLogin: () async {
|
|
|
|
await authClient.signin(context);
|
|
|
|
var authorized = await authClient.isAuthorized();
|
|
|
|
setState(() {
|
|
|
|
isAuthorized = authorized;
|
|
|
|
});
|
|
|
|
},
|
2024-02-08 12:30:19 +00:00
|
|
|
),
|
2024-03-23 15:05:04 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 5),
|
|
|
|
child: Wrap(
|
|
|
|
spacing: 5,
|
|
|
|
children: [
|
|
|
|
FutureBuilder(
|
|
|
|
future: authClient.isAuthorized(),
|
|
|
|
builder:
|
|
|
|
(BuildContext context, AsyncSnapshot<bool> snapshot) {
|
|
|
|
return (snapshot.hasData && snapshot.data == true)
|
|
|
|
? InkWell(
|
|
|
|
borderRadius:
|
|
|
|
const BorderRadius.all(Radius.circular(40)),
|
|
|
|
splashColor: Colors.indigo.withAlpha(30),
|
|
|
|
onTap: () async {
|
|
|
|
authClient.signoff();
|
|
|
|
var authorized = await authClient.isAuthorized();
|
|
|
|
setState(() {
|
|
|
|
isAuthorized = authorized;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: const ListTile(
|
|
|
|
leading: Icon(Icons.logout),
|
|
|
|
title: Text('Logout'),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(40)),
|
|
|
|
splashColor: Colors.indigo.withAlpha(30),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const AboutScreen(),
|
|
|
|
));
|
|
|
|
},
|
|
|
|
child: const ListTile(
|
|
|
|
leading: Icon(Icons.info_outline),
|
|
|
|
title: Text('About'),
|
2024-02-08 12:30:19 +00:00
|
|
|
),
|
2024-03-23 15:05:04 +00:00
|
|
|
),
|
|
|
|
],
|
2024-02-08 12:30:19 +00:00
|
|
|
),
|
2024-03-23 15:05:04 +00:00
|
|
|
),
|
|
|
|
]),
|
2024-02-07 17:25:58 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-02-07 20:40:56 +00:00
|
|
|
}
|