import 'package:desktopapp/classes/routes.dart'; import 'package:desktopapp/utils/requests.dart'; import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); Widget buildContent(BuildContext context, SharedPreferences prefs) { return Column(children: [ const Padding( padding: EdgeInsets.symmetric(vertical: 20), child: Text('Appuyez sur le bouton pour envoyer une alerte de test', style: TextStyle(fontSize: 20)), ), TextButton( onPressed: () async { if (await Requests.sendAlert('*MrDev023* *Break* Test !')) { showDialog( context: context, builder: (_) => AlertDialog( title: const Text('Info'), content: const Text('Envoie réussie'), actions: [ TextButton( onPressed: () { Navigator.pop(context); }, child: const Text('OK')) ], )); } else { showDialog( context: context, builder: (_) => AlertDialog( title: const Text('Erreur'), content: const Text('Impossible de se connecter.'), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text('OK')) ], )); } }, child: const Text('Envoyer une alerte de test')), ]); } @override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder( future: SharedPreferences.getInstance(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { final prefs = snapshot.data!; Future(() async { if (!prefs.containsKey('credentials.access_token')) { Navigator.of(context) .pushReplacementNamed(Routes.streamlabsTutorial.path); } }); return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [buildContent(context, prefs)], ) ]); } else { return const Center(child: CircularProgressIndicator()); } })); } }