2022-03-31 22:04:57 +02:00
|
|
|
import 'package:desktopapp/classes/routes.dart';
|
2022-04-12 20:46:42 +02:00
|
|
|
import 'package:desktopapp/utils/requests.dart';
|
2022-03-31 21:34:28 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-03-31 22:04:57 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-03-31 21:34:28 +02:00
|
|
|
|
|
|
|
class HomePage extends StatelessWidget {
|
|
|
|
const HomePage({Key? key}) : super(key: key);
|
|
|
|
|
2022-03-31 22:04:57 +02:00
|
|
|
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 {
|
2022-04-12 20:46:42 +02:00
|
|
|
if (await Requests.sendAlert('*MrDev023* *Break* Test !')) {
|
2022-03-31 22:04:57 +02:00
|
|
|
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')),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-03-31 21:34:28 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-03-31 22:04:57 +02:00
|
|
|
return Scaffold(
|
|
|
|
body: FutureBuilder(
|
|
|
|
future: SharedPreferences.getInstance(),
|
|
|
|
builder: (BuildContext context,
|
|
|
|
AsyncSnapshot<SharedPreferences> 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());
|
|
|
|
}
|
|
|
|
}));
|
2022-03-31 21:34:28 +02:00
|
|
|
}
|
|
|
|
}
|