Finish 0.1
This commit is contained in:
parent
4e8fd12fdc
commit
d19dc1ada7
3 changed files with 102 additions and 3 deletions
|
@ -20,4 +20,4 @@ var routes = <String, WidgetBuilder>{
|
||||||
Routes.home.path: (context) => const HomePage(),
|
Routes.home.path: (context) => const HomePage(),
|
||||||
};
|
};
|
||||||
|
|
||||||
var initialRoute = Routes.streamlabsTutorial.path;
|
var initialRoute = Routes.home.path;
|
||||||
|
|
|
@ -103,7 +103,8 @@ class Step3 extends StatelessWidget {
|
||||||
await dio.post('https://streamlabs.com/api/v1.0/token', data: data);
|
await dio.post('https://streamlabs.com/api/v1.0/token', data: data);
|
||||||
|
|
||||||
if (response.statusCode == HttpStatus.ok) {
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
prefs.setString('credentials', response.data.toString());
|
jsonDecode(response.data).forEach((key, value) =>
|
||||||
|
prefs.setString('credentials.$key', value.toString()));
|
||||||
Logger.log(LoggerType.info, this,
|
Logger.log(LoggerType.info, this,
|
||||||
'Authorization success : ${response.data}');
|
'Authorization success : ${response.data}');
|
||||||
showDialog(
|
showDialog(
|
||||||
|
|
|
@ -1,10 +1,108 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:desktopapp/classes/routes.dart';
|
||||||
|
import 'package:desktopapp/utils/logger.dart';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
class HomePage extends StatelessWidget {
|
||||||
const HomePage({Key? key}) : super(key: key);
|
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 {
|
||||||
|
Dio dio = Dio(BaseOptions(
|
||||||
|
contentType: Headers.jsonContentType,
|
||||||
|
responseType: ResponseType.json,
|
||||||
|
validateStatus: (_) => true));
|
||||||
|
|
||||||
|
var accessToken = prefs.getString('credentials.access_token');
|
||||||
|
|
||||||
|
var data = jsonEncode({
|
||||||
|
'type': 'donation',
|
||||||
|
'message': '*MrDev023* *Break* Test !',
|
||||||
|
'access_token': accessToken,
|
||||||
|
'special_text_color': '#ff00ff',
|
||||||
|
'image_href': 'https://postimgs.org/img/logo.png',
|
||||||
|
'sound_href': ''
|
||||||
|
});
|
||||||
|
|
||||||
|
var response = await dio
|
||||||
|
.post('https://streamlabs.com/api/v1.0/alerts', data: data);
|
||||||
|
|
||||||
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
|
prefs.setString('credentials', response.data.toString());
|
||||||
|
Logger.log(LoggerType.info, this,
|
||||||
|
'Authorization success : ${response.data}');
|
||||||
|
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 {
|
||||||
|
Logger.log(LoggerType.error, this,
|
||||||
|
'Authorization error : ${response.data} with $data and ${response.requestOptions.headers}');
|
||||||
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Scaffold(body: Text('Test'));
|
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());
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue