import 'package:flutter/material.dart';
import 'package:school_management_system/components/default_values.dart';
import 'package:school_management_system/screens/welcome/welcome_screen.dart';

late Future<bool> _checkToken;

class FinanceScreen extends StatefulWidget {
  const FinanceScreen({super.key});

  @override
  State<FinanceScreen> createState() => _FinanceScreenState();
}

class _FinanceScreenState extends State<FinanceScreen> {
  
  @override
  void initState() {
    _checkToken = checkTokenValidity();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    _checkToken.then(
      (value) {
        if (!value) {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) {
                return const WelcomeScreen();
              },
            ),
          );

          ScaffoldMessenger.of(context).showSnackBar(
            const SnackBar(
              content: Text('Session Time Out / Sign Back In'),
            ),
          );
        }
      },
    );

    return const Center(
      child: Text(
        'Finance Page',
        style: TextStyle(fontWeight: FontWeight.w800),
      ),
    );
  }
}
