import 'dart:async';

import 'package:flutter/material.dart';

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

  @override
  State<LoadingSpinner> createState() => _LoadingSpinnerState();
}

class _LoadingSpinnerState extends State<LoadingSpinner> {
  bool textVisible = false;
  late Timer timer;

  @override
  void initState() {
    timer = Timer(const Duration(seconds: 30), () {
      setState(() {
        textVisible = true;
      });
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) => Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Visibility(
          visible: !textVisible,
          replacement: const Icon(Icons.sentiment_dissatisfied_outlined),
          child: const CircularProgressIndicator(),
        ),
        const SizedBox(height: 30),
        Visibility(
          visible: textVisible,
          child: const Text(
            textAlign: TextAlign.center,
            'Irgendetwas funktioniert nicht!\nBist du mit dem Internet verbunden?\n\nVersuche die App neuzustarten',
          ),
        ),
      ],
    ),
  );

  @override
  void dispose() {
    timer.cancel();
    super.dispose();
  }
}
