Created .env file for environment variables and added corresponding package (flutter_dotenv)

This commit is contained in:
2024-01-15 16:08:16 +03:00
parent d530b6b409
commit b3a49c85a2
7 changed files with 14 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ import 'package:validators/validators.dart';
import 'package:eatvio_app/widgets/next_step_button.dart';
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'dart:convert';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
@@ -83,8 +84,7 @@ class AuthScreen extends StatelessWidget {
'password': state.passwordController!.text,
};
final response = await http.post(
Uri.parse(
'https://emaibo4wahye-dev3.eatvio.ru/api/login'),
Uri.parse(dotenv.env['SERVER_ROOT']! + '/login'),
headers: {'Content-Type': 'application/json'},
body: json.encode(credentials),
encoding: utf8);
@@ -103,7 +103,7 @@ class AuthScreen extends StatelessWidget {
builder: (context) => AlertDialog(
title: Text('Ошибка'),
content:
Text(jsonDecode(jsonEncode(response.body))),
Text(dotenv.env['SERVER_ROOT']! + '/login'),
actions: [
TextButton(
onPressed: () {

View File

@@ -1,5 +1,3 @@
import 'dart:ffi';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import '/core/app_export.dart';
@@ -7,6 +5,7 @@ import 'package:eatvio_app/presentation/profile/my_profile_screen/models/my_prof
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:hive/hive.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
part 'my_profile_event.dart';
part 'my_profile_state.dart';
@@ -24,7 +23,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
box.delete('token');
final response = await http.post(
Uri.parse('http://10.55.5.126:1092/api/profile/logout'),
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/logout'),
headers: {
'Authorization': 'Bearer $token',
},
@@ -47,7 +46,7 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
final box = await Hive.openBox('token');
final token = box.get('token');
final response = await http.get(
Uri.parse('https://emaibo4wahye-dev3.eatvio.ru/api/profile/index'),
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/index'),
headers: {
'Authorization': 'Bearer $token',
},

View File

@@ -7,7 +7,7 @@ import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart';
import 'package:eatvio_app/widgets/next_step_button.dart';
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/data/models/userRegistrationModel/user_registration_model.dart';
import 'package:eatvio_app/data/models/tokenModel/token_model.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:hive/hive.dart';
@@ -72,8 +72,7 @@ class AdditionalInformationScreen extends StatelessWidget {
.userRegistrationSheet;
sheet.additionalInfo = state.editTextController!.text;
final response = await http.post(
Uri.parse(
'https://emaibo4wahye-dev3.eatvio.ru/api/register'),
Uri.parse(dotenv.env['SERVER_ROOT']! + '/register'),
headers: {'Content-Type': 'application/json'},
body: json.encode(sheet),
);