
import 'dart:async';

import 'package:flutter/material.dart';

class LoadingSpinner extends StatefulWidget {
  const LoadingSpinner({Key? key}) : super(key: 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: 15), () {
      setState(() {
        textVisible = true;
      });
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Visibility(
            visible: !textVisible,
            replacement: const Icon(Icons.signal_wifi_connected_no_internet_4_outlined),
            child: const CircularProgressIndicator(),
          ),
          const SizedBox(height: 30),
          Visibility(
            visible: textVisible,
            child: const Text("Etwas scheint nicht zu funktionieren!\nBist du mit dem Internet verbunden?\n\nVersuche die App neuzustarten"),
          ),
        ],
      ),
    );
  }

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