add variable global for adress api

This commit is contained in:
Valentin CZERYBA 2022-09-21 23:00:37 +02:00
parent e4540dd3e5
commit 7750126ee4
3 changed files with 8 additions and 3 deletions

View File

@ -8,6 +8,8 @@ import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'variable/globals.dart' as globals;
void main() {
runApp(const MyApp());
}
@ -65,7 +67,7 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
String former = "";
if ((user.isNotEmpty) && (jwt.isNotEmpty)) {
var urlGet = Uri.parse("http://localhost:8083/api/users");
var urlGet = Uri.parse("http://${globals.api}/users");
var responseGet = await http
.get(urlGet, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'});

View File

@ -9,6 +9,8 @@ import 'MyHomePage.dart';
import 'classes/alert.dart';
import 'variable/globals.dart' as globals;
void main() {
runApp(MyApp());
}
@ -32,7 +34,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
TextEditingController inputPseudo = TextEditingController();
TextEditingController inputPassword = TextEditingController();
Future<void> _login(BuildContext context) async {
var url = Uri.parse("http://localhost:8083/api/token");
var url = Uri.parse("http://${globals.api}/token");
var pseudo = inputPseudo.text;
var password = inputPassword.text;
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
@ -125,7 +127,7 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
var jwt = prefs.getString("jwt") ?? "";
var user = prefs.getString("user") ?? "";
if ((jwt.isNotEmpty) && (user.isNotEmpty)) {
var urlToken = Uri.parse("http://localhost:8083/api/token");
var urlToken = Uri.parse("http://${globals.api}/token");
var responseToken = await http.get(urlToken,
headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'});

View File

@ -0,0 +1 @@
String api = "10.0.2.2:8083/api";