import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tasktracker/Data.dart';
import 'package:tasktracker/googleSignIn.dart';
import 'package:restart_app/restart_app.dart';

class AccountSettings extends StatefulWidget {
  const AccountSettings({Key? key}) : super(key: key);

  @override
  _AccountSettingsState createState() => _AccountSettingsState();
}

class _AccountSettingsState extends State<AccountSettings> {

  @override void initState() {
    // TODO: implement initState
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context)=>GoogleSignInProvider(),
      builder: (context, snapshot) {
        return Scaffold(
          appBar: AppBar(title: Row(
            children: [
              FaIcon(FontAwesomeIcons.user),
              SizedBox(width: 15,),
              Text("Account Settings"),
            ],
          )),
          body: SafeArea(
            child: Column(
              children: [
                SizedBox(
                  height: 10,
                ),
                ListTile(
                  leading: FaIcon(FontAwesomeIcons.signOut),
                  title: Text("Log out",style:TextStyle(color: Colors.red)),
                  subtitle: Row(
                    children: [
                      Text("Good-bye"),
                    ],
                  ),
                  onTap: () async{
                    final provider = Provider.of<GoogleSignInProvider>(context, listen:false);
                    provider.logout();
                    final prefs = await SharedPreferences.getInstance();
                    await prefs.clear();
                    Restart.restartApp(webOrigin: '/splash');
                  },
                ),

              ],
            ),
          ),
        );
      }
    );
  }
}
