import 'package:flutter/material.dart'; import 'package:goatagent/auth.dart'; import 'package:goatagent/widgets/name_card.dart'; class AccountScreen extends StatefulWidget { const AccountScreen({super.key}); @override State createState() => _AccountScreenState(); } class _AccountScreenState extends State { bool isAuthorized = false; @override void initState() { super.initState(); AuthGuard().isAuthorized().then((value) { setState(() { isAuthorized = value; }); }); } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Padding( padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 20), child: Column( children: [ Padding( padding: const EdgeInsets.only(top: 20), child: NameCard( onLogin: () async { await AuthGuard().login(context); var authorized = await AuthGuard().isAuthorized(); setState(() { isAuthorized = authorized; }); }, ), ), FutureBuilder( future: AuthGuard().isAuthorized(), builder: (BuildContext context, AsyncSnapshot 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)); } }, ), ], ), ), ), ); } }