diff --git a/lib/api/services/http_client.dart b/lib/api/services/http_client.dart index 28cbc43..b0e9a49 100644 --- a/lib/api/services/http_client.dart +++ b/lib/api/services/http_client.dart @@ -4,7 +4,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class HttpClient { late Dio client; - HttpRequestHandler() { + HttpClient() { client = Dio(BaseOptions( baseUrl: dotenv.env['BASE_URL'] ?? 'http://10.0.2.2:3000', headers: { @@ -13,27 +13,6 @@ class HttpClient { )); } - Future fetchWithRetry(String url, - {int retries = 3, int delay = 1000}) async { - int attempt = 0; - while (attempt < retries) { - try { - final response = await Dio().get(url); - return response; - } on DioException catch (e) { - if (e.response?.statusCode == 429) { - attempt++; - if (attempt >= retries) { - rethrow; - } - await Future.delayed(Duration(milliseconds: delay * attempt)); - } else { - rethrow; - } - } - } - throw Exception('Failed to fetch data after $retries attempts'); - } } diff --git a/lib/src/app/home/home_page.dart b/lib/src/app/home/home_page.dart index 48d561a..d7f9687 100644 --- a/lib/src/app/home/home_page.dart +++ b/lib/src/app/home/home_page.dart @@ -65,6 +65,13 @@ class HomepageState extends State { ), child: const BannerComponent(hasPromotion: true), ), + Divider(), + ConstrainedBox( + constraints: BoxConstraints( + maxHeight: screenHeight * 0.2, // 60% da altura da tela + ), + child: const BannerComponent(hasPromotion: true), + ), ], ), ), diff --git a/lib/src/app/login/login_page.dart b/lib/src/app/login/login_page.dart index c554eb1..095ff25 100644 --- a/lib/src/app/login/login_page.dart +++ b/lib/src/app/login/login_page.dart @@ -179,8 +179,8 @@ class LoginPageState extends State { .then((value) => value) .catchError((error) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Erro ao fazer login'), + SnackBar( + content: Text(error.toString()), backgroundColor: Colors.redAccent, ), ); diff --git a/lib/src/components/Expert.dart b/lib/src/components/Expert.dart new file mode 100644 index 0000000..67f215f --- /dev/null +++ b/lib/src/components/Expert.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; +import 'package:gohealth/api/repositories/expert_doctor_repository.dart'; +import 'package:http/http.dart'; + +class Expert extends StatefulWidget { + @override + _ExpertState createState() => _ExpertState(); +} + +class _ExpertState extends State { + final TextEditingController _controller = TextEditingController(); + late final expertDoctor; + + Future texto = Future.value(Response('', 200)); + + @override + void initState() { + super.initState(); + expertDoctor = expertDoctor(); + } + + void getSymptoms(String prompt) { + setState(() { + texto = expertDoctor.getSymptoms(prompt); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Column( + children: [ + Expanded( + child: FutureBuilder( + future: texto, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Text('Erro: ${snapshot.error}'); + } else { + if (!snapshot.hasData || (snapshot.data!.body as List).isEmpty) { + return const Center(child: Text('Nenhum produto encontrado.')); + } else { + return Text(snapshot.data.toString()); + } + } + }, + ), + ), + Padding( + padding: const EdgeInsets.all(16.0), + child: Form( + child: Column( + children: [ + TextFormField( + controller: _controller, + decoration: InputDecoration(labelText: 'Digite o sintoma'), + ), + SizedBox(height: 16), + ElevatedButton( + onPressed: () { + getSymptoms(_controller.text); + }, + child: Text('Enviar'), + ), + ], + ), + ), + ), + ], + ), + ); + } +} \ No newline at end of file