Add httpserver
This commit is contained in:
parent
155d97c9df
commit
0d412f2a5a
3 changed files with 74 additions and 12 deletions
|
@ -9,17 +9,6 @@ class Step2 extends StatelessWidget {
|
||||||
final TextEditingController _clientIdController = TextEditingController();
|
final TextEditingController _clientIdController = TextEditingController();
|
||||||
final TextEditingController _clientSecretController = TextEditingController();
|
final TextEditingController _clientSecretController = TextEditingController();
|
||||||
|
|
||||||
Widget buildFieldDescription(String field, String description) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Text(field, style: const TextStyle(fontWeight: FontWeight.bold)),
|
|
||||||
const Text(' : '),
|
|
||||||
Text(description)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildContent(BuildContext context) {
|
Widget buildContent(BuildContext context) {
|
||||||
return Column(children: [
|
return Column(children: [
|
||||||
const Padding(
|
const Padding(
|
||||||
|
|
72
lib/widgets/components/tutorials/step3.dart
Normal file
72
lib/widgets/components/tutorials/step3.dart
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class Step3 extends StatelessWidget {
|
||||||
|
const Step3({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
Widget buildContent(BuildContext context, SharedPreferences prefs) {
|
||||||
|
return Column(children: [
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 20),
|
||||||
|
child: Text('Étape 3:Authorisation de l\'application',
|
||||||
|
style: TextStyle(fontSize: 20)),
|
||||||
|
),
|
||||||
|
const Text(
|
||||||
|
'Pour pouvoir utiliser l\'application, il faut récupérer les clefs associées à l\'application créée juste avant.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future waitAuthorizationCallback() async {
|
||||||
|
var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 1214);
|
||||||
|
var request = await server.first;
|
||||||
|
|
||||||
|
var uri = Uri.dataFromString(request.requestedUri.toString());
|
||||||
|
var query = uri.queryParameters;
|
||||||
|
var code = query['code'];
|
||||||
|
|
||||||
|
if (code != null) {
|
||||||
|
var prefs = await SharedPreferences.getInstance();
|
||||||
|
prefs.setString('code', code);
|
||||||
|
}
|
||||||
|
|
||||||
|
request.response
|
||||||
|
..headers.contentType = ContentType.text
|
||||||
|
..write('You can close tab now')
|
||||||
|
..close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
waitAuthorizationCallback();
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: FutureBuilder(
|
||||||
|
future: SharedPreferences.getInstance(),
|
||||||
|
builder: (BuildContext context,
|
||||||
|
AsyncSnapshot<SharedPreferences> snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
final prefs = snapshot.data!;
|
||||||
|
return buildContent(context, prefs);
|
||||||
|
} else {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {}, child: const Text('Étape précédente')),
|
||||||
|
TextButton(onPressed: () {}, child: const Text('Étape suivante'))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:desktopapp/widgets/components/tutorials/step1.dart';
|
import 'package:desktopapp/widgets/components/tutorials/step1.dart';
|
||||||
import 'package:desktopapp/widgets/components/tutorials/step2.dart';
|
import 'package:desktopapp/widgets/components/tutorials/step2.dart';
|
||||||
|
import 'package:desktopapp/widgets/components/tutorials/step3.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class TutorialPage extends StatelessWidget {
|
class TutorialPage extends StatelessWidget {
|
||||||
|
@ -7,6 +8,6 @@ class TutorialPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(body: Step2());
|
return Scaffold(body: Step3());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue