-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refatorar HttpClient, adicionar componente Expert e melhorar tratamen…
…to de erros na página de login
- Loading branch information
Showing
4 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Expert> { | ||
final TextEditingController _controller = TextEditingController(); | ||
late final expertDoctor; | ||
|
||
Future<Response> 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<Response>( | ||
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'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |